Page MenuHomePhabricator

CVE-2025-62655: SQL injection in Cargo via Special:CargoExport
Closed, ResolvedPublicSecurity

Description

The Cargo extension inserts the values of two URL parameters into raw SQL without escaping them, allowing for SQL injection.

Reproduction steps

  1. Create Template:Author:
<noinclude>{{#cargo_declare:_table=Authors|Birthday=Date}}</noinclude>
<includeonly>{{#cargo_store:_table=Authors}}</includeonly>
  1. Create the cargo table at /w/index.php?title=Template:Author&action=recreatedata
  2. Create a page with the following contents: {{Author|Birthday=2024-01-01}}
  3. Go to /wiki/Special:CargoExport?format=fullcalendar&tables=Authors&fields=Birthday&start=2025-01-01%27))%20OR%20SLEEP(5);--%20 and observe that the query takes 5s to load, because the SLEEP() function is executed.

Cause

$datesLowerLimit and $datesUpperLimit are retrieved from the start and end request parameters:
https://github.com/wikimedia/mediawiki-extensions-Cargo/blob/5b7fe938f3bb4c758d8a58fbe36cdeee2bb4f1a6/includes/specials/CargoExport.php#L128-L129
Both variables are then inserted into raw SQL without any escaping being done:
https://github.com/wikimedia/mediawiki-extensions-Cargo/blob/5b7fe938f3bb4c758d8a58fbe36cdeee2bb4f1a6/includes/specials/CargoExport.php#L150

The payload 2025-01-01')) OR SLEEP(5);-- can therefore be used to break out of the single quotes and inject arbitrary SQL.

Additional information

  • MediaWiki: 1.45.0-alpha
  • Cargo: b304b24

Event Timeline

Change #1186068 had a related patch set uploaded (by Yaron Koren; author: Yaron Koren):

[mediawiki/extensions/Cargo@master] Add escaping of "start" and "end for calendar format

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

@Yaron_Koren please properly provide attribution in the patchset to me

I'd recommend using git am; otherwise I can also upload it myself

@Yaron_Koren please properly provide attribution in the patchset to me

I've done so myself now, but it is usually common practice to use git am to apply a patch locally before uploading it, so the author field of the commit is correctly set.

I think the gate-and-submit job for the patchset was cancelled because you edited the commit message after +2ing it (not sure whether that is actually intended to happen in this case, probably not)

Change #1186068 merged by jenkins-bot:

[mediawiki/extensions/Cargo@master] Add escaping of "start" and "end for calendar format

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

@SomeRandomDeveloper - thank you for the patch! This was a pretty serious bug.

I assume this can be closed.

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

[mediawiki/extensions/Cargo@REL1_44] Add escaping of "start" and "end for calendar format

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

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

[mediawiki/extensions/Cargo@REL1_43] Add escaping of "start" and "end for calendar format

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

sbassett renamed this task from SQL injection in Cargo via Special:CargoExport to CVE-2025-62655: SQL injection in Cargo via Special:CargoExport.Oct 17 2025, 10:46 PM
sbassett triaged this task as Medium priority.
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 Medium.

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

[mediawiki/extensions/Cargo@REL1_39] Add escaping of "start" and "end for calendar format

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

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

[mediawiki/extensions/Cargo@REL1_39] Add escaping of "start" and "end for calendar format

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

Change #1196984 abandoned by SBassett:

[mediawiki/extensions/Cargo@REL1_39] Add escaping of "start" and "end for calendar format

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

Evidently some other fix needs to be backported to these branches before this change (or any other) can pass validation; I thought it was this one, but clearly not, since this cherry-picked version gets the same error:

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Cargo/+/1196985

From what @SomeRandomDeveloper tells me, master is really the only maintained branch of ext:Cargo at this point. So we have a few options here, IMO:

  1. Abandon the backports for 1.39, 1.43 and 1.44
  2. Fix the unrelated issues on those branches to get things testing fine
  3. Just force-merge the backports as the test issues seem completely unrelated

1 is the easy option. 2 is potentially way too much effort given the likely realities of ext:Cargo usage. And 3 is likely fine in this case but certainly a bit dangerous.

Actually, there's a fourth option, as far as I can tell: delete the REL1_43 and REL1_44 branches, and recreate them as copies of master. (This unfortunately can't be done for REL1_39, since the latest Cargo code only supports MW 1.40 and higher.) I would think this is the best option, at least for those two branches, since it's the most painless overall. But I'm not against any of these.

As Cargo doesn't use release branches, they could just be deleted (that would reduce confusion all around I think).

Change #1196980 merged by jenkins-bot:

[mediawiki/extensions/Cargo@REL1_44] Add escaping of "start" and "end for calendar format

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

As Cargo doesn't use release branches, they could just be deleted (that would reduce confusion all around I think).

Ok, that should be a separate task (filed as T407862). I think we can just request that it be removed from Wikimedia branching or something like that?

Evidently some other fix needs to be backported to these branches before this change (or any other) can pass validation; I thought it was this one, but clearly not, since this cherry-picked version gets the same error:

Just FYI, in this instance, it's fairly trivial to fix the failing tests on the release branches - they just need https://gerrit.wikimedia.org/r/1197350 and https://gerrit.wikimedia.org/r/1197348 backported to them as ParserOutput::getText() is now hard-deprecated: https://gerrit.wikimedia.org/r/1146557. I've already done this for REL1_44 and that backport for this issue is now merged. But to the larger point, we obviously shouldn't be wasting time on backports if only master is actually supported for Cargo development and releases.

Change #1196983 merged by jenkins-bot:

[mediawiki/extensions/Cargo@REL1_39] Add escaping of "start" and "end for calendar format

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

Change #1196981 abandoned by SBassett:

[mediawiki/extensions/Cargo@REL1_43] Add escaping of "start" and "end for calendar format

Reason:

Cargo isn't supported on this branch and this is a non-trivial backport

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