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

CORS module excessively sets the Vary response header #539

Open
bardiharborow opened this issue Jan 16, 2025 · 0 comments
Open

CORS module excessively sets the Vary response header #539

bardiharborow opened this issue Jan 16, 2025 · 0 comments

Comments

@bardiharborow
Copy link

bardiharborow commented Jan 16, 2025

cors::CorsLayer sets the Vary response header to origin, access-control-request-method, access-control-request-headers (added in #199) regardless of the provided CORS configuration.

From MDN:

The HTTP Vary response header describes the parts of the request message (aside from the method and URL) that influenced the content of the response it occurs in. Including a Vary header ensures that responses are separately cached based on the headers listed in the Vary field.

cors::CorsLayer should only add a request header to the Vary response header if a dynamic response is calculated based on that request header. .permissive(), for example, does not dynamically adjust the response at all.

In general, dynamic behaviour appears to occur through various .mirror_request() methods. It can also occur when closures are passed, though there it isn't trivial to determine what request headers have been used to determine the response; that case may instead require a call-out in the documentation.

Workaround

use tower_http::cors::{CorsLayer, Vary};

CorsLayer::permissive().vary(Vary::list([]));
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

No branches or pull requests

1 participant