Page MenuHomePhabricator

🤖️ Wikibase REST API ignores `bot` user right, lets anyone mark edits as bot edits
Closed, ResolvedPublic5 Estimated Story PointsSecurity

Description

Expected behaviour: Making an edit marked as "bot" with Wikibase REST API when the client does not authenticate as a user having a "bot" right should be rejected due to insufficient permissions.
Current behaviour. Making a bot edit as an anonymous user (who does not have "bot" right) succeeds - the edit is marked as done by bot and skipped in Recent Changes


Note: the Wikibase REST API isn’t enabled in production yet, no need to panic :)

curl -i -H 'Content-Type: application/json' --data '{"statement":{"type":"statement","mainsnak":{"snaktype":"value","property":"P62013","datavalue":{"type":"string","value":"abcde"}},"rank":"normal"},"bot":true}' https://wikidata.beta.wmflabs.org/w/rest.php/wikibase/v0/entities/items/Q81561/statements

Resulting edit:

image.png (27×940 px, 13 KB)

That’s an anonymous edit (note the lack of authentication in the request) – it definitely shouldn’t be allowed to be listed as a bot edit in the recent changes (which means it won’t be shown by default in recent changes or watchlists). The bot flag in the request should be silently ignored, because the anonymous user doesn’t have the bot right (compare Special:UserGroupRights).

This happens because MediaWikiEditEntityFactoryItemUpdater::update() directly sets the EDIT_FORCE_BOT flag based on the edit metadata bot flag, which in turn directly comes from the request (in AddItemStatement::execute()).

		$status = $editEntity->attemptSave(
			$item,
			$this->summaryFormatter->format( $editMetadata->getSummary() ),
			EDIT_UPDATE | ( $editMetadata->isBot() ? EDIT_FORCE_BOT : 0 ), // <--
			false,
			false,
			$editMetadata->getTags()
		);

It’s missing an equivalent of this EntitySavingHelper::attemptSaveEntity() snippet somewhere in the chain (or maybe it should use the helper instead of the underlying EditEntity?):

		if ( isset( $requestParams['bot'] ) && $requestParams['bot'] &&
			$this->permissionManager->userHasRight( $user, 'bot' ) // <--
		) {
			$flags |= EDIT_FORCE_BOT;
		}

Details

Risk Rating
Low
Author Affiliation
Wikimedia Deutschland

Event Timeline

Notes from task breakdown:

  • throw an exception in MediaWikiEditEntityFactoryItemUpdater in case it gets an EditMetadata object with the bot flag set to true but with a user who doesn't have the corresponding right.
  • create a middleware that does the same check and returns an error response (TBD)
Jakob_WMDE renamed this task from Wikibase REST API ignores `bot` user right, lets anyone mark edits as bot edits to 🤖️ Wikibase REST API ignores `bot` user right, lets anyone mark edits as bot edits.Oct 25 2022, 2:23 PM

Verified locally to work as expected. Thanks

sbassett added a project: SecTeam-Processed.
sbassett subscribed.

Note: the Wikibase REST API isn’t enabled in production yet, no need to panic :)

Is there a reason not to make this public then? I feel like this could probably be worked upon in gerrit unless I'm missing something.

Good point @sbassett. For that reasons it was actually worked upon in the open on Gerrit

WMDE-leszek changed the visibility from "Custom Policy" to "Public (No Login Required)".Nov 20 2022, 2:05 PM
WMDE-leszek changed the edit policy from "Custom Policy" to "All Users".

Good point @sbassett. For that reasons it was actually worked upon in the open on Gerrit

Ok. Is there a change set we could reference here? Searching the Phab task ID doesn't seem to get me anything...

sbassett changed Risk Rating from N/A to Low.Nov 21 2022, 3:52 PM

oh dear, I think we have created some mess here. Changes/patches have been linked to subtasks of that "story" -- subtasks have inherited the limited visibility of this ticket. Fixing it now.

Relevant changes are
https://gerrit.wikimedia.org/r/c/851610
https://gerrit.wikimedia.org/r/c/852204

WMDE-leszek claimed this task.