Page MenuHomePhabricator

Support CORS in gitlab-content tool
Closed, ResolvedPublicFeature

Description

Currently, the "gitlab-content" tool can be used to load eg. JavaScript and CSS from GitLab on Wikimedia wikis. However, scripts cannot load data files from there (or at least, without workarounds).

In my use case, I would like to load JavaScript and then lazily load a JSON file on demand from https://gitlab.wikimedia.org/msz2001/abusefilter-analyzer/-/tree/deploy The latter I wanted to do with fetch(), so that I can retrieve and process the response.

However, the request is blocked due to it being cross-origin. Here, I'd like to ask for CORS support in the tool.

I imagine it to be implemented in one of two ways. Since the requests contain no credentials, Access-Control-Allow-Origin: * could be hardcoded into responses, so that no additional measures will need to be taked by the clients to be able to fetch from gitlab-content. This is the simpler one.

Alternatively, a similar way to MediaWiki API's is possible, ie. one needs to pass an additional param in the URL with the origin host, which is then included in the response as Access-Control-Allow-Origin header.

For example:

https://gitlab-content.toolforge.org/{REPO}/-/raw/{PATH}?mime={MIME}&maxage={MAXAGE}&origin=en.wikipedia.org

would allow the browser to share the response with a script running on en.wikipedia.org, by including Access-Control-Allow-Origin: en.wikipedia.org.

Event Timeline

Iniquity subscribed.

@bd808 As it turns out, the task already exists :) I also encountered this today.

image.png (261×651 px, 43 KB)

Iniquity changed the subtype of this task from "Task" to "Feature Request".Jul 17 2025, 8:29 PM
bd808 triaged this task as Medium priority.Jul 17 2025, 9:24 PM

I really thought that the Toolforge front proxy already did this for all tools, but I was apparently confusing the Toolforge proxy with the tools-static proxy.

bd808 changed the task status from Open to In Progress.Jul 20 2025, 4:38 PM
bd808 claimed this task.
bd808 moved this task from Ready to Doing on the Tool-gitlab-content board.

Mentioned in SAL (#wikimedia-cloud) [2025-07-20T17:58:27Z] <wmbot~bd808@tools-bastion-12> Built new image from 449e522e (T397571, T393928)