hun*_*aub 6 iframe html5 google-chrome sandbox content-security-policy
我认为这只是对规范的一个简单误解.但是,我遇到了在沙盒保护的iFrame中包含脚本的问题.具体来说,我正在处理的代码如下.
在top.html中:
<iframe src="framed.html" sandbox="allow-scripts"></iframe>
Run Code Online (Sandbox Code Playgroud)
在framed.html中
...
<head>
<meta http-equiv="Content-Security-Policy" content="script-src example.com">
<script src="http://example.com/script.js"></script>
</head>
...
Run Code Online (Sandbox Code Playgroud)
在Chrome中运行此文件时,它会给我错误:
拒绝加载脚本" http://example.com/script.js ",因为它违反了以下内容安全策略指令:"script-src localhost:9000".
为什么阻止脚本加载?我知道没有allow-same-origin,iFrame获得一个完全独特的起源,不等于任何其他起源.因此,script-src 'self'不会奏效.但是,我试图从CSP中明确调用的原点加载脚本.思考?
更新:创建JSFiddle以展示问题.
当您使用具有唯一来源的沙盒页面时,您无法在CSP中放置没有方案的主机,这就是违反该策略的原因.使用script-src https://example.com或script-src http://example.com甚至script-src https://example.com https: //example.com,CSP将正确放宽(请注意,CSP是基于白名单的,默认情况下大多数情况都是不允许的.
; Schemes: "https:" / "custom-scheme:" / "another.custom-scheme:"
scheme-source = scheme-part ":"
; Hosts: "example.com" / "*.example.com" / "https://*.example.com:12/path/to/file.js"
host-source = [ scheme-part "://" ] host-part [ port-part ] [ path-part ]
scheme-part = scheme
; scheme is defined in section 3.1 of RFC 3986.
host-part = "*" / [ "*." ] 1*host-char *( "." 1*host-char )
host-char = ALPHA / DIGIT / "-"
port-part = ":" ( 1*DIGIT / "*" )
path-part = path-abempty
; path-abempty is defined in section 3.3 of RFC 3986.
Run Code Online (Sandbox Code Playgroud)
但是没有allow-same-origin令牌的沙盒框架将具有null原点,并且URL匹配算法不允许无方案指令匹配(下面显示的算法的相关部分):
6.6.1.6.url是否与重定向计数在原点中匹配表达式?给定URL(url),源表达式(表达式),原点(原点)和数字(重定向计数),如果url匹配表达式,则此算法返回"匹配",否则返回"不匹配".
...
如果表达式与主机源语法匹配:
如果url的主机是
null,则返回"不匹配".
- 如果url的主机是
null,则返回"不匹配".如果expression没有scheme-part,则返回"不匹配",除非满足下列条件之一:
- 原产地计划是网址计划
- origin的方案是"http",而url的方案是"https","ws"或"wss".
- origin的方案是"https",而url的方案是"wss".
在给定的示例中:
origin是null(因为sandbox没有使用allow-same-origin).http://example.com/script.js该null产地的方案不符合任何过去三年的情况下,所以没有计划将主机名不匹配任何URL,因此违反策略.
| 归档时间: |
|
| 查看次数: |
8955 次 |
| 最近记录: |