Page MenuHomePhabricator

Gadgets hosted on github.com was blocked due to CSP
Closed, DeclinedPublicBUG REPORT

Description

The issue arose because some users reported that one of my tools was not working; this is the relevant issue.

Steps to replicate the issue:

Open the User Preferences, Appearance, and add a new line of code for Custom JavaScript:

mw.loader.load("https://github.com/Frederisk/Wikitext-Extension-Gadget/releases/latest/download/index-vscode.js");

What happens?:

This tool is not working properly and is displaying an error in the console:

plain
Wikitext-Extension-Gadget:1  GET https://meta.wikimedia.org/wiki/User:Rowe_Wilson_Frederisk_Holme/Wikitext-Extension-Gadget 404 (Not Found)
load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:9 Loading the script 'https://github.com/Frederisk/Wikitext-Extension-Gadget/releases/latest/download/index-vscode-insiders.js' violates the following Content Security Policy directive: "script-src 'unsafe-eval' blob: 'self' *.wikimedia.org *.wikipedia.org *.wikinews.org *.wiktionary.org *.wikibooks.org *.wikiversity.org *.wikisource.org wikisource.org *.wikiquote.org *.wikidata.org *.wikifunctions.org *.wikivoyage.org *.mediawiki.org mediawiki.org wikimedia.org *.wmflabs.org *.wmcloud.org *.toolforge.org wss://*.toolforge.org *.jsdelivr.net unpkg.com cdnjs.cloudflare.com raw.githubusercontent.com *.github.com code.jquery.com cdn.mathjax.org use.typekit.net fonts.cdnfonts.com use.fontawesome.com i.ytimg.com rsms.me doi.org localhost https://localhost:* http://localhost:* wss://localhost:* ws://localhost:* *.google.com *.gstatic.com *.googleapis.com *.translate.yandex.net yastatic.net ya.ru radically.github.io cdn.sammdot.ca cdn.fontshare.com viaf.org publicai-proxy.alaexis.workers.dev iiif.archive.org api.flickr.com live.staticflickr.com api.anthropic.com api.openai.com api.publicai.co catalogo.pusc.it parsifal.urbe.it opac.sbn.it overpass-api.de api.openrouteservice.org archive.org *.openstreetmap.org *.waymarkedtrails.org *.thunderforest.com registry.ipe.wiki analytics.ipe.wiki qlever.dev app.goacoustic.com wikipedia-archive.ourworldindata.org api.inaturalist.org inaturalist-open-data.s3.amazonaws.com validator.w3.org db.onlinewebfonts.com fontlibrary.org 'unsafe-inline'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback. The action has been blocked.
addScript @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:9
load @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:19
(anonymous) @ ext.globalCssJs.user-script-0.js:7
runScript @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:11
execute @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:13
doPropagation @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:5
requestIdleCallback
setAndPropagate @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:6
impl @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:18
eval @ load.php?lang=zh-tw&modules=mediawiki.visibleTimeout&skin=timeless&version=1goy8:1
indirectEval @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:10
asyncEvalTask @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
(anonymous) @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
requestIdleCallback
asyncEval @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
asyncEvalTask @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
(anonymous) @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
requestIdleCallback
asyncEval @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
asyncEvalTask @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
(anonymous) @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
requestIdleCallback
asyncEval @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:15
work @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:16
enqueue @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:10
load @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:19
(anonymous) @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:23
(anonymous) @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:23
load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:3 Exception in module-execute in module ext.gadget.Navigation_popups:
load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:3 Error: Module "ext.gadget.HanAssist" is not loaded
    at require (load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:19:911)
    at ext.gadget.Navigation_popups-script-0.js:17:19
    at css (ext.gadget.Navigation_popups-script-0.js:285:3)
    at runScript (load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:11:465)
    at Array.<anonymous> (load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:12:504)
    at flushCssBuffer (load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:4:385)
