Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cors: allow using regexes to match origins #3769

Merged
merged 4 commits into from
Jul 10, 2018

Conversation

codesuki
Copy link
Member

@codesuki codesuki commented Jul 1, 2018

Description: Adds allow_origin_regex field to the CORS config which is a list of regexes to match against. First the fixed strings in allow_origin are checked and afterwards the regexes.
If it's preferable to to only allow one regex or a boolean switch for the current allow_origins, let me know.

Risk Level: Medium
Testing: Unit and integration tests.
Docs Changes: Yes
Release Notes: cors: allow using regexes to match origins
Resolves #2526

Signed-off-by: Neri Marschik codesuki@users.noreply.github.com

Resolves envoyproxy#2526

Signed-off-by: Neri Marschik <codesuki@users.noreply.github.com>
if (allowOriginRegexes() == nullptr) {
return false;
}
for (const auto& regex : *allowOriginRegexes()) {
Copy link
Member Author

@codesuki codesuki Jul 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have been great if for() just gets skipped when allowOriginRegexes is a nullptr, like in Go.

Signed-off-by: Neri Marschik <codesuki@users.noreply.github.com>
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Just a couple things, one of which is that per #2832 and the recent announcement, we're not taking any further v1 API changes in advance of removing it altogether. Please revert the rds_json.cc change and the API v1 docs.

@@ -303,6 +303,9 @@ message CorsPolicy {

// Specifies if CORS is enabled. Defaults to true. Only effective on route.
google.protobuf.BoolValue enabled = 7;

// Specifies regex patterns that match allowed origins.
repeated string allow_origin_regex = 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth moving this up, next to allow_origin since they're releated (and add // [#comment:next free field: 9] just above the message CorsPolicy).

I think it's also woth a comment to indicate that an origin that matches either allow_origin or allow_origin_regex will be allowed.

Signed-off-by: Neri Marschik <codesuki@users.noreply.github.com>
@codesuki
Copy link
Member Author

codesuki commented Jul 5, 2018

Done! I changed the links in the doc to be more helpful.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Small Q. Please merge master which fixed proto format to make sure that nothing in the proto changes needs fixing. Thank you!

@@ -15,6 +15,7 @@ upstream cluster to route to or whether to perform a redirect.
"name": "...",
"domains": [],
"routes": [],
"cors": {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert? Or was this missing previously?

Copy link
Member Author

@codesuki codesuki Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing previously. We have a cors config on vhost and route, I noticed that field was missing in the docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below in this file we have

:ref:`cors <config_http_conn_man_route_table_cors>`
    (optional, object) Specifies the virtual host's CORS policy.

Signed-off-by: Neri Marschik <codesuki@users.noreply.github.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mattklein123 mattklein123 merged commit 00bb039 into envoyproxy:master Jul 10, 2018
@codesuki codesuki deleted the cors-regex branch July 10, 2018 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please support domain matching in the CORS config
3 participants