@netlify/plugin-csp-nonce 1.2.10 → 1.2.11
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 +18 -5
package/package.json
CHANGED
package/src/__csp-nonce.ts
CHANGED
|
@@ -19,6 +19,21 @@ type Params = {
|
|
|
19
19
|
const params = inputs as Params;
|
|
20
20
|
|
|
21
21
|
const handler = async (request: Request, context: Context) => {
|
|
22
|
+
const isGET = request.method === "GET";
|
|
23
|
+
// We only need to run this for HTTP GET requests.
|
|
24
|
+
// If it is not a GET, then return early.
|
|
25
|
+
//
|
|
26
|
+
// If we instead used `context.next(request)`
|
|
27
|
+
// we would be passing the request through this
|
|
28
|
+
// edge function for no useful reason.
|
|
29
|
+
if (!isGET) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// At this point, we know it's a GET request,
|
|
35
|
+
// we have to now make the request, in order to
|
|
36
|
+
// see what the HTTP response's content-type is.
|
|
22
37
|
const response = await context.next(request);
|
|
23
38
|
|
|
24
39
|
let header = params.reportOnly
|
|
@@ -28,12 +43,10 @@ const handler = async (request: Request, context: Context) => {
|
|
|
28
43
|
// for debugging which routes use this edge function
|
|
29
44
|
response.headers.set("x-debug-csp-nonce", "invoked");
|
|
30
45
|
|
|
31
|
-
// html GETs only
|
|
32
|
-
const isGET = request.method?.toUpperCase() === "GET";
|
|
33
46
|
const isHTMLResponse = response.headers
|
|
34
47
|
.get("content-type")
|
|
35
48
|
?.startsWith("text/html");
|
|
36
|
-
const shouldTransformResponse =
|
|
49
|
+
const shouldTransformResponse = isHTMLResponse;
|
|
37
50
|
if (!shouldTransformResponse) {
|
|
38
51
|
console.log(`Unnecessary invocation for ${request.url}`, {
|
|
39
52
|
method: request.method,
|
|
@@ -180,8 +193,8 @@ const excludedExtensions = [
|
|
|
180
193
|
export const config: Config = {
|
|
181
194
|
path: params.path,
|
|
182
195
|
excludedPath: ["/.netlify*", `**/*.(${excludedExtensions.join("|")})`]
|
|
183
|
-
|
|
184
|
-
|
|
196
|
+
.concat(params.excludedPath)
|
|
197
|
+
.filter(Boolean),
|
|
185
198
|
handler,
|
|
186
199
|
onError: "bypass",
|
|
187
200
|
};
|