Page MenuHomePhabricator

CVE-2023-37255: Special:CheckUser 'get edits' is vulnerable to HTML injection through user agent string
Closed, ResolvedPublicSecurity

Description

Steps to reproduce

  • Modify your user agent to include HTML
  • Make a test edit or logged action
  • Load Special:CheckUser
  • Run a check using the 'get edits' type
  • Notice that the HTML isn't escaped

Example
Override your user agent string (example using Firefox about:config):

image.png (101×2 px, 13 KB)

Inspecting the logged edit using inspect element:
image.png (107×560 px, 6 KB)

Other information
The user agent is truncated before insertion into the database at 255 bytes which could make it harder to abuse. Only occurs when running the 'get edits' check type.

Event Timeline

Dreamy_Jazz renamed this task from Special:CheckUser vulnerable to HTML injection through user agent string to Special:CheckUser 'get edits' is vulnerable to HTML injection through user agent string.Mar 30 2023, 2:44 PM

Proposed patch:

Please add a SECURITY: prefix to the commit message.

Proposed patch:

Please add a SECURITY: prefix to the commit message.

Done. Updated patch provided below:

Added prefix, will deploy now. I was able to reproduce the issue and test the fix locally.

Scratch that, I’ll use the updated patch from @Dreamy_Jazz instead :)

@Reedy I wonder if we can include this in the security release that you pre-announced yesterday? Or is this too short notice? (Security deployment is currently ongoing, btw.)

This fix needs backporting to 1.39 and 1.40. 1.38 and before doesn't seem to have this problem.

This fix needs backporting to 1.39 and 1.40. 1.38 and before doesn't seem to have this problem.

Agreed, I just checked the same thing. (The bug was introduced in 6d6b229c02, the old code was using htmlspecialchars( $row->cuc_agent ) and thus safe.)

The fix should be deployed on wmf.1 and wmf.2 now. (I used deploy_security.py.)

Can verify this deployed correctly.

Was able to verify without the need to spoof my user agent to include HTML as there is separate bug with the template parser that makes the user agent not display if there is a specific character (which is how I found this issue) when the value is escaped. That issue is rare (only seen it once) and isn't a security issue. Will be looking for the associated task and if not filing one.

Thanks all for the quick patch and deploy.

@Reedy I wonder if we can include this in the security release that you pre-announced yesterday? Or is this too short notice? (Security deployment is currently ongoing, btw.)

Since CheckUser isn't bundled with core, it would go out as part of a supplemental security releases (current tracking bug: T325849). I don't know if I'd agree there's any sense of urgency here - anything within the supplemental release can be made public and have backports performed once the issue has been patched in Wikimedia production. So this issue could be a part of the next supplemental security release, but be disclosed and backported much sooner.

So this issue could be a part of the next supplemental security release, but be disclosed and backported much sooner.

Considering that users of the release branches will be pulling the changes soon, getting this merged into the release branches before the git pull is run makes sense to me. Therefore, given that this seems to be an okay thing once it's fixed in WMF production (which it has been), I'll do as such now.

A useful side effect of getting this fix out is that it makes fixing a non-security bug easier as this method of escaping seems to prevent some unicode characters being displayed (see T333573). The temporary fix (unless I can find the core issue) would be to use htmlspecialchars to escape the value. This method would conflict with the currently deployed security patch.

sbassett added a subscriber: gerritbot.

Considering that users of the release branches will be pulling the changes soon, getting this merged into the release branches before the git pull is run makes sense to me. Therefore, given that this seems to be an okay thing once it's fixed in WMF production (which it has been), I'll do as such now.

That's fine - I've got it tracked for the next supplemental release: T333626. Completely fine to open this up and do backports now.

sbassett changed the task status from Open to In Progress.Apr 4 2023, 8:05 PM
sbassett triaged this task as Medium priority.
sbassett changed Author Affiliation from N/A to Wikimedia Communities.
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 905733 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@REL1_40] SECURITY: Escape user-agent in SpecialCheckUser get edits mode

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

Change 905734 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@REL1_39] SECURITY: Escape user-agent in SpecialCheckUser get edits mode

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

Change 905734 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@REL1_39] SECURITY: Escape user-agent in SpecialCheckUser get edits mode

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

Change 905733 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@REL1_40] SECURITY: Escape user-agent in SpecialCheckUser get edits mode

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

Change 905706 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] SECURITY: Escape user-agent in SpecialCheckUser get edits mode

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

Unsure what else might need to be done before this can be marked as resolved (i.e. removing the patch on WMF systems), but the fix has been merged and backported to all supported versions that were vulnerable.

Unsure what else might need to be done before this can be marked as resolved (i.e. removing the patch on WMF systems), but the fix has been merged and backported to all supported versions that were vulnerable.

We track Wikimedia production patches on another task and Release Engineering has a step in the train that detects when such patches should fall off. So I think this can be resolved for now.

mmartorana renamed this task from Special:CheckUser 'get edits' is vulnerable to HTML injection through user agent string to CVE-2023-37255: Special:CheckUser 'get edits' is vulnerable to HTML injection through user agent string.Jun 30 2023, 5:54 PM