You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-12Lines changed: 43 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,10 @@ This plugin will generate meta content for your Content Security Policy tag and
12
12
13
13
All inline JS and CSS will be hashed, and inserted into the policy.
14
14
15
-
16
15
## Installation
17
16
18
17
Install the plugin with npm:
18
+
19
19
```
20
20
npm i --save-dev csp-html-webpack-plugin
21
21
```
@@ -32,20 +32,26 @@ new CspHtmlWebpackPlugin()
32
32
## Configuration
33
33
34
34
This `CspHtmlWebpackPlugin` accepts 2 params with the following structure:
35
-
*`{object}` Policy (optional) - a flat object which defines your CSP policy. Valid keys and values can be found on the [MDN CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) page. Values can either be a string or an array of strings.
36
-
*`{object}` Additional Options (optional) - a flat object with the optional configuration options:
37
-
*`{boolean}` devAllowUnsafe - if you as the developer want to allow `unsafe-inline`/`unsafe-eval` and _not_ include hashes for inline scripts. If any hashes are included in the policy, modern browsers ignore the `unsafe-inline` rule.
38
-
*`{boolean|Function}` enabled - if false, or the function returns false, the empty CSP tag will be stripped from the html output.
39
-
* The `htmlPluginData` is passed into the function as it's first param.
40
-
* If `enabled` is set the false, it will disable generating a CSP for all instances of `HtmlWebpackPlugin` in your webpack config.
41
-
*`{string}` hashingMethod - accepts 'sha256', 'sha384', 'sha512' - your node version must also accept this hashing method.
35
+
36
+
-`{object}` Policy (optional) - a flat object which defines your CSP policy. Valid keys and values can be found on the [MDN CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) page. Values can either be a string or an array of strings.
37
+
-`{object}` Additional Options (optional) - a flat object with the optional configuration options:
38
+
-`{boolean|Function}` enabled - if false, or the function returns false, the empty CSP tag will be stripped from the html output.
39
+
- The `htmlPluginData` is passed into the function as it's first param.
40
+
- If `enabled` is set the false, it will disable generating a CSP for all instances of `HtmlWebpackPlugin` in your webpack config.
41
+
-`{string}` hashingMethod - accepts 'sha256', 'sha384', 'sha512' - your node version must also accept this hashing method.
42
+
-`{object}` hashEnabled - a `<string, boolean>` entry for which policy rules are allowed to include hashes
43
+
-`{object}` nonceEnabled - a `<string, boolean>` entry for which policy rules are allowed to include nonces
42
44
43
45
The plugin also adds a new config option onto each `HtmlWebpackPlugin` instance:
44
-
*`{object}` cspPlugin - an object containing the following properties:
45
-
*`{boolean}` enabled - if false, the CSP tag will be removed from the HTML which this HtmlWebpackPlugin instance is generating.
46
-
*`{object}` policy - A custom policy which should be applied only to this instance of the HtmlWebpackPlugin
47
46
48
-
Note that policies are merged in the following order:
47
+
-`{object}` cspPlugin - an object containing the following properties:
48
+
-`{boolean}` enabled - if false, the CSP tag will be removed from the HTML which this HtmlWebpackPlugin instance is generating.
49
+
-`{object}` policy - A custom policy which should be applied only to this instance of the HtmlWebpackPlugin
50
+
-`{object}` hashEnabled - a `<string, boolean>` entry for which policy rules are allowed to include hashes
51
+
-`{object}` nonceEnabled - a `<string, boolean>` entry for which policy rules are allowed to include nonces
52
+
53
+
Note that policies and `hashEnabled` / `nonceEnabled` are merged in the following order:
54
+
49
55
```
50
56
> HtmlWebpackPlugin cspPlugin.policy
51
57
> CspHtmlWebpackPlugin policy
@@ -72,10 +78,19 @@ If 2 policies have the same key/policy rule, the former policy will override the
0 commit comments