@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@netlify/plugin-csp-nonce",
4
- "version": "1.2.10",
4
+ "version": "1.2.12",
5
5
  "description": "Use a nonce for the script-src and style-src directives of your Content Security Policy.",
6
6
  "main": "index.js",
7
7
  "repository": {
@@ -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 = isGET && isHTMLResponse;
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
- .concat(params.excludedPath)
184
- .filter(Boolean),
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;