@netlify/plugin-csp-nonce 1.2.10 → 1.2.12
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/package.json +1 -1
- package/src/__csp-nonce.ts +8 -9
package/package.json
CHANGED
package/src/__csp-nonce.ts
CHANGED
|
@@ -21,19 +21,13 @@ const params = inputs as Params;
|
|
|
21
21
|
const handler = async (request: Request, context: Context) => {
|
|
22
22
|
const response = await context.next(request);
|
|
23
23
|
|
|
24
|
-
let header = params.reportOnly
|
|
25
|
-
? "content-security-policy-report-only"
|
|
26
|
-
: "content-security-policy";
|
|
27
|
-
|
|
28
24
|
// for debugging which routes use this edge function
|
|
29
25
|
response.headers.set("x-debug-csp-nonce", "invoked");
|
|
30
26
|
|
|
31
|
-
// html GETs only
|
|
32
|
-
const isGET = request.method?.toUpperCase() === "GET";
|
|
33
27
|
const isHTMLResponse = response.headers
|
|
34
28
|
.get("content-type")
|
|
35
29
|
?.startsWith("text/html");
|
|
36
|
-
const shouldTransformResponse =
|
|
30
|
+
const shouldTransformResponse = isHTMLResponse;
|
|
37
31
|
if (!shouldTransformResponse) {
|
|
38
32
|
console.log(`Unnecessary invocation for ${request.url}`, {
|
|
39
33
|
method: request.method,
|
|
@@ -42,6 +36,10 @@ const handler = async (request: Request, context: Context) => {
|
|
|
42
36
|
return response;
|
|
43
37
|
}
|
|
44
38
|
|
|
39
|
+
let header = params.reportOnly
|
|
40
|
+
? "content-security-policy-report-only"
|
|
41
|
+
: "content-security-policy";
|
|
42
|
+
|
|
45
43
|
// CSP_NONCE_DISTRIBUTION is a number from 0 to 1,
|
|
46
44
|
// but 0 to 100 is also supported, along with a trailing %
|
|
47
45
|
// @ts-ignore
|
|
@@ -180,10 +178,11 @@ const excludedExtensions = [
|
|
|
180
178
|
export const config: Config = {
|
|
181
179
|
path: params.path,
|
|
182
180
|
excludedPath: ["/.netlify*", `**/*.(${excludedExtensions.join("|")})`]
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
.concat(params.excludedPath)
|
|
182
|
+
.filter(Boolean),
|
|
185
183
|
handler,
|
|
186
184
|
onError: "bypass",
|
|
185
|
+
method: "GET",
|
|
187
186
|
};
|
|
188
187
|
|
|
189
188
|
export default handler;
|