x-xss x-frame-options strict-transport-security
2016-06-22 by dongnan
功能简介
服务器响应头里面缺乏 Strict-Transport-Security 、X-Frame-Options、X-XSS-Protection。
- Strict-Transport-Security标志,一定程度上可防止- HTTPS的中间人攻击,
- X-Frame-Options可防止点击劫持攻击(防止本网站被其他网站嵌套包含),
- X-XSS-Protection一定程度上可防止反射型跨站脚本攻击。
举个栗子
带有 x-xss x-frame-options strict-transport-security 安全头部信息。
# 执行命令
curl -IL https://ssl.ywwd.net
HTTP/1.1 200 OK
Date: Tue, 19 Apr 2016 10:08:38 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Set-Cookie: PHPSESSID=163872facd9952ee04bd517b5eddf075; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: UUID=46c0fcdb-0e4d-f7e3-9798-571603b64d1f; expires=Wed, 19-Apr-2017 10:08:38 GMT; Max-Age=31536000; path=/; domain=.ywwd.net; secure; httponly
XContent-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=86400
Set-Cookie: SESSION_COOKIE=test01; path=/
如何添加这些添加这些头部?
以 nginx 为例配置文件如下:
server
{
    listen      80;
    #....省略
    add_header XContent-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Frame-Options SAMEORIGIN;
    add_header Strict-Transport-Security "max-age=86400";
}
测试
nginx 设置 X-Frame-Options SAMEORIGIN 头部,防止被 iframe 框架加载你的网站页面。
