Skip to content
This repository was archived by the owner on May 23, 2026. It is now read-only.

Commit fe71b94

Browse files
committed
check Content-Type
1 parent c2cb1e5 commit fe71b94

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎src/CCWData-Code-Injection-Fix.user.js‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,30 @@ Element.prototype.appendChild = function (c) {
2424
console.log('CCWData-Code-Injection-Fix fetch ' + src)
2525
c.removeAttribute("src")
2626
fetch(src, { cache: 'default' })
27-
.then(r => r.text())
28-
.then(text => {
27+
.then(r => {
28+
const type = r.headers.get('Content-Type')?.split(';')[0].trim()
29+
switch (type) {
30+
// https://htmlspecs.com/mimesniff/#javascript-mime-type
31+
case "application/ecmascript":
32+
case "application/javascript":
33+
case "application/x-ecmascript":
34+
case "application/x-javascript":
35+
case "text/ecmascript":
36+
case "text/javascript":
37+
case "text/javascript1.0":
38+
case "text/javascript1.1":
39+
case "text/javascript1.2":
40+
case "text/javascript1.3":
41+
case "text/javascript1.4":
42+
case "text/javascript1.5":
43+
case "text/jscript":
44+
case "text/livescript":
45+
case "text/x-ecmascript":
46+
case "text/x-javascript":
47+
return r.text()
48+
}
49+
throw `Refused to execute script from '${src}' because its MIME type ('${type}') is not executable.`
50+
}).then(text => {
2951
c.innerHTML = text.replace(/(?=\([^()]+\)\.push\()/, injectPrefix)
3052
console.log('CCWData-Code-Injection-Fix', appendChild.call(this, c))
3153
})

0 commit comments

Comments
 (0)