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
+17-16Lines changed: 17 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,17 @@ First, add the dependency:
16
16
npm i @netlify/plugin-csp-nonce
17
17
```
18
18
19
-
Then, include the plugin inside your `netlify.toml`:
19
+
Then, include the plugin inside your `netlify.toml`:
20
20
21
21
```
22
22
# netlify.toml
23
23
[[plugins]]
24
24
package = "@netlify/plugin-csp-nonce"
25
25
```
26
26
27
-
28
27
## Configuration options
29
28
30
-
Sample configuration:
29
+
Sample configuration:
31
30
32
31
```
33
32
# netlify.toml
@@ -41,31 +40,35 @@ Sample configuration:
41
40
]
42
41
```
43
42
44
-
#### `reportOnly`
45
-
*Default: `true`*.
43
+
#### `reportOnly`
44
+
45
+
_Default: `true`_.
46
46
47
47
When true, uses the `Content-Security-Policy-Report-Only` header instead of the `Content-Security-Policy` header. Setting `reportOnly` to `true` is useful for testing the CSP with real production traffic without actually blocking resources. Be sure to monitor your logging function to observe potential violations.
48
48
49
49
#### `reportUri`
50
-
*Default: `undefined`*.
51
50
52
-
The relative or absolute URL to report any violations. If left undefined, violations are reported to the `__csp-violations` function, which this plugin deploys. If your site already has a `report-uri` directive defined in its CSP header, then that value will take precedence.
51
+
_Default: `undefined`_.
52
+
53
+
The relative or absolute URL to report any violations. If left undefined, violations are reported to the `__csp-violations` function, which this plugin deploys. If your site already has a `report-uri` directive defined in its CSP header, then that value will take precedence.
53
54
54
55
#### `unsafeEval`
55
-
*Default: `true`.*
56
+
57
+
_Default: `true`._
56
58
57
59
When true, adds `'unsafe-eval'` to the CSP for easier adoption. Set to `false` to have a safer policy if your code and code dependencies does not use `eval()`.
58
60
59
61
#### `path`
60
-
*Default: `"/*"`.*
62
+
63
+
_Default: `"/_"`.\*
61
64
62
65
The glob expressions of path(s) that should invoke the CSP nonce edge function. Can be a string or array of strings.
63
66
64
67
#### `excludedPath`
65
-
*Default: `[]`*
66
68
67
-
The glob expressions of path(s) that _should not_ invoke the CSP nonce edge function. Must be an array of strings. This value gets spread with common non-html filetype extensions (`*.css`, `*.js`, `*.svg`, etc).
69
+
_Default: `[]`_
68
70
71
+
The glob expressions of path(s) that _should not_ invoke the CSP nonce edge function. Must be an array of strings. This value gets spread with common non-html filetype extensions (`*.css`, `*.js`, `*.svg`, etc).
69
72
70
73
## Debugging
71
74
@@ -80,6 +83,8 @@ To further limit invocations, add globs to the `excludedPath` configuration opti
80
83
81
84
Requests that invoke the nonce edge function will contain a `x-debug-csp-nonce: invoked` response header. Use this to determine if unwanted paths are invoking the edge function, and add those paths to the `excludedPath` array.
82
85
86
+
Also, monitor the edge function logs in the Netlify UI. If the edge function is invoked but the response is not transformed, the request's path will be logged.
87
+
83
88
### Not transforming as expected
84
89
85
90
If your HTML does not contain the `nonce` attribute on the `<script>` tags that you expect, ensure that all of these criteria are met:
@@ -91,10 +96,6 @@ If your HTML does not contain the `nonce` attribute on the `<script>` tags that
91
96
92
97
### Quickly enabling and disabling
93
98
94
-
You may want to quickly enable/disable the plugin while monitoring violation reports. You can do so without modifying code.
99
+
You may want to quickly enable/disable the plugin while monitoring violation reports. You can do so without modifying code.
95
100
96
101
Simply set the `DISABLE_CSP_NONCE` environment variable to `true`, and your next deploy will skip running the plugin. Setting to `false` will re-enable the plugin. The environment variable needs to be scoped to `Builds`.
0 commit comments