Azure 交换在应用内容安全策略后不起作用

Azure Swap does not work after applying Content Security Policy

我刚刚在我的开发环境中将内容安全策略应用到我的 Azure Web 应用程序,它工作正常。

我还可以将它上传到我在 Azure 上的暂存站点,它在那里运行良好,策略被正确应用,然后由我的浏览器强制执行。但是,当我进行交换时,出现以下错误:

Cannot swap slots for site 'MySite' because the worker process in 'staging' slot aborted the warmup request. This may happen if site has IP Restriction or URL rewrite rules that block HTTP requests.

这是我正在应用的政策(在我的 web.config 中定义)

<add name="Content-Security-Policy"
     value="default-src     'none';
            script-src      'self' https: 'unsafe-inline' 'unsafe-eval';
            style-src       'self' https: 'unsafe-inline';
            img-src         'self' https: 'unsafe-inline' data: blob:;
            connect-src     'self' https:;       
            font-src        'self' https:;
            object-src      'none';
            media-src       'self';
            child-src       'self';
            form-action     'self';
            frame-ancestors 'none'"/>

有什么问题?

A​​zure 不喜欢 web.config.

中 Content-Security-Policy 值中的回车符 returns

如果您使用 App Service Editor(可通过 Azure 门户获得)检查 web.config,那么您会看到马车 returns 已经被编码并变成了

&#xD;&#xA;

创建以下无效 CSP,这就是交换中断的原因:

default-src 'none';&#xD;&#xA; script-src 'self' https: 'unsafe-inline' 'unsafe-eval';&#xD;&#xA; style-src 'self' https: 'unsafe-inline';&#xD;&#xA; img-src 'self' https: 'unsafe-inline' data: blob:;&#xD;&#xA; connect-src 'self' https:; &#xD;&#xA; font-src 'self' https:;&#xD;&#xA; object-src 'none';&#xD;&#xA; media-src 'self';&#xD;&#xA; child-src 'self';&#xD;&#xA; form-action 'self';&#xD;&#xA; frame-ancestors 'none'

简而言之,我们需要在一行中输入所有 CSP,这会降低可读性,但 Azure 需要交换。