Angular 中的内容安全策略标头

时间:2021-06-03 08:36:56

标签: javascript .net angular azure

在 Angular 应用程序中,在 Content-Security-Policy 标头中允许需要哪些值? 它向我抛出这样的错误我还在我的 angular 应用程序中添加了 web.config 文件。

这里,我还附上了 index.html 文件。

index html file

Content-security-policy

1 个答案:

答案 0 :(得分:0)

从我的角度来看,我为上述项目找到了 2 个解决方案。

1.这是 web.config 文件。

    size    from    to
0   65      CEO     CEO
1   76      CEO     Employee
2   135     CEO     Vice President

这里仅适用于 Content-Security-Policy 标头

  <httpProtocol>
    <customHeaders>
    <remove name="X-Powered-By" />
    <add name="Referrer-Policy" value="no-referrer" />
    <add name="Permissions-Policy" value="camera=*,geolocation=*,microphone=*,autoplay=*,fullscreen=*,picture-in-picture=*,sync-xhr=*,encrypted-media=*,oversized-images=*" />
    <add name="Strict-Transport-Security" value="max-age=31536000; includeSubdomains" />
    <add name="X-Frame-Options" value="SAMEORIGIN" />
    <add name="X-Xss-Protection" value="1; mode=block" />
    <add name="X-Content-Type-Options" value="nosniff" />
    <add name="Content-Security-Policy" value="script-src https: 'unsafe-inline' 'unsafe-eval';
          style-src https: 'unsafe-inline' 'unsafe-eval';
          img-src https: data:;
          font-src https: data:;" />
  </customHeaders>
  </httpProtocol>

对于每个 API 调用,如果您需要添加以下标头,您可以像这样在 http-interceptor 文件中添加标头。

<add name="Content-Security-Policy" value="script-src 'self' 'unsafe-inline' 'unsafe-eval' https://stackpath.bootstrapcdn.com https://code.jquery.com https://cdnjs.com https://cdnjs.cloudflare.com; 
          style-src 'self' 'unsafe-inline' 'unsafe-eval' fonts.gstatic.com fonts.googleapis.com https://stackpath.bootstrapcdn.com https://use.fontawesome.com;
          object-src 'none';
          img-src 'self' data: blob:;
          font-src 'self' data: https://use.fontawesome.com fonts.gstatic.com fonts.googleapis.com ;"