简体   繁体   English

在ASP.NET MVC中使用web.config的内容安全策略标头列表保护

[英]Content security policy header list protection using web.config in ASP.NET MVC

eg Image file Webconfig file which i manage in my project 例如我在项目中管理的图像文件Webconfig文件

eg Image file of Issue facing for 404Javascript.js I am facing the following Content Security Policy issue in my existing ASP.NET MVC project. 例如404Javascript.js面临的问题的图像文件,我在现有的ASP.NET MVC项目中面临以下内容安全策略问题。

We used https://sitecheck.sucuri.net/ to check security scan 我们使用https://sitecheck.sucuri.net/来检查安全扫描

Issue - Security Headers 问题-安全标题

Missing security header for XSS Protection. XSS Protection缺少安全标头。 Affected pages: 受影响的页面:

Missing security header to prevent Content Type sniffing. 缺少安全标头以防止内容类型嗅探。 Affected pages: 受影响的页面:

Missing Strict-Transport-Security security header. 缺少Strict-Transport-Security安全标头。 Affected pages: 受影响的页面:

Default server banners displayed. 显示默认服务器横幅。 Your site is displaying your web server default banners. 您的网站正在显示您的Web服务器默认横幅。 Affected pages: 受影响的页面:
https://www.example.com/404javascript.js https://www.example.com/404javascript.js
https://www.example.com/404testpage4525d2fdc https://www.example.com/404testpage4525d2fdc

We are trying to resolve that using web config file with following configuration: 我们正在尝试使用具有以下配置的网络配置文件来解决该问题:

<customHeaders>
  <remove name="X-Powered-By" />
  <add name="X-Frame-Options" value="DENY" />
  <add name="X-Xss-Protection" value="1; mode=block" />
  <add name="X-Content-Type-Options" value="nosniff" />
  <add name="Referrer-Policy" value="no-referrer" />
  <add name="X-Permitted-Cross-Domain-Policies" value="none" />
  <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
  <add name="Feature-Policy" value="accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'" />
</customHeaders>

<httpRuntime targetFramework="4.6.1" maxRequestLength="1048576"  
             requestValidationMode="4.0" executionTimeout="110" 
             enableVersionHeader="false" />

But we are still facing same issue after changing configuration, please look at our process where we are wrong or any alternate solution. 但是,在更改配置后,我们仍然面临着同样的问题,请查看我们的处理过程中出现的错误或任何其他解决方案。

Make sure you add custom header tag in system.webserver section not in the system.web section.: 确保在system.webserver部分而不是system.web部分中添加自定义标头标记:

<system.webServer>
  <httpProtocol>
    <customHeaders>

      <add name="X-Frame-Options" value="SAMEORIGIN" />

      <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains"/>

      <add name="X-XSS-Protection" value="1; mode=block" />

      <add name="X-Content-Type-Options" value="nosniff" />

      <add name="Content-Security-Policy" value="default-src 'self'; font-src *;img-src * data:; script-src *; style-src *;" />

      <add name="Referrer-Policy" value="strict-origin" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

after doing chnages restart the iis server. 更改后,重新启动iis服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM