漏洞修复:HTML5: Overly Permissive CORS Policy

本文讨论了CORS(跨源资源共享)的安全问题,建议限制Access-Control-Allow-Origin头的访问权限,避免使用通配符,并提供了一种实现白名单策略的方法。通过在服务器端设置特定的Access-Control-Allow-Origin值,可以确保只有信任的域名能够访问资源,防止敏感信息泄露。同时,介绍了如何通过判断请求来源并返回403错误来进一步增强安全性。
摘要由CSDN通过智能技术生成

描述

A resource on the target website has been found to be shared across websites using CORS with an open access control policy. Cross-Origin Resource Sharing, commonly referred to as CORS, is a technology that allows a domain to define a policy for its Review your Cross-Origin-Resource-Sharing policy and consider restricting access to only trusted domains. Never use wildcard open-access permissions (e.g. “*”) in the Access-Control-Allow-Origin header. Additionally, do not automatically include Access -Control-Allow-Origin headers in the response unless the request is cross-domain. Alternatively, implement an allow list of known domains that are allowed to access this domain and only include domains that actually tried to access the resource. Otherwise, reject the request and reply with only host domain not exposing all allowed domains. Reserve the use of CORS for resources that cannot be shared in other ways (e.g. JavaScript can be accessed using SCRIPT tag as well as images can be accessed using IMG tag from other domains). Finally, make sure that this resource does not disclose any sensitive information and only share resources required to preserve functionality in contrast to an open domain CORS access.

解决方案

在server中添加
add_header Access-Control-Allow-Origin 允许访问的ip或者域名,允许访问的ip或者域名;
例如:

server{
	add_header Access-Control-Allow-Origin  192.168.11.62;
}

或者

server{
	add_header 'Access-Control-Allow-Origin' $http_origin;
}

实际情况中,还是扫到了
另一个解决方案
判断$http_origin
如果不在白名单,直接403

if ( $http_origin !~* '192.168.1.1|172.1.1.1') {
        return 403 ;
}

参考

https://blog.csdn.net/CutelittleBo/article/details/122728054

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值