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

Feature/cors allow credentials #464

Conversation

cast
Copy link
Contributor

@cast cast commented Jun 9, 2018

Relates to issue #463

Added support for CORS headers Access-Control-Expose-Headers and Access-Control-Allow-Credentials in the CORS Configuration block at the Serverless::Api resource.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

cast added 2 commits June 9, 2018 01:49
 progress commit to support Access-Control-Allow-Credentials and Access-Control-Expose-Headers
Set allow credentials output to "'true'"
Added additional tests for the add_cors method
@cast
Copy link
Contributor Author

cast commented Jun 9, 2018

Still needs translator input/output tests

"application/json": "{}\n"
},
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is invalid output. A-C-A-O isn't allowed to have the wildcard value when A-C-A-C is set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! @cast could you add some logic to throw InvalidDocument when a user tries to specify Allow-Credentials: true and Allow-Origin: *?

@brettstack
Copy link
Contributor

This is great! Could you add validation for the Credentials+Wildcard scenario?

…dcard value ("'*'") now throws InvalidDocument
Copy link
Contributor

@brettstack brettstack left a comment

Choose a reason for hiding this comment

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

This is awesome. Really appreciate the tests!

@chrisoverzero
Copy link
Contributor

chrisoverzero commented Jun 29, 2018

As I mentioned in the issue for this PR, I think that adding Access-Control-Expose-Headers headers to preflight responses is not meaningful. The specification calls it out specifically as being for:

[a]n HTTP response to a CORS request that is not a CORS-preflight request […]

Unless something has changed, SAM can't modify the headers of responses that make it through API Gateway and into Lambda. Is that still the case?

@cast
Copy link
Contributor Author

cast commented Jun 29, 2018

Thanks @brettstack !

Will the error message still fit in the cloudformation UI/api before being truncated? The declarative part is at the end so if it is truncated people might not know what's going on.

The documentation mentions that AllowedOrigin is a required field, while it is in fact implicitly set to to "'*'" when no explicit configuration is used.

@brettstack
Copy link
Contributor

Thanks for raising this @chrisoverzero. After reviewing the spec and other documentation more thoroughly it does appear Expose-Headers is not intended for preflight responses.

@brettstack
Copy link
Contributor

@cast if you can provide a repro/use-case for including this in preflight I can take another look. Otherwise the Allow-Credentials part of this PR is still very useful.

@cast
Copy link
Contributor Author

cast commented Jun 29, 2018

Thanks @chrisoverzero for the spec review. Apart from a now fixed side effect leading me to think the allowed exposed headers was an issue in our internal development I added it mainly because other api management solutions often allow or force to take a liberal approach to preflight CORS (ApiMan, Axway,...).

I'm not aware of specific browsers and browser versions that require the exposed header in the preflight response. I'm assuming if there is an issue it would be in old versions due to the current living standard.

I'll remove the exposed headers parts.

@cast cast changed the title Feature/cors expose headers and allow credentials Feature/cors allow credentials Jun 29, 2018
@JenningsWu
Copy link

Any updates? This is really helpful for our project : )

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.

None yet

5 participants