2

我很难将多个 url 添加为脚本源

我试过了:

  • 将它们全部设置在同一个 ScriptSource 字符串中,但运行失败,说 url 无效
  • 所以我将它们链接起来,但它不起作用,只有最后一个在标题中返回

chrome中收到的标头

content-security-policy: default-src 'self';script-src 'self' 'unsafe-inline' unpkg.com;style-src 'self' 'unsafe-inline';img-src 'self';block-all-mixed-content
content-security-policy-report-only: default-src 'self';img-src 'none'

.NET Core 方面:

app.UseCsp(opts => opts
    .BlockAllMixedContent()
    .DefaultSources(s => s.Self())

    .ImageSources(s => s.Self())

    .ScriptSources(s => s.Self())
    .ScriptSources(s => s.UnsafeInline())
    .ScriptSources(s => s.CustomSources("www.googletagmanager.com")
                            .CustomSources("www.googleanalytics.com")
                            .CustomSources("unpkg.com")
                        )

    .StyleSources(s => s.Self())
    .StyleSources(s => s.UnsafeInline())               
);

有人可以帮我吗?

感谢您的帮助

4

1 回答 1

0

好的,我终于找到了,它是一个 params 参数,所以没有数组,只是用 , 分隔的字符串,

.ScriptSources(s => s.CustomSources("www.googletagmanager.com","www.googleanalytics.com","unpkg.com")
                        )
于 2021-03-18T11:17:21.487 回答