CORS Allow-Credentials and Expose-Headers support
I plan to create a PR to add support for Access-Control-Allow-Credentials and Access-Control-Expose-Headers in the CORS configuration block.
Right now you have to add swagger aws integration configuration for options requests to facilitate this. Having these setting in the CORS configuration block will make CORS configuration easier and especially less error prone .
We are using (the same) custom headers for our endpoints so moving this configuration from swagger into the CORS configuration block would improve our configuration workflow.
Adding support for these headers would complete CORS header support according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
It appears to me that "Access-Control-Expose-Headers" is not meant to be set on preflight responses, but only on "actual" responses. SAM can't do anything to modify the application's response headers (IIRC); it's up to the application to set those. I think that adding it to a preflight response carries no meaning.
Hi @chrisoverzero , the Access-Control-Expose-Headers header is required to be set on the Options preflight call as well (at least in current Chrome version).
I can't seem to recreate that. I've created an API that responds to preflight requests without "Access-Control-Expose-Headers" and to non-preflight requests with "Access-Control-Expose-Headers". In Chrome 67.0.3396.79, I'm running this:
fetch(
'http://localhost:5000/cors/exposed',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({})
}).then(r => console.log(r.headers.get('something-custom')))
…and I am able to read the value of the "Something-Custom" header.
Additionally, the spec calls out "Access-Control-Expose-Headers" as a header that appears in responses to non-preflight requests.
what about Access-Control-Allow-Credentials ?
Access-Control-Allow-Credentials is valid for the responses to both preflight and non-preflight CORS requests.
exactly and it should be part of preflight requests as well so CORS option in SAM should support this.
What should SAM do if a template sets Access-Control-Allow-Credentials and sets Access-Control-Allow-Origin to "'*'"?
Hi Chris, IMO SAM can leave it as it is and pass it on to API gateway and browser will give error related to this as part of client request. This is the same behaviour as API gateway.
Merged into develop. Thank you for this contribution!
Released!