@netlify/plugin-csp-nonce 1.2.6 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +22 -10
- package/package.json +1 -1
- package/src/__csp-nonce.ts +3 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ When true, adds `'unsafe-eval'` to the CSP for easier adoption. Set to `false` t
|
|
|
60
60
|
|
|
61
61
|
#### `path`
|
|
62
62
|
|
|
63
|
-
_Default: `"
|
|
63
|
+
_Default: `"/*"`._
|
|
64
64
|
|
|
65
65
|
The glob expressions of path(s) that should invoke the CSP nonce edge function. Can be a string or array of strings.
|
|
66
66
|
|
package/index.js
CHANGED
|
@@ -3,10 +3,17 @@ import fs, { copyFileSync } from "fs";
|
|
|
3
3
|
|
|
4
4
|
const SITE_ID = "321a7119-6008-49a8-9d2f-e20602b1b349";
|
|
5
5
|
|
|
6
|
-
export const onPreBuild = async ({
|
|
6
|
+
export const onPreBuild = async ({
|
|
7
|
+
inputs,
|
|
8
|
+
netlifyConfig,
|
|
9
|
+
utils,
|
|
10
|
+
constants,
|
|
11
|
+
}) => {
|
|
7
12
|
const config = JSON.stringify(inputs, null, 2);
|
|
8
13
|
const { build } = netlifyConfig;
|
|
9
14
|
|
|
15
|
+
const { INTERNAL_EDGE_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC } = constants;
|
|
16
|
+
|
|
10
17
|
// DISABLE_CSP_NONCE is undocumented (deprecated), but still supported
|
|
11
18
|
// -> superseded by CSP_NONCE_DISTRIBUTION
|
|
12
19
|
if (build.environment.DISABLE_CSP_NONCE === "true") {
|
|
@@ -35,25 +42,30 @@ export const onPreBuild = async ({ inputs, netlifyConfig, utils }) => {
|
|
|
35
42
|
? "./src"
|
|
36
43
|
: "./node_modules/@netlify/plugin-csp-nonce/src";
|
|
37
44
|
|
|
38
|
-
const edgeFunctionsDir = build.edge_functions || "./netlify/edge-functions";
|
|
39
45
|
// make the directory in case it actually doesn't exist yet
|
|
40
|
-
await utils.run.command(`mkdir -p ${
|
|
41
|
-
console.log(
|
|
46
|
+
await utils.run.command(`mkdir -p ${INTERNAL_EDGE_FUNCTIONS_SRC}`);
|
|
47
|
+
console.log(
|
|
48
|
+
` Writing nonce edge function to ${INTERNAL_EDGE_FUNCTIONS_SRC}...`,
|
|
49
|
+
);
|
|
42
50
|
copyFileSync(
|
|
43
51
|
`${basePath}/__csp-nonce.ts`,
|
|
44
|
-
`${
|
|
52
|
+
`${INTERNAL_EDGE_FUNCTIONS_SRC}/__csp-nonce.ts`,
|
|
53
|
+
);
|
|
54
|
+
fs.writeFileSync(
|
|
55
|
+
`${INTERNAL_EDGE_FUNCTIONS_SRC}/__csp-nonce-inputs.json`,
|
|
56
|
+
config,
|
|
45
57
|
);
|
|
46
|
-
fs.writeFileSync(`${edgeFunctionsDir}/__csp-nonce-inputs.json`, config);
|
|
47
58
|
|
|
48
59
|
// if no reportUri in config input, deploy function on site's behalf
|
|
49
60
|
if (!inputs.reportUri) {
|
|
50
|
-
const functionsDir = build.functions || "./netlify/functions";
|
|
51
61
|
// make the directory in case it actually doesn't exist yet
|
|
52
|
-
await utils.run.command(`mkdir -p ${
|
|
53
|
-
console.log(
|
|
62
|
+
await utils.run.command(`mkdir -p ${INTERNAL_FUNCTIONS_SRC}`);
|
|
63
|
+
console.log(
|
|
64
|
+
` Writing violations logging function to ${INTERNAL_FUNCTIONS_SRC}...`,
|
|
65
|
+
);
|
|
54
66
|
copyFileSync(
|
|
55
67
|
`${basePath}/__csp-violations.ts`,
|
|
56
|
-
`${
|
|
68
|
+
`${INTERNAL_FUNCTIONS_SRC}/__csp-violations.ts`,
|
|
57
69
|
);
|
|
58
70
|
} else {
|
|
59
71
|
console.log(` Using ${inputs.reportUri} as report-uri directive...`);
|
package/package.json
CHANGED
package/src/__csp-nonce.ts
CHANGED
|
@@ -92,7 +92,9 @@ const handler = async (request: Request, context: Context) => {
|
|
|
92
92
|
const d = directive.trim();
|
|
93
93
|
// intentionally add trailing space to avoid mangling `script-src-elem`
|
|
94
94
|
if (d.startsWith("script-src ")) {
|
|
95
|
-
|
|
95
|
+
// append with trailing space to include any user-supplied values
|
|
96
|
+
// https://github.com/netlify/plugin-csp-nonce/issues/72
|
|
97
|
+
return d.replace("script-src ", `${scriptSrc} `).trim();
|
|
96
98
|
}
|
|
97
99
|
// intentionally omit report-uri: theirs should take precedence
|
|
98
100
|
return d;
|