Skip to content

Commit 02a95ed

Browse files
Disable script overloads for non scripts
1 parent c18ffdc commit 02a95ed

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/features/runtime-checks.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ const defaultElementMethods = {
4444
}
4545
const supportedTrustedTypes = 'TrustedScriptURL' in window
4646

47+
const jsMimeTypes = [
48+
'text/javascript',
49+
'text/ecmascript',
50+
'application/javascript',
51+
'application/ecmascript',
52+
'application/x-javascript',
53+
'application/x-ecmascript',
54+
'text/javascript1.0',
55+
'text/javascript1.1',
56+
'text/javascript1.2',
57+
'text/javascript1.3',
58+
'text/javascript1.4',
59+
'text/javascript1.5',
60+
'text/jscript',
61+
'text/livescript',
62+
'text/x-ecmascript',
63+
'text/x-javascript'
64+
]
65+
4766
class DDGRuntimeChecks extends HTMLElement {
4867
#tagName
4968
#el
@@ -128,6 +147,11 @@ class DDGRuntimeChecks extends HTMLElement {
128147
// @ts-expect-error TrustedScript is not defined in the TS lib
129148
if (supportedTrustedTypes && el.textContent instanceof TrustedScript) return
130149

150+
// Short circuit if not a script type
151+
if (!jsMimeTypes.includes(el.type) &&
152+
el.type !== 'module' &&
153+
el.type !== '') return
154+
131155
el.textContent = wrapScriptCodeOverload(el.textContent, scriptOverload)
132156
}
133157

0 commit comments

Comments
 (0)