Skip to content

Commit a12ab1a

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

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/features/runtime-checks.js

Lines changed: 25 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,12 @@ 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+
const scriptType = el.type.toLowerCase()
152+
if (!jsMimeTypes.includes(scriptType) &&
153+
scriptType !== 'module' &&
154+
scriptType !== '') return
155+
131156
el.textContent = wrapScriptCodeOverload(el.textContent, scriptOverload)
132157
}
133158

0 commit comments

Comments
 (0)