漏洞修复:HTML5: CORS Prolonged Caching of Preflight Response

描述

WebInspect has discovered a preflight response that is configured to be cached for a prolonged amount of time. The time a response is allowed to be cached is conveyed using an Access-Control-Max-Age response header and a value more than 30 minutes is considered to be prolonged. Cross-Origin Resource Sharing, commonly referred to as CORS, is a technology that allows a domain to define a policy for its resources to be accessed by a web page hosted on a different domain using cross domain XML HTTP Requests (XHR). Historically, the browser restricts cross domain XHR requests to abide by the same origin policy. At its basic form, the same origin policy sets the script execution scope to the resources available on the current domain and prohibits any communication to domains outside this scope. Therefore, execution and incorporation of remote methods and functions hosted on domains outside of the current domain are effectively prohibited. While CORS is supported on all major browsers, it also requires that the domain correctly defines the CORS policy in order to have its resources shared with another domain. These restrictions are managed by access policies typically included in specialized response headers, such as:
Access-Control-Allow-Origin
Access-Control-Allow-Headers
Access-Control-Allow-Methods
Access-Control-Max-Age
The browser generates a preflight OPTIONS request whenever the cross domain request made by the web page is anything other than a simple HTTP request. A GET or POST HTTP request with no special headers or credentials is considered a simple request. A response for a preflight request exposes the server’s CORS policy via specialized headers mentioned above. After examining the required permissions, the browser makes the actual request that the web page initially performed. This extra preflight request adds overhead and hence the server can configure its preflight response to be cached.

解决方案

add_header Access-Control-Max-Age 1200;
例如:

server{
	add_header Access-Control-Max-Age 1200;
}

解决思路

大体意思是
预检响应的长时间缓存可能会带来安全威胁,因为可以在服务器上更新策略,而浏览器仍将允许未经授权访问基于原始缓存策略的资源。允许缓存响应的时间使用 Access-Control-Max-Age 响应标头来传达,超过 30 分钟的值被认为是延长的。
那我们就设置为30分钟以内,目前设置为了20分钟也就是1200秒

参考

https://vulncat.fortify.com/en/detail?id=desc.dynamic.html.html5_cors_prolonged_caching_of_preflight_response

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Max-Age

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个报错是由于浏览器的CORS(跨域资源共享)策略所引起的。浏览器在发送跨域的XMLHttpRequest请求时,会先发送一个预检请求(OPTIONS请求)来检查服务器是否允许该跨域请求。如果预检请求的响应不满足CORS策略的要求,浏览器就会阻止该请求。 解决这个问题的方法有几种: 1. 在服务器端添加CORS头部:根据引用中的PHP代码示例,可以在服务器端设置相应的CORS头部,允许指定的跨域请求。 2. 修改默认Header参数:根据引用和的报错信息中提到的,默认Header参数可能导致请求被阻止,可以尝试修改默认Header参数,以满足CORS策略的要求。 3. 使用代理服务器:可以通过设置代理服务器来解决CORS问题。将请求发送到代理服务器上,然后由代理服务器再发送请求到目标服务器,这样就可以绕过浏览器的CORS策略限制。 需要注意的是,解决CORS问题要根据具体的情况来定,具体的方法可能会因服务器端和客户端的不同而有所差异。建议参考引用、和中提供的信息,结合自己的实际情况来进行解决。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check](https://blog.csdn.net/csdn_avatar_2019/article/details/126538547)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [前端报错:has been blocked by CORS policy: Response to preflight request doesn‘t pass access ...](https://blog.csdn.net/qq_39408664/article/details/130195520)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值