漏洞名称
跨源资源共享不安全配置漏洞
风险等级:
中
详细描述
跨源资源共享(cors)是一种机制,允许不同源之间的web资源相互交互。
在cors不安全配置漏洞中,web应用的服务器被误配置为允许来自任何来源的请求访问资源,或者错误地暴露敏感数据给不受信任的外部源。
解决办法
在server块上方增加
map $http_origin $cors_origin {
default "";
"http://自己的域名" $http_origin;
} 在server块中,对应端口的所有location块中增加以下配置
# 添加 cors 头部
if ($cors_origin) {
add_header 'access-control-allow-origin' $cors_origin always;
add_header 'access-control-allow-methods' 'get, post, put, delete, options' always;
add_header 'access-control-allow-headers' 'content-type, authorization' always;
add_header 'access-control-allow-credentials' 'true' always;
add_header 'access-control-max-age' 3600 always;
} 
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论