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

Manual CORS headers in response message are stripped #1303

Open
NichUK opened this issue Mar 14, 2017 · 7 comments
Open

Manual CORS headers in response message are stripped #1303

NichUK opened this issue Mar 14, 2017 · 7 comments
Assignees
Milestone

Comments

@NichUK
Copy link

NichUK commented Mar 14, 2017

In an HttpTrigger function, I am manually setting CORS headers in the HttpResponseMessage, using C#.

When running in an WebApp, this works perfectly, however when running as a function, my manual CORS headers are stripped and replaced with CORS headers from the function application settings. I need to dynamically set CORS headers as my functions will be access from a variety of domains, and having to continually update the function app to add them in would just not be possible, and the wildcard cannot be used because it is incompatible with the withCredentials: true attribute on the XMLHttpRequest call.

Surely function application headers should only be added when there are no existing headers (which must have been created on purpose), rather than replacing them?

This problem is related to #620, but because I am setting the withCredentials attribute on the call, the workaround to remove all CORS information from the function app, doesn't work. This is therefore a blocker.

Also, the portal complains "Error: CORS is not configured for this function app. Please add https://functions.azure.com to your CORS list."

@christopheranderson
Copy link
Contributor

@ahmelsayed - can you investigate?

@ahmelsayed
Copy link
Contributor

This is a side effect of our CORS implementation in Antares and the fact that the portal depends on CORS to communicate with the runtime.
If you want to handle OPTIONS requests in your functions, you need to disable CORS feature which will mean you can't use the portal.

@NichUK
Copy link
Author

NichUK commented Mar 20, 2017

It would seem to me that if CORS headers are already present when a response is sent out from a function (i.e. they MUST have been deliberately manually added), then your CORS implementation should respect those and leave them alone. If they are not present, then you should add them as currently.

@ricklove
Copy link

@NichUK

The workaround in #620 should work with "withCredentials". If you remove all CORS entries in the portal, the portal will start complaining about it, but the manual CORS entries will work.

However, I discovered, that this is only true if the new Proxies (Preview) is disabled. When I enabled the Proxies, it broke this workaround and the Access-Control-Allow-Origin went back to a wildcard.

When I disabled Proxies, then it allowed the CORS to go through.


I agree with NichUK that if CORS has been set manually in an azure function, this should override any other settings.

However, I suspect the implementation problem with this is with the OPTIONS pre-flight request and in order to set CORS headers manually, we would need to handle the OPTIONS request manually also.

@christopheranderson
Copy link
Contributor

I'll follow up with the folks who manage this for App Service.

@paulbatum paulbatum modified the milestones: April 2017, May 2017 May 1, 2017
@paulbatum paulbatum modified the milestones: May 2017, June 2017 Jun 20, 2017
@paulbatum paulbatum modified the milestones: Next, June 2017 Jul 12, 2017
@DonKarlssonSan
Copy link

Do you have any updates regarding this issue?

@masters3d
Copy link

Same issue with V1, any plans to address this in V2 or beyond? This is very surprising, I am glad I am not alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants