Skip to content

Commit a284913

Browse files
authored
Do not check callerRealm for eval (#540)
According to WPTs web-platform-tests/wpt#32898, Firefox, Safari and Chrome only check policies of the calleeRealm for determining if eval is allowed. Discussions on #438 explain why it is probably hopeless to correctly check the callerRealm. This change adapt the spec to adhere the vendors' implementation, and only check calleeRealm.
1 parent 54fe8a8 commit a284913

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

index.bs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,50 +1408,49 @@ spec: WebAssembly-web-api-api; urlPrefix: https://webassembly.github.io/spec/web
14081408
EnsureCSPDoesNotBlockStringCompilation(|callerRealm|, |calleeRealm|, |source|)
14091409
</h4>
14101410

1411-
Given two <a>realms</a> (|callerRealm| and |calleeRealm|), and a string (|source|), this algorithm
1412-
returns normally if string compilation is allowed, and throws an "`EvalError`" if not:
1411+
Given two <a>realms</a> (<var ignore>callerRealm</var> and |calleeRealm|),
1412+
and a string (|source|), this algorithm returns normally if string compilation
1413+
is allowed, and throws an "`EvalError`" if not:
14131414

1414-
1. Let |globals| be a list containing |callerRealm|'s [=Realm/global object=] and |calleeRealm|'s
1415-
[=Realm/global object=].
1415+
1. Let |result| be "`Allowed`".
14161416

1417-
2. For each |global| in |globals|:
1417+
2. For each |policy| in |calleeRealm|'s [=global object/CSP list=]:
14181418

1419-
1. Let |result| be "`Allowed`".
1419+
1. Let |source-list| be `null`.
14201420

1421-
2. For each |policy| in |global|'s [=global object/CSP list=]:
1421+
2. If |policy| contains a [=directive=] whose [=directive/name=] is "`script-src`", then
1422+
set |source-list| to that [=directive=]'s [=directive/value=].
14221423

1423-
1. Let |source-list| be `null`.
1424+
Otherwise if |policy| contains a [=directive=] whose [=directive/name=] is
1425+
"`default-src`", then set |source-list| to that directive's [=directive/value=].
14241426

1425-
2. If |policy| contains a [=directive=] whose [=directive/name=] is "`script-src`", then
1426-
set |source-list| to that [=directive=]'s [=directive/value=].
1427+
3. If |source-list| is not `null`, and does not contain a [=source expression=] which is
1428+
an [=ASCII case-insensitive=] match for the string "<a grammar>`'unsafe-eval'`</a>",
1429+
then:
14271430

1428-
Otherwise if |policy| contains a [=directive=] whose [=directive/name=] is
1429-
"`default-src`", then set |source-list| to that directive's [=directive/value=].
1431+
1. Let |violation| be the result of executing [[#create-violation-for-global]] on
1432+
|calleeRealm|, |policy|, and "`script-src`".
14301433

1431-
3. If |source-list| is not `null`, and does not contain a [=source expression=] which is
1432-
an [=ASCII case-insensitive=] match for the string "<a grammar>`'unsafe-eval'`</a>",
1433-
then:
1434+
2. Set |violation|'s [=violation/resource=] to "`eval`".
14341435

1435-
1. Let |violation| be the result of executing [[#create-violation-for-global]] on
1436-
|global|, |policy|, and "`script-src`".
1436+
3. If |source-list| [=list/contains=] the expression
1437+
"<a grammar>`'report-sample'`</a>", then set |violation|'s [=violation/sample=] to
1438+
the substring of |source| containing its first 40 characters.
14371439

1438-
2. Set |violation|'s [=violation/resource=] to "`eval`".
1440+
4. Execute [[#report-violation]] on |violation|.
14391441

1440-
3. If |source-list| [=list/contains=] the expression
1441-
"<a grammar>`'report-sample'`</a>", then set |violation|'s [=violation/sample=] to
1442-
the substring of |source| containing its first 40 characters.
1442+
5. If |policy|'s [=policy/disposition=] is "`enforce`", then set |result| to
1443+
"`Blocked`".
14431444

1444-
4. Execute [[#report-violation]] on |violation|.
1445-
1446-
5. If |policy|'s [=policy/disposition=] is "`enforce`", then set |result| to
1447-
"`Blocked`".
1448-
1449-
3. If |result| is "`Blocked`", throw an `EvalError` exception.
1445+
3. If |result| is "`Blocked`", throw an `EvalError` exception.
14501446

14511447
ISSUE(tc39/ecma262#938): {{HostEnsureCanCompileStrings()}} does not include the string which is
14521448
going to be compiled as a parameter. We'll also need to update HTML to pipe that value through
14531449
to CSP.
14541450

1451+
Note: The parameter |callerRealm| is ignored on purpose, see
1452+
<a href="https://github.com/w3c/webappsec-csp/issues/438">Issue 438</a>.
1453+
14551454
<h3 id="wasm-integration">Integration with WebAssembly</h3>
14561455

14571456
WebAssembly defines the {{HostEnsureCanCompileWasmBytes()}} abstract operation

0 commit comments

Comments
 (0)