如何在IdentityServer4中允许使用Google字体

4
要在IdentityServer3中使用Google字体,以下的Content-Security-Policy从未起作用:
<meta http-equiv="Content-Security-Policy" 
      content=" style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
                font-src 'self' 'unsafe-inline' https://fonts.gstatic.com data:">

相反,我们在idsrvApp.UseIdentityServer构造函数中配置了CspOptions,这确实起作用:

CspOptions = new CspOptions {
    FontSrc = "https://fonts.gstatic.com",
    StyleSrc = "https://fonts.googleapis.com",
    Enabled = true
}

我们如何在IdentityServer4中配置CspOptions?我找不到它。
1个回答

9
对于其他遇到此问题的人,需要修改IdentityServer4快速入门文件中的SecurityHeadersAttribute.cs文件。添加以下行即可解决问题:
var csp = "default-src 'self'; object-src 'none'; frame-ancestors 'none'; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self';";

// These two lines enable google fonts
csp += "font-src 'self' https://fonts.gstatic.com;";
csp += "style-src 'self' https://fonts.googleapis.com;";

该文件位于quickstart/SecurityHeadersAttribute.cs。

谢谢,我一直在寻找一种方法将第三方脚本-src添加到IdentityServer4基础应用程序中,通过您的评论,我终于弄清楚了,感谢您的帮助。 - Ahmed HABBACHI
适用于.NET 5和IdentityServer4,谢谢! - Anthony Liriano

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接