繁体   English   中英

因为它违反了以下内容安全策略指令:“style-src'self'”

[英]because it violates the following Content Security Policy directive: “style-src 'self'”

我有一个带有此标题的网页。

这是一个只有twitter bootstrap js的非交互式页面。

<head>
    <title>Versions: unknown bl version vs. 1.0.487 [flavor: HISTORIC_TIME]</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
    <script type="script" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
    <link rel="icon" href="/jenkins/view/QA/job/RoutingRegression/ws/src/main/resources/html_pages/images/favicon.png" type="image/gif" sizes="16x16">
</head>

在此输入图像描述

我在stackoverflow上看到了一些帖子,但无法理解如何解决这个问题。

拒绝加载样式表' https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css ',因为它违反了以下内容安全策略指令:“style-src'self'”。

landing_page.html:1拒绝加载样式表' https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css ',因为它违反了以下内容安全策略指令:“style- src'self'“。

我试图将<meta>更改为

<meta content="text/html; charset=utf-8 ;script-src 'self' http://onlineerp.solution.quebec 'unsafe-inline' 'unsafe-eval';" http-equiv="content-type">

在此输入图像描述

但它没有帮助

任何想法?

尝试将CS​​P拆分为单独的标记并添加style-src引用,如下所示:

<meta http-equiv="content-type" content="text/html; charset=utf-8 ;">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' http://onlineerp.solution.quebec 'unsafe-inline' 'unsafe-eval'; style-src 'self' maxcdn.bootstrapcdn.com"> 

这应该说你信任来自maxcdn.bootstrapcdn.com的样式。

有关内容安全策略的详细解释,请访问http://content-security-policy.com/

您不能将CDN用于js,您必须复制“ https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css ”的内容并在您的js中创建一个新文件目录并将其命名为bootstrap.min.js并将其中的所有内容粘贴到其中,然后在HTML文件头中删除包含此URL的行并使用此代替

<script src="js/jquery.min.js"></script>

确保这是包含所提及URL中所有数据的文件的写入路径

问候

将Content-Security-Policy元标记添加到标题中,如下所示:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' *.bootstrapcdn.com">

它允许您从域bootstrapcdn.com加载JavaScript,图像,CSS,字体,AJAX请求,框架和HTML5媒体等内容。

如果您仍然有相同的错误报告,则问题可能在于您使用的框架。 我在播放框架2.6.17中遇到了类似的问题,它默认启用了自己的Content-Security-Policy标头,修复了:

play.filters.headers.contentSecurityPolicy="default-src 'self' *.bootstrapcdn.com"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM