【问题标题】:Adding Content Security Policy to Azure Web APP向 Azure Web APP 添加内容安全策略
【发布时间】:2021-07-27 20:13:57
【问题描述】:

我正在尝试将 HSTS 和 X-XSS 添加到我的 Web 应用程序。我一直在使用这个进行测试: 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.config 不是必需的)

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

我将如何做到这一点?

谢谢!

【问题讨论】:

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


    【解决方案1】:

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

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

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

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

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

      Implement Content Security Policy using local htaccess file (Apache)

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

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

    【讨论】:

    • 感谢您的回复,但我如何确定哪个网络服务器?我不认为 IIS 或 Apcahe(我尝试使用 web.config 和 .htaccess,但没有效果)。 Azure Web APP中也没有使用Nginx
    • @QuentinMerlin IIS 适用于 Windows。
    • @QuentinMerlin 正如我所说,我不建议您使用添加 .htaccess 或 .conf 文件来执行此操作。更改代码是最好的方法!
    • @QuentinMerlin 如果我的回复有帮助,请接受它作为答案(单击回复旁边的标记选项将其从灰色切换为填写。),请参阅meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 2022-12-01
    • 1970-01-01
    • 2017-09-30
    • 2019-02-11
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    相关资源
    最近更新 更多