Stored Cross-Site Scripting in MediaWiki
The MediaWiki parser for internal links was vulnerable to stored cross-site scripting, allowing an attacker to inject script code into pages, forms, and media descriptions. An attacker with page creation rights could store malicious script that executes when other users view the affected content.
Published on machevalia.blog
Bug BountyWrite Ups
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
MediaWiki is the wiki software behind Wikipedia and many other crowd-sourced content sites. It provides page creation and editing, a form builder, and media upload with description fields. The target in this write-up was an older MediaWiki installation, and the researcher had already established, in a separate write-up on access control, that they could create their own pages, forms, and edit content in various places, including media that had been uploaded to the server. That earlier finding is the precondition for everything below: without the ability to write content into the wiki, there is no stored XSS to trigger.
The goal here was stored cross-site scripting: getting a payload persisted server-side so that it executes in the browser of anyone who views the affected page or field.
Setup
The researcher used the access they had already obtained to create pages, forms, and to edit media descriptions. The tooling mentioned is xsshunter.com, used to craft a payload to steal the researcher's own cookie. plus public payload lists for initial probing: PortSwigger's XSS payload list and Payloadbox's XSS-Payload-List. No specific MediaWiki version number is given in the report; it is described only as an older version.
Finding it
With write access in hand, the researcher tried a handful of standard XSS payloads from the usual lists. The reasoning was that an older MediaWiki install would likely have known parser issues, given the volume of MediaWiki CVEs catalogued on MITRE. Rather than fuzzing every payload on every list, the researcher picked a few favourites for initial tests, on the view that a fancy payload is only needed when going for a bypass.
Digging through CVE reports led to obscure links to old Red Hat Linux vulnerability verification threads. One of those threads linked to https://phabricator.wikimedia.org/T1137264, where the author explained that the MediaWiki parser for internal links was vulnerable to XSS using this payload:
[[#%3Cscript%3Ealert(1)%3C/script%3E|
The payload is a MediaWiki internal-link construct whose fragment is percent-encoded. The report does not explain how the parser handles it.
Exploitation
Step 1: Confirm the payload is stored and rendered
The researcher found the payload successful in several areas: form creation, wiki pages, and media description fields, all under the wpTextbox1 form field. wpTextbox1 is the name MediaWiki gives to the main edit textarea, so anything that accepts wiki markup through that field is a candidate.
Step 2: Attempt cookie theft
Using xsshunter.com, the researcher crafted a payload intended to steal their own cookie, purely to demonstrate impact. The report does not reproduce that payload. The attempt failed to yield a useful cookie because the page was served over HTTP while the cookies were secure-only, so the browser would not send them over the plain HTTP connection. The stored XSS itself was still demonstrated, which was enough for the report to be accepted.
Step 3: Report
The vulnerability was reported in three separate places in a single combined report. The report was accepted. At the time of writing, all patching attempts had failed.
Root cause
The report says the MediaWiki parser for internal links was vulnerable to XSS with this payload, without describing the mechanism. The report frames the wider problem as architectural: MediaWiki appears to manage filtering by creating exclusions and individual replacements for specific payloads, strings, and characters within each separate piece of the codebase, based on the various Phabricator threads the researcher read. That approach leaves gaps wherever a new encoding or syntax path reaches the same sink. A holistic change to how user-provided content is filtered would be needed across the entire codebase, which the researcher acknowledges is easier said than done for a crowd-sourced CMS. The report does not identify the specific function or file where the escaping is missing.
Impact
An attacker who can write content into the wiki, through page creation, forms, or media description fields, can store script that executes in the browser of anyone who views the affected content. In this case the practical impact was limited by the site being served over HTTP with secure-only cookies, so session cookies were not exposed over that channel. The report does not assess impact against other cookie configurations or other users' sessions beyond this.
Fix
No fix is described. The report states that patching attempts had failed and that the researcher would update the write-up if a patch were implemented successfully. The report says a holistic change in how user-provided content is filtered would be required across the codebase.
Variants to test
- Try the same internal-link payload in every field that submits through
wpTextbox1: page edits, form creation, and media description fields. A positive result is the script executing when the saved content is viewed. - Vary the encoding of the fragment: double-encoding, mixed case in the tag name, and other percent-encoded forms of
<script>. A positive result is execution where the plain payload was filtered. - Try other MediaWiki markup constructs that accept a fragment or free text, such as links with different prefixes. A positive result is the same decode-then-render behaviour in a different parser path.
- Test whether the payload survives preview versus save, since preview and stored rendering can use different code paths. A positive result is execution on the saved page even if preview is clean.
- Where cookies are secure-only and the site is HTTP, look for other exfiltration channels or higher-privileged viewers. A positive result is script execution in a context where a meaningful secret is reachable.
What happened, in plain words
A security researcher found a way to make a wiki website store a small piece of malicious code and then run it in the browser of anyone who opened the affected page. The wiki software was MediaWiki, the same software that runs Wikipedia. The researcher could already create pages, build forms and edit media descriptions on the site, so they had somewhere to plant the code. They found a known trick in an old bug report: a specially written internal link that the wiki decodes and then prints into the page without cleaning it up. The trick worked in several places. The researcher tried to use it to steal their own login cookie as a demonstration, but the site was served over plain HTTP while the cookies were marked secure-only, so the browser refused to send them. The stored code execution itself was still proven, the report was accepted, and the researcher was paid 1090.00 USD so far, with fixes still pending.
The product and the feature
MediaWiki is wiki software. A wiki is a website where many people can create and edit pages through the browser, and every change is saved on the server so the next visitor sees it. Wikipedia is the best-known example, but the same software powers many other crowd-sourced content sites.
The features that matter here are:
- Page creation and editing: a text box where you type content in wiki markup, a lightweight formatting language. For example, double square brackets around a word make an internal link to another page.
- A form builder: a feature that lets users assemble forms on the wiki.
- Media upload with description fields: you can upload a file and write a description next to it.
All of these accept text that gets saved on the server and shown to other people later. That is exactly the kind of feature where stored cross-site scripting lives.
The target was an older MediaWiki installation. The report does not give a version number. The researcher had already published a separate write-up about an access control problem, which showed they could create their own pages, forms and edit content in various places, including media already uploaded to the server. Think of access control as the bouncer at a club: it decides who is allowed in and what they may do once inside. That earlier finding is the precondition for everything here. If you cannot write content into the wiki, you have nowhere to plant stored code.
The vulnerability class: stored cross-site scripting
A browser cannot tell the difference between a script the site meant to run and a script that slipped in through a text field. It runs both.
There are two broad flavours:
- Reflected XSS: the malicious text bounces straight back in the response to the same request, for example through a search term shown on the results page. It only affects the person who sends the crafted request.
- Stored XSS: the malicious text is saved on the server, in a page, a form or a description field, and is served to everyone who views it later. This is the more dangerous flavour because the attacker does not need to trick each victim individually.
The goal in this write-up was stored XSS: get a payload saved on the server so that it runs in the browser of anyone who views the affected page or field. A payload here simply means the piece of text that carries the malicious code.
Setup and tooling
The researcher used the access they had already obtained to create pages, forms and edit media descriptions. Two kinds of tool are mentioned:
- xsshunter.com, used to craft a payload to steal the researcher's own cookie. A callback is the signal the payload sends back to the researcher when it runs, for example a request to a server the researcher controls. It is how you prove the code actually executed in a browser rather than just sitting in the page source.
- Public payload lists for initial probing: PortSwigger's XSS payload list and Payloadbox's XSS-Payload-List. These are catalogues of ready-made test strings that people share so others do not have to reinvent them.
No specific MediaWiki version number is given in the report. It is described only as an older version.
Finding it
With write access in hand, the researcher tried a handful of standard XSS payloads from the usual lists. The reasoning was simple: an older MediaWiki install would likely have known parser issues, given the volume of MediaWiki CVEs catalogued on MITRE. A CVE is a publicly assigned identifier for a known security flaw, and MITRE is one of the organisations that maintains the catalogue. If a product has a long list of past flaws, an old installation is a reasonable place to look for one that was never fixed.
Rather than fuzzing every payload on every list, the researcher picked a few favourites for initial tests. Fuzzing means throwing large numbers of variations at a target and watching for anything unusual. The view was that a fancy payload is only needed when you are trying to get past a filter, a bypass. For a first look, a small set of well-known strings is usually enough.
Digging through CVE reports led to obscure links to old Red Hat Linux vulnerability verification threads. One of those threads linked to https://phabricator.wikimedia.org/T1137264, where the author explained that the MediaWiki parser for internal links was vulnerable to XSS using this payload:
[[#%3Cscript%3Ealert(1)%3C/script%3E|
[[and]]are the wiki markup for an internal link, a link to another page on the same wiki. The double brackets are the signal to the parser: treat what is between us as a link.#marks a fragment, a jump target inside a page, the same idea as the part after a#in a normal web address.%3Cis the percent-encoded form of the<character. Percent-encoding is a way of writing characters that would otherwise be awkward or unsafe in a URL, using a percent sign and two hexadecimal digits.%3Cmeans<and%3Emeans>.scriptis the name of the HTML element that tells a browser to run code.alert(1)is the classic harmless test: it makes the browser pop up a small dialogue box showing the number 1. If you see the box, your code ran.%3C/script%3Eis the percent-encoded closing tag,</script>.- The trailing
|is part of the link syntax and is left dangling. It is enough for the parser to accept the construct.
The report says the MediaWiki parser for internal links was vulnerable to XSS with this payload, without describing the mechanism. Escaping means converting characters that have special meaning in HTML into harmless equivalents so the browser shows them as text instead of treating them as code. Here that step is missing, so the script tag lands in the HTML as live code.
Exploitation
Step 1: Confirm the payload is stored and rendered
The researcher found the payload successful in several areas: form creation, wiki pages, and media description fields, all under the wpTextbox1 form field. wpTextbox1 is the name MediaWiki gives to the main edit text box, the large area where you type wiki markup. Anything that accepts wiki markup through that field is a candidate, because the same parser handles it.
Why this step matters: a stored XSS only counts if the payload survives being saved and then runs when the page is viewed. Seeing the alert box after saving, not just while typing, is the proof.
Step 2: Attempt cookie theft
Using xsshunter.com, the researcher crafted a payload intended to steal their own cookie, purely to demonstrate impact. A cookie is a small piece of data a website asks your browser to keep and send back with later requests. It is how a site remembers that you are logged in: the cookie acts like a wristband you get at the door and show at every counter inside. If someone else gets your wristband, they can act as you. That is why stealing a session cookie is the classic demonstration for XSS.
The report does not reproduce that payload. The attempt failed to yield a useful cookie because the page was served over HTTP while the cookies were secure-only. HTTP is the plain, unencrypted version of the web protocol. A secure-only cookie is one the browser will only send over an encrypted connection, HTTPS. Since the site was plain HTTP, the browser would not send those cookies at all, so there was nothing for the payload to capture. The stored XSS itself was still demonstrated, which was enough for the report to be accepted.
Step 3: Report
The vulnerability was reported in three separate places in a single combined report. The report was accepted. At the time of writing, all patching attempts had failed.
Root cause
The parser for internal links decodes the percent-encoded fragment and then places it into the output without adequate escaping, so encoded markup such as %3Cscript%3E becomes live HTML. The report frames the wider problem as architectural: MediaWiki appears to manage filtering by creating exclusions and individual replacements for specific payloads, strings, and characters within each separate piece of the codebase, based on the various Phabricator threads the researcher read. Phabricator is the bug-tracking system the project uses.
Think of it as a building with many doors where the guard writes down a list of known troublemakers and checks names at each door separately. A new disguise, a new spelling or a new door the guard forgot about, and the person walks straight in. That approach leaves gaps wherever a new encoding or syntax path reaches the same sink. A sink is the place in the code where data finally gets written into the page. A holistic change to how user-provided content is filtered would be needed across the entire codebase, which the researcher acknowledges is easier said than done for a crowd-sourced CMS. A CMS, content management system, is software for publishing and managing website content, and crowd-sourced means many contributors rather than one team. The report does not identify the specific function or file where the escaping is missing.
Impact
An attacker who can write content into the wiki, through page creation, forms or media description fields, can store script that executes in the browser of anyone who views the affected content. In this case the practical impact was limited by the site being served over HTTP with secure-only cookies, so session cookies were not exposed over that channel. The report does not assess impact against other cookie configurations or other users' sessions beyond this.
Fix
No fix is described. The report states that patching attempts had failed and that the researcher would update the write-up if a patch were implemented successfully. The report says a holistic change in how user-provided content is filtered would be required across the codebase. Output encoding means converting special characters into safe equivalents at the moment the page is built, so the browser always treats user text as text.
Variants to test
- Try the same internal-link payload in every field that submits through
wpTextbox1: page edits, form creation, and media description fields. A positive result is the script executing when the saved content is viewed. - Vary the encoding of the fragment: double-encoding, mixed case in the tag name, and other percent-encoded forms of
<script>. A positive result is execution where the plain payload was filtered. - Try other MediaWiki markup constructs that accept a fragment or free text, such as links with different prefixes. A positive result is the same decode-then-render behaviour in a different parser path.
- Test whether the payload survives preview versus save, since preview and stored rendering can use different code paths. A positive result is execution on the saved page even if preview is clean.
- Where cookies are secure-only and the site is HTTP, look for other exfiltration channels or higher-privileged viewers. A positive result is script execution in a context where a meaningful secret is reachable.
Glossary
- Access control: the rules that decide who may see or change what on a website.
- Bypass: getting past a security filter or restriction that is meant to block you.
- Callback: the signal a payload sends back to the researcher when it runs, proving execution.
- CMS (content management system): software for publishing and managing website content.
- Cookie: a small piece of data a site asks your browser to store and send back with later requests, often used to keep you logged in.
- CVE: a publicly assigned identifier for a known security flaw.
- Escaping / output encoding: converting characters with special meaning in HTML into harmless equivalents so they display as text.
- Fragment: the part of a web address after
#, pointing to a location inside a page. - Fuzzing: sending large numbers of variations at a target and watching for unusual behaviour.
- HTTP / HTTPS: the plain and the encrypted versions of the web protocol.
- Internal link: in wiki markup, a link to another page on the same wiki, written with double square brackets.
- MediaWiki: the wiki software behind Wikipedia and many other crowd-sourced sites.
- MITRE: an organisation that maintains a catalogue of known security flaws.
- Parser: the part of the software that reads wiki markup and turns it into a web page.
- Payload: the piece of text that carries the malicious code.
- Percent-encoding: writing characters as a percent sign plus two hexadecimal digits, such as
%3Cfor<. - Phabricator: the bug-tracking system the project uses.
- Reflected XSS: XSS that bounces back in the response to one request and only affects the person who sends it.
- Secure-only cookie: a cookie the browser only sends over an encrypted HTTPS connection.
- Session cookie: the cookie that identifies your logged-in session.
- Sink: the place in code where data is finally written into the page.
- Stored XSS: XSS where the payload is saved on the server and served to everyone who views the affected content.
- Wiki markup: the lightweight formatting language used to write wiki pages.
- wpTextbox1: the name MediaWiki gives to the main edit text box.