@@ -8,9 +8,12 @@ const sleep = async (ms = 50) =>
8
8
9
9
let scriptBundlePath ;
10
10
try {
11
- scriptBundlePath = new URL ( document . currentScript . src ) . pathname . match (
12
- / ^ ( .* \/ ) (?: p a g e f i n d - ) ? m o d u l a r - u i .j s .* $ /
13
- ) [ 1 ] ;
11
+ // Important: Check that the element is indeed a <script> node, to avoid a DOM clobbering vulnerability
12
+ if ( document ?. currentScript && document . currentScript . tagName . toUpperCase ( ) === 'SCRIPT' ) {
13
+ scriptBundlePath = new URL ( document . currentScript . src ) . pathname . match (
14
+ / ^ ( .* \/ ) (?: p a g e f i n d - ) ? m o d u l a r - u i .j s .* $ /
15
+ ) [ 1 ] ;
16
+ }
14
17
} catch ( e ) {
15
18
scriptBundlePath = "/pagefind/" ;
16
19
}
@@ -166,12 +169,22 @@ export class Instance {
166
169
console . error (
167
170
[
168
171
`Pagefind couldn't be loaded from ${ this . options . bundlePath } pagefind.js` ,
169
- `You can configure this by passing a bundlePath option to PagefindComposable Instance` ,
170
- `[DEBUG: Loaded from ${
171
- document ?. currentScript ?. src ?? "no known script location"
172
- } ]`,
172
+ `You can configure this by passing a bundlePath option to PagefindComposable Instance`
173
173
] . join ( "\n" )
174
174
) ;
175
+ // Important: Check that the element is indeed a <script> node, to avoid a DOM clobbering vulnerability
176
+ if (
177
+ document ?. currentScript &&
178
+ document . currentScript . tagName . toUpperCase ( ) === "SCRIPT"
179
+ ) {
180
+ console . error (
181
+ `[DEBUG: Loaded from ${
182
+ document . currentScript ?. src ?? "bad script location"
183
+ } ]`
184
+ ) ;
185
+ } else {
186
+ console . error ( "no known script location" ) ;
187
+ }
175
188
}
176
189
177
190
await imported_pagefind . options ( this . pagefindOptions || { } ) ;
0 commit comments