关于允许TRACE方法,HTTP X-XSS-Protection缺失,HTTP Content-Security-Policy缺失,X-Frame-Options Header未配置安全处理方法

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

基于Apache Web服务器对一下发现的安全问题进行配置处理,包含允许TRACE方法,HTTP X-XSS-Protection缺失,HTTP Content-Security-Policy缺失,X-Frame-Options Header未配置,HTTP X-Download-Options缺失,HTTP X-Content-Type-Options缺失,HTTP X-Permitted-Cross-Domain-Policies缺失,会话Cookie中缺少HttpOnly属性,会话Cookie中缺少secure属性的处理。

配置文件路径:/etc/httpd/conf/httpd.conf


一、允许TRACE方法

编辑配置文件:

/etc/httpd/conf/httpd.conf

在文件最后一行加上 TraceEnable off
如果不行的话在 vhost.conf 也加上以上的指令,重启apache

/etc/init.d/httpd restart

或是在httpd.conf里面每一个visual host里面加以下的module(RrwriteEngine需要compiler)

RewriteEngine on RewriteCond %{REQUEST_METHOD}^(TRACE|TRACK) RewriteRule .* – [F]

这一点比较复杂visual host都加上…重启
/etc/init.d/httpd restart 稍后生效

二、HTTP X-XSS-Protection缺失

修改apache的配置文件httpd.conf,在网站目录配置下即<Directory “网站目录”>段配置下,添加以下配置,重启生效

Header always append X-XSS-Protection '1; mode=block'

三、HTTP Content-Security-Policy缺失

修改apache的配置文件httpd.conf,在网站目录配置下即<Directory “网站目录”>段配置下,添加以下配置,重启生效

Header set Content-Security-Policy "default-src 'self' localhost:8080 'unsafe-inline' 'unsafe-eval' blob: data: ;"

四、HTTP X-Download-Options缺失

修改apache的配置文件httpd.conf,在网站目录配置下即<Directory “网站目录”>段配置下,添加以下配置,重启生效

Header add X-Download-Options "value"

五、HTTP X-Content-Type-Options缺失

修改apache的配置文件httpd.conf,在网站目录配置下即<Directory “网站目录”>段配置下,添加以下配置,重启生效

Header always set X-Content-Type-Options nosniff

六、HTTP X-Permitted-Cross-Domain-Policies缺失

修改apache的配置文件httpd.conf,在网站目录配置下即<Directory “网站目录”>段配置下,添加以下配置,重启生效

Header add X-Permitted-Cross-Domain-Policies "value"

七、X-Frame-Options Header未配置

修改apache的配置文件httpd.conf,在<Directory “网站目录”>段配置下,添加以下配置,重启生效

<Directory />
	AllowOverride none
	Require all denied
	<LimitExcept POST GET>
	Require valid-user
	</LimitExcept>
</Directory>

八、会话Cookie中缺少HttpOnly属性、会话Cookie中缺少secure属性

框架的入口文件插入

ini_set('session.cookie_httponly', true);
ini_set('session.cookie_secure', true);
$session->start();

总结

汇总下配置文件的编辑内容如下:

<VirtualHost *:80>
    ServerAdmin ***
    ServerName www.***.com
    ServerAlias ***.com
    DocumentRoot /home/website/
    DirectoryIndex index.shtml

    <Directory "/home/website/">
        AllowOverride All
        Order allow,deny
        Allow from all
        Header always append X-XSS-Protection '1; mode=block'
        Header set Content-Security-Policy "default-src 'self' localhost:80 'unsafe-inline' 'unsafe-eval' blob: data: api.map.baidu.com *.bdimg.com;"
        Header add X-Download-Options "value"
        Header always set X-Content-Type-Options nosniff
        Header add X-Permitted-Cross-Domain-Policies "value"
        <LimitExcept POST GET>
                Require valid-user
        </LimitExcept>
    </Directory>

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
        RewriteRule ^/(.*)$ /index.php?_url=/$1 [QSA,L]
        RewriteEngine on RewriteCond %{REQUEST_METHOD}^(TRACE|TRACK) RewriteRule .* – [F]
    </IfModule>
    php_flag magic_quotes_gpc 0
</VirtualHost>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

無薪法师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值