trackError @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:3
runScript @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:12
(anonymous) @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:12
flushCssBuffer @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:4
requestAnimationFrame
addEmbeddedCSS @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:4
execute @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:12
doPropagation @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:5
requestIdleCallback
setAndPropagate @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:6
impl @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:18
(anonymous) @ load.php?modules=ext.gadget.Navigation_popups:1
index.php?title=MediaWiki:Gadget-ToolsRedirect.js&action=raw&ctype=text/javascript:5 Uncaught ReferenceError: require is not defined
(anonymous) @ index.php?title=MediaWiki:Gadget-ToolsRedirect.js&action=raw&ctype=text/javascript:5
(anonymous) @ index.php?title=MediaWiki:Gadget-ToolsRedirect.js&action=raw&ctype=text/javascript:734
index.php?title=MediaWiki:Gadget-contribsrange.js&action=raw&ctype=text/javascript:35 Uncaught ReferenceError: require is not defined
(anonymous) @ index.php?title=MediaWiki:Gadget-contribsrange.js&action=raw&ctype=text/javascript:35
(anonymous) @ index.php?title=MediaWiki:Gadget-contribsrange.js&action=raw&ctype=text/javascript:259
load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:12 This page is using the deprecated ResourceLoader module "jquery.ui".
Please use Codex instead.
execute @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:12
doPropagation @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:5
requestIdleCallback
setAndPropagate @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:6
impl @ load.php?lang=zh-tw&modules=startup&only=scripts&raw=1&skin=timeless:18
(anonymous) @ load.php?lang=zh-tw&modules=jquery.ui&skin=timeless&version=1n57r:1

What should have happened instead?:

Clearly, this was an unintended consequence of trying to fix this bug; removing github.com caused the apex domain to be rejected. I believe both github.com and *.github.com should be included.

Software version: Wikimedia sites

Other information (browser name/version, screenshots, etc.):

Event Timeline

Allowing to load any and every potentially malicious code hosted on github.com where anyone could upload anything, with no limiting criteria, sounds to me like defeating the purpose of CSP.

In fact, since *.github.com (specifically api.github.com) and raw.githubusercontent.com are already on the whitelist, it is practically possible to fetch source code from any repository. Thus, if the current policy remains, one alternative is modifying the GitHub Actions to push the build outputs to a regular repository branch instead of using the GitHub Releases feature.

Another option would be instructing users to load the script directly from the main branch. (If my request cannot be accommodated, I will likely go with this option. While it might expose users to a less stable version, the gadget is mature enough that I foresee very few updates).

From a technical standpoint, I don't feel this restriction improves security. It only creates futile maintenance burdens for me and makes the setup confusing for the end users.

Naturally, if the underlying objective is to restrict all third-party code from GitHub entirely, I would understand that as a separate matter.

Allowing to load any and every potentially malicious code hosted on github.com where anyone could upload anything, with no limiting criteria, sounds to me like defeating the purpose of CSP.

(edit conflict) *.jsdelivr.net and raw.githubusercontent.com are on the list.

Why not use git hosting operated by Wikimedia itself instead?

Thus, if the current policy remains

The current Wikimedia CSP allow-list will not remain in place indefinitely. Many of the external domains currently allowed there are going to be winnowed down over the next several months. More details can be found in https://www.mediawiki.org/wiki/Product_Safety_and_Integrity/Account_Security/Securing_User-Managed_Code, T117618 and T427557.

sbassett claimed this task.
sbassett triaged this task as Low priority.
sbassett moved this task from Backlog to Done on the ContentSecurityPolicy board.

I'm going to decline this, as we are no longer adding post-#2026-user-javascript-incident exceptions to the primary CSP governing Wikimedia wikis. As a workaround, you can likely use www.github.com as the domain, but I would encourage migrating the affected code to either a JavaScript page on a Wikimedia wiki or a hosted script under a toolforge or wmcs project.