向 Azure Web APP 添加内容安全策略

时间:2021-05-05 13:37:57

标签: node.js azure azure-web-app-service

我正在尝试向我的 Web 应用程序添加 HSTS 和 X-XSS。我一直在使用这个进行测试: https://securityheaders.io

我一直使用此链接作为起始参考:

https://tomssl.com/2016/06/30/how-to-fix-the-http-response-headers-on-azure-web-apps-to-get-an-a-plus-on-securityheaders-io/

我在 /site/wwwroot 中添加了 web.config 文件,我停止并启动了我的 web 应用程序,但它看起来没有效果(我认为 web.config 不是必需的)

我有 Linux 网络应用程序(Slack:NodeJS)

我将如何做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以在代码中更改 Content-Security-Policy。这是解决您问题的更好方法。

相关博客How To Secure Node.js Applications with a Content Security Policy

enter image description here

我发现在azure linux中,并不能直接知道linux服务器使用的是哪个webserver,所以没有尝试下面的方法。如果您有兴趣,可以提出支持寻求帮助,让 Microsoft 工程师帮助您。

由于您使用的是 linux 平台,因此您需要确定您在网络应用中使用的网络服务器。

  1. 如果使用apache,可以添加.htaccess文件来解决问题。

    Implement Content Security Policy using local htaccess file (Apache)

  2. 如果是 nginx,你可以添加 yourcustom.conf 文件来做到这一点。

    https://gist.github.com/plentz/6737338