Skip to content

Commit adfe2d6

Browse files
Disable script overloads for non scripts (#521)
Co-authored-by: David Harbage <[email protected]>
1 parent 98bc87b commit adfe2d6

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
@@ -46,6 +46,25 @@ const defaultElementMethods = {
4646
}
4747
const supportedTrustedTypes = 'TrustedScriptURL' in window
4848

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

152+
// Short circuit if not a script type
153+
const scriptType = el.type.toLowerCase()
154+
if (!jsMimeTypes.includes(scriptType) &&
155+
scriptType !== 'module' &&
156+
scriptType !== '') return
157+
133158
el.textContent = wrapScriptCodeOverload(el.textContent, scriptOverload)
134159
}
135160

0 commit comments

Comments
 (0)