了解HTTP安全标头(HTTP Security Headers)
安全标头是指定网络客户端(通常是浏览器)和应用程序服务器之间 HTTP 通信行为和安全相关细节的 HTTP 响应标头,其目的是促进深度防御。一旦设置了这些 HTTP 响应头,就能限制现代浏览器运行到容易预防的漏洞,并增加应用程序的安全层。
每个应用程序中配置以下安全标头:
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-xss-protection: 0
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
permissions-policy: battery=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()
content-security-policy: frame-ancestors ‘self’; upgrade-insecure-requests; block-all-mixed-content;
strict-transport-security
这个安全标头的全称是HTTP Strict Transport Security(HSTS),它告诉浏览器仅通过HTTPS而不是HTTP来与服务器通信。这可以防止SSL剥离攻击,其