Html Error: Refused to load the script because it violates the following Content Security Policy directive

Html Error: Refused to load the script because it violates the following Content Security Policy directive

Font awesome 无法加载请帮助。我需要使用很棒的字体图标,但出现此错误。 拒绝加载脚本 'https://use.fontawesome.com/a780df76b3.js',因为它违反了以下内容安全策略指令:“script-src 'self'”。请注意 'script-src-elem' 未明确设置,因此 'script-src' 用作后备

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
    <meta name="google-site-verification" content="3WujPQ31psszBWWagcwEXBhSUGSZreEvBe4ax5T1i2E" />
    <title>Authenticate</title>
    <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
    <link rel="preconnect" href="https://fonts.gstatic.com" />
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet" />

    <style>
        * {
            font-family: "Montserrat", sans-serif;
        }

        .google {
            margin-left: 630px;
            margin-bottom: 100px;
            margin-top: 80px;
        }

        .title {
            font-family: "Montserrat", sans-serif;
        }
        .google{
            margin: 0 auto;
            color: #111
        }

        .github {
            margin: 0 auto;
            color: #111
        }
    </style>
    <script  defer src="https://use.fontawesome.com/a780df76b3.js"></script>

</head>

<body>
    <h1 class="text-xl font-black my-9 text-center mx-auto title">
        Authenticate to start using
    </h1>
    <a id="google-button" class="btn btn-block btn-social btn-google google" href="/auth/google/">
        <i class="fa fa-google"></i> Login with Google
    </a>
    <!--Github-->
    <a id="github-button" class="btn btn-block btn-social btn-github github" href="/auth/github/">
        <i class="fa fa-github"></i> Login with GitHub
    </a>





</body>

</html>

正在显示这个

正如您在“运行 代码片段”中看到的那样,您的代码在这里运行良好。因此,原因在于您的 web-server - 它默认发布内容安全策略 "script-src 'self'"

只需将 https://use.fontawesome.com host-source 添加到 script-src 指令中:
"script-src 'self' https://use.fontawesome.com".

如果您不知道它是什么,请关闭 CSP。因为默认 CSP 设置也将至少被阻止:https://unpkg.com/tailwindcss@^2/dist/tailwind.min.csshttps://fonts.gstatic.comhttps://fonts.googleapis.comstyle-srcscript-src 指令中。

既然你没有说明用什么作为服务器,我就试着猜一下:Node.js + Helmet 4 管理安全headers.
在 Helmet 中禁用 contentSecurityPolicy 中间件但保留其余 headers:

helmet({
  contentSecurityPolicy: false,
})