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

Enable flask-cors to work well with CDNs and caches #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rtshilston
Copy link

At present, the vary header is ONLY set if an inbound request has an appropriate 'origin' value. This isn't compatible with using flask-cors with endpoints that have positive cache-headers.

An example scenario is:

  • User 1 requests endpoint without CORS.
  • Response is sent with 1hr cache header, and doesn't include a vary header
  • User 2 requests endpoint and requires CORS
  • Cache responds with cached response to user 1, which fails CORS checks.

This change ensures that if the vary_header flag is set, then it'll always send the header, so that flask-cors can dependably be used with caching.

This supports the use of flask-cors behind intermediate caches / CDNs.
@corydolphin
Copy link
Owner

corydolphin commented Jul 6, 2021

At present, the vary header is ONLY set if an inbound request has an appropriate 'origin' value. This isn't compatible with using flask-cors with endpoints that have positive cache-headers.

An example scenario is:

  • User 1 requests endpoint without CORS.
  • Response is sent with 1hr cache header, and doesn't include a vary header
  • User 2 requests endpoint and requires CORS
  • Cache responds with cached response to user 1, which fails CORS checks.

This change ensures that if the vary_header flag is set, then it'll always send the header, so that flask-cors can dependably be used with caching.

Hey @rtshilston this scenario should be covered by default with the "always_send" option. It seems like in that scenario it may be correct to return the wildcard. What have you seen?

@rtshilston
Copy link
Author

Hey @corydolphin - thanks for the response. I'm not proposing sending the CORS headers. Instead, always sending "Vary: Origin". I think that's totally safe and compliant with specs. If it's useful for me to build a working test-case, let me know and I'll do that.

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

2 participants