是否可以在 Azure Blob 存储中托管的静态网站上添加内容安全策略 ( CSP ) header ?
我可以看到您可以通过使用 Azure CLI 和以下命令来添加元数据:
az storage blob metadata update --container-name --name "blobname" --metadata key=value
但是,这些永远不会最终传播到 HTTP header 。
有没有办法向 blob 添加自定义 header ?
最佳答案
因为目前此功能不可用(您可以前往 feedback site 对该功能进行投票),因此您可以通过 Azure Function Functions 来实现。
您可以引用以下博客:Static web hosting with security headers on Azure .
还有一种方法(这是 msdn enter link description here 中的答案)可以向 Web 添加 X-XSS 保护。在应用程序 wwwroot 文件夹中创建 web.config 文件,然后粘贴以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- START x-xss protection -->
<httpProtocol>
<customHeaders>
<add name="X-Xss-Protection" value="1; mode=block" />
<add name="Content-Security-Policy" value="default-src 'self';" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<!-- END x-xss protection -->
<rewrite>
<rules>
<!-- BEGIN rule TAG FOR HTTPS REDIRECT -->
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- END rule TAG FOR HTTPS REDIRECT -->
</rules>
</rewrite>
</system.webServer>
</configuration>
关于azure - Azure Blob 存储中托管的静态网站的 CSP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55933255/