Skip to content

Add Vary header for correct fixing of CORS headers#14

Open
LukasKalbertodt wants to merge 1 commit intomainfrom
add-vary-header-cors
Open

Add Vary header for correct fixing of CORS headers#14
LukasKalbertodt wants to merge 1 commit intomainfrom
add-vary-header-cors

Conversation

@LukasKalbertodt
Copy link
Member

When the server's Access-Control-Allow-Origin header depends on the incoming Origin header, then the server should also set Vary: Origin. Otherwise, browsers are allowed to cache the response (made from one origin) and use it when another origin requests the same file. But then the Allow-Origin does not match the second one, leading to a CORS error. With this header, the browser must cache the response separately for each origin. This of course has some disadvantages, as there will be more cache misses. It's not ideal, but the previous config can lead to very broken behavior in some situations.

As an aside: if I understand the config correctly, if opencast_nginx_cors_urls are not set, then the cors headers always say "allow" to whatever origin. Is that really intended? Seems potentially dangerous that leaving away this config value opens up CORS to everyone.

When the server's `Access-Control-Allow-Origin` header depends on the incoming `Origin` header, then the server should also set `Vary: Origin`. Otherwise, browsers are allowed to cache the response (made from one origin) and use it when another origin requests the same file. But then the `Allow-Origin` does not match the second one, leading to a CORS error. With this header, the browser must cache the response separately for each origin. This of course has some disadvantages, as there will be more cache misses. It's not ideal, but the previous config can lead to very broken behavior in some situations.

As an aside: if I understand the config correctly, if `opencast_nginx_cors_urls` are not set, then the cors headers always say "allow" to whatever origin. Is that really intended? Seems potentially dangerous that leaving away this config value opens up CORS to everyone.
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.

1 participant