-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bug: CORS Support in start-api #4991
Bug: CORS Support in start-api #4991
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to have integration tests that could help us validate the behavior?
return cors_headers | ||
|
||
cors_origins = cors_headers["Access-Control-Allow-Origin"] | ||
# unset this header due to restrictive manner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why unset this? It looks like it should be removed in the case that response_allowed_origin
is not set. If so, I would move this to be closer to line 437. I think it just make it a little easier to read since the mutation of the cors_headers
is all in one spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jfuss , thank you for taking your time to review this
we unset and set again if a match is found (restrictive manner)
if multiple domains are allowed, we only send back 1 allowed domain in our response header
if all domains are allowed, we also only send back 1 allowed domain in our response header
we do not return this header (implying a deny) if no matches is found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @jfuss please also refer to my below comment:
#4991 (comment)
@@ -303,6 +303,7 @@ def _request_handler(self, **kwargs): | |||
|
|||
route = self._get_current_route(request) | |||
cors_headers = Cors.cors_to_headers(self.api.cors) | |||
cors_headers = self._response_cors_headers(request, cors_headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for creating this PR! Did we need to restrict this behaviour to only run for HTTP APIs? From the docs and the linked issue, this seems to be something that the Lambda function deals with on for REST, but we would need to manage for HTTP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @lucashuy
During the implementation, I referred to MDN web docs for reference:
I also referred to the implementation of middy cors middleware
below piece of code will basically parse and return a single origin if matched:
it is explained if looking deeper into the getOrigin()
function:
Hope these help explain the reasoning behind my code.
Thanks,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch!
merged and resolved conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This reverts commit 3882c3d.
@sleepwithcoffee .. We had to revert this PR as it cause some regression, and some of the integration test cases are failing. Please check the revert PR to get more details. Could you please update this PR to fix the failing test cases, and add new integration test cases that cover the cases you are fixing here. |
Which issue(s) does this change fix?
#4161
Why is this change necessary?
To address a bug raised in ticket of local API gateway that does not properly return CORS headers. Currently, a workaround of using external plugin is required.
How does it address the issue?
Inject CORS response headers when returning to client. There are generated based on request Origin header.
What side effects does this change have?
I would expect none since this is a bug fix and an improvement. With this, user would not need to use external plugin to enable CORS for the local stack.
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Current behavior:
New behavior:
Some consideration: