@netlify/plugin-csp-nonce 1.2.4 → 1.2.6
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 +6 -4
package/package.json
CHANGED
package/src/__csp-nonce.ts
CHANGED
|
@@ -90,15 +90,16 @@ const handler = async (request: Request, context: Context) => {
|
|
|
90
90
|
.map((directive) => {
|
|
91
91
|
// prepend our rules for any existing directives
|
|
92
92
|
const d = directive.trim();
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
// intentionally add trailing space to avoid mangling `script-src-elem`
|
|
94
|
+
if (d.startsWith("script-src ")) {
|
|
95
|
+
return d.replace("script-src ", scriptSrc);
|
|
95
96
|
}
|
|
96
97
|
// intentionally omit report-uri: theirs should take precedence
|
|
97
98
|
return d;
|
|
98
99
|
})
|
|
99
100
|
.filter(Boolean);
|
|
100
101
|
// push our rules if the directives don't exist yet
|
|
101
|
-
if (!directives.find((d) => d.startsWith("script-src"))) {
|
|
102
|
+
if (!directives.find((d) => d.startsWith("script-src "))) {
|
|
102
103
|
directives.push(scriptSrc);
|
|
103
104
|
}
|
|
104
105
|
if (!directives.find((d) => d.startsWith("report-uri"))) {
|
|
@@ -112,8 +113,9 @@ const handler = async (request: Request, context: Context) => {
|
|
|
112
113
|
response.headers.set(header, value);
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
const querySelectors = ["script", 'link[rel="preload"][as="script"]'];
|
|
115
117
|
return new HTMLRewriter()
|
|
116
|
-
.on("
|
|
118
|
+
.on(querySelectors.join(","), {
|
|
117
119
|
element(element: HTMLElement) {
|
|
118
120
|
element.setAttribute("nonce", nonce);
|
|
119
121
|
},
|