CORS访问控制 - 最大年龄被忽略 [英] CORS Access-Control-Max-Age is ignored

查看:343
本文介绍了CORS访问控制 - 最大年龄被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的域托管一个WebApp和他的API,并使用CORS能够工作在同一起源政策。到现在为止还挺好。这工作。



为了只发送一个CORS预检每个会话我设置
访问控制最大年龄20天,但这不工作(在Chrome中测试):
https://db.tt/vfIW3fD2


$ b $

Chrome / Blink的最大预检时间为10分钟(600秒) )。以下是源代码中定义此位置的位置:



https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/core /loader/CrossOriginPreflightResultCache.cpp&l=40&rcl=1399481969



超过10分钟的任何预检时间将被忽略,而将使用10分钟。



不同的浏览器可能有不同的最高年龄政策。 Safari / WebKit缓存长达5分钟,而Firefox缓存长达24小时。 Chrome源代码表示存在最大值,以最小化切换到安全网络后使用中毒缓存的风险。



EDIT :另请注意,代码定义的默认超时为5秒:



https://code.google.com/p/chromium/codesearch#chromium/src/ third_party / WebKit / Source / core / loader / CrossOriginPreflightResultCache.cpp& l = 39& rcl = 1399481969



如果代码无法解析max-年龄头(或服务器未指定max-age头),浏览器默认为5秒。


I'm hosting an WebApp and his API on different domains and use CORS to be able to work around the same origin policy. So far, so good. This works.

To only send a CORS preflight once per session I set the Access-Control-Max-Age to 20 days, But this is not working (tested in Chrome): https://db.tt/vfIW3fD2

What do I have to change?

解决方案

Chrome/Blink imposes a max preflight time of 10 minutes (600 seconds). Here's the location in source code that defines this:

https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/core/loader/CrossOriginPreflightResultCache.cpp&l=40&rcl=1399481969

Any preflight time above 10 minutes will be ignored, and 10 minutes will be used instead.

Different browsers may have different max age policies. Safari/WebKit caches for up to 5 minutes, while Firefox caches for up to 24 hours. The Chrome source code indicates that the max value exists in order to "minimize the risk of using a poisoned cache after switching to a secure network".

EDIT: Also note that the code defines a default timeout of 5 seconds:

https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/core/loader/CrossOriginPreflightResultCache.cpp&l=39&rcl=1399481969

If the code can't parse the max-age header (or the server doesn't specify a max-age header), the browser defaults to 5 seconds.

这篇关于CORS访问控制 - 最大年龄被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