网站安全
网站cookie没有设置HTTPOnly标志,存在XSS风险。
使用开源zap 扫描网站。出现如下警报:Cookie No HttpOnly Flag 解决方案:
1.修改 Web.config 文件,增加HttpOnly属性。
- 打开你的网站根目录中的 Web.config 文件。
- 在 <system.web> 或 <system.webServer> 部分中添加以下代码:
md
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
...
</system.webServer>
...
<system.web>
<httpCookies httpOnlyCookies="true" />
</system.web>
</configuration>2.使用 IIS URL Rewrite 模块
确保你的 IIS 服务器上安装了 URL Rewrite 模块 安装完成后,在你的 Web.config 文件中添加以下内容:
md
<system.webServer>
...
<rewrite>
<outboundRules>
<rule name="Add HttpOnly" preCondition="No HttpOnly">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; HttpOnly" />
<conditions>
</conditions>
</rule>
<preConditions>
<preCondition name="No HttpOnly">
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; HttpOnly" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
...
<system.webServer>