Skip to content

Commit 671892e

Browse files
authored
Merge pull request #1 from carlosjoan91/main
Add mention of eval-like functions
2 parents 0a09543 + 52a47ca commit 671892e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ feedback on the proposed solution. It has not been approved to ship in Chrome.
2121
- [<strong>Non-goals</strong>](#strongnon-goalsstrong)
2222
- [**Use cases**](#use-cases)
2323
- [Allowlisting specific URLs for use with script-src](#allowlisting-specific-urls-for-use-with-script-src)
24-
- [Allowlisting specific scripts for use with `eval` or `Function`](#allowlisting-specific-scripts-for-use-with-eval-or-function)
24+
- [Allowlisting specific scripts for use with `eval` or `eval`-like functions](#allowlisting-specific-scripts-for-use-with-eval-or-eval-like-functions)
2525
- [**Proposed Solution**](#proposed-solution)
2626
- [Add new CSP directive](#add-new-csp-directive)
2727
- [Introduce new url-hashes keyword to cover script-src attributes](#introduce-new-url-hashes-keyword-to-cover-script-src-attributes)
28-
- [Extend script hashes to cover eval](#extend-script-hashes-to-cover-eval)
28+
- [Extend script hashes to cover eval and eval-like functions](#extend-script-hashes-to-cover-eval-and-eval-like-functions)
2929
- [Add hashes to CSP reporting](#add-hashes-to-csp-reporting)
3030
- [**Deployment use case examples**](#deployment-use-case-examples)
3131
- [Single-page applications](#single-page-applications)
@@ -43,7 +43,7 @@ feedback on the proposed solution. It has not been approved to ship in Chrome.
4343

4444
## Introduction
4545

46-
We're proposing a new CSP directive to help websites protect themselves against DOM XSS. Developers will be able to allowlist scripts that are allowed to execute through the existing hashes mechanism, that will now extend to cover [script-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) URLs and [eval](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval). This facilitates an easier to deploy, robust CSP policy that mitigates XSS by blocking unallowed inline and eval scripts.
46+
We're proposing a new CSP directive to help websites protect themselves against DOM XSS. Developers will be able to allowlist scripts that are allowed to execute through the existing hashes mechanism, that will now extend to cover [script-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) URLs and [eval](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) (and other eval-like functions). This facilitates an easier to deploy, robust CSP policy that mitigates XSS by blocking unallowed inline and eval scripts.
4747

4848
To be secure, a policy needs to permit legitimate scripts to execute, while blocking any scripts that the application doesn't expect. In practice, this means avoiding host-based allowlists and having a strict CSP allowing the execution of scripts by using nonces or hashes.
4949

@@ -78,9 +78,9 @@ The core challenge for CSP is to distinguish between legitimate scripts (intende
7878
Sites that want to allowlist specific scripts for use with script-src currently have 2 options, allowlist the specific scripts contents through [subresource integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity), which is not practical for scripts that change often (e.g. analytics scripts), or use [host-source](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#host-source) to allowlist hostnames, which has the issues [described in further detail below](?tab=t.0#bookmark=id.i59bvq2i29zz). These issues would be addressed if we have a mechanism to allowlist full URLs for script-src.
7979

8080

81-
### Allowlisting specific scripts for use with `eval` or `Function`
81+
### Allowlisting specific scripts for use with `eval` or `eval`-like functions
8282

83-
The only existing mechanism to use eval or Function is by enabling them with [unsafe-eval](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_eval_expressions), which allows all scripts. This means that currently any site that needs to use eval must expose itself to eval-based XSS risks. Allowlisting individual scripts would prevent this risk.
83+
The only existing mechanism to use eval or eval-like functions (Function, and string literals in setTimeout, setInterval, and setImmediate) is by enabling them with [unsafe-eval](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_eval_expressions), which allows all scripts. This means that currently any site that needs to use eval must expose itself to eval-based XSS risks. Allowlisting individual scripts would prevent this risk.
8484

8585

8686
## **Proposed Solution**
@@ -128,9 +128,9 @@ Content-Security-Policy: script-src 'url-hashes' 'sha256-SHA256("script.js")';
128128

129129

130130

131-
### Extend script hashes to cover eval
131+
### Extend script hashes to cover eval and eval-like functions
132132

133-
Similarly, scripts run within eval() currently can only be allowed via unsafe-eval, which allows any script, with no mechanism to allowlist only specific ones. This proposes that script hashes should cover scripts loaded via eval, in addition to inline scripts, e.g. given a CSP of `script-src 'sha256-SHA256(foo)'; `permitting `eval(foo);`
133+
Similarly, scripts run within eval() currently can only be allowed via unsafe-eval, which allows any script, with no mechanism to allowlist only specific ones. This proposes that script hashes should cover scripts loaded via eval (Function, or string literals in setTimeout, setInterval, and setImmediate), in addition to inline scripts, e.g. given a CSP of `script-src 'sha256-SHA256(foo)'; `permitting `eval(foo);`
134134

135135

136136
### Add hashes to CSP reporting
@@ -145,7 +145,7 @@ This necessitates adding two fields: the hash of the content of a script (for in
145145

146146
### Single-page applications
147147

148-
To create a hash-based policy for a static, single-page application, the developer can run tooling to parse the HTML of the application and calculate the hashes of all inline &lt;script> blocks, URLs present in &lt;script src> attributes, and code blocks used in eval or New Function() blocks.
148+
To create a hash-based policy for a static, single-page application, the developer can run tooling to parse the HTML of the application and calculate the hashes of all inline &lt;script> blocks, URLs present in &lt;script src> attributes, and code blocks used in eval, New Function(), or string literals in setTimeout, setInterval, and setImmediate blocks.
149149

150150
The tooling can generate a list of hashes and potentially automatically insert an HTML &lt;meta> tag with their values, e.g. &lt;meta http-equiv="Content-Security-Policy" content="script-src ‘sha256-abc...” url-hashes 'sha256-xyz…'">. The developer can optionally add the 'strict-dynamic' keyword to permit allowlisted scripts to transitively load additional scripts at runtime.
151151

index.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Include Can I Use Panels: yes
2020
Introduction {#intro}
2121
=====================
2222

23-
For now, see the [explainer]([REPOSITORYURL]).
23+
For now, see the [explainer](https://github.com/explainers-by-googlers/script-src-v2/).
2424

2525
See [https://garykac.github.io/procspec/](https://garykac.github.io/procspec/),
2626
[https://dlaliberte.github.io/bikeshed-intro/index.html](https://dlaliberte.github.io/bikeshed-intro/index.html),

0 commit comments

Comments
 (0)