列举的这些HTTP响应头中,哪些最有效?
2025-07-02
20
参考资料
列举的这些HTTP响应头中,哪些最有效?
有效的HTTP响应头及其操作示例:
Content-Security-Policy
防止XSS攻击
示例:
Content-Security-Policy: default-src 'self'
X-Content-Type-Options
阻止MIME类型嗅探
示例:
X-Content-Type-Options: nosniff
X-Frame-Options
防止点击劫持
示例:
X-Frame-Options: DENY
Strict-Transport-Security (HSTS)
强制HTTPS
示例:
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-XSS-Protection
启用浏览器XSS过滤器
示例:
X-XSS-Protection: 1; mode=block
Referrer-Policy
控制Referer信息
示例:
Referrer-Policy: no-referrer
Feature-Policy
限制浏览器功能
示例:
Feature-Policy: geolocation 'none'
操作示例(Nginx配置):
add_header Content-Security-Policy "default-src 'self'"; add_header X-Content-Type-Options "nosniff"; add_header X-Frame-Options "DENY"; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains"; add_header X-XSS-Protection "1; mode=block"; add_header Referrer-Policy "no-referrer"; add_header Feature-Policy "geolocation 'none'";