【问题标题】:How to Allow Google fonts in IdentityServer4如何在 IdentityServer4 中允许使用 Google 字体
【发布时间】:2018-04-14 16:13:03
【问题描述】:

要在 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?我很难找到它。

【问题讨论】:

    标签: security identityserver4 google-fonts


    【解决方案1】:

    对于其他卡住的人,需要修改 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

    【讨论】:

    • 谢谢,我正在寻找一种将 3rd 方脚本-src 添加到 identityServer4 基础应用程序的方法,根据您的评论,我明白了,谢谢,这很有帮助
    • 适用于 .NET 5 和 IdentityServer4,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-11-20
    • 2023-03-09
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 2017-12-22
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多