Skip to content

gh-148954: Escape methodname in xmlrpc.client.dumps() to prevent XML injection#148968

Merged
serhiy-storchaka merged 10 commits into
python:mainfrom
sanyamk23:fix-xmlrpc-methodname-sanitization
Jun 6, 2026
Merged

gh-148954: Escape methodname in xmlrpc.client.dumps() to prevent XML injection#148968
serhiy-storchaka merged 10 commits into
python:mainfrom
sanyamk23:fix-xmlrpc-methodname-sanitization

Conversation

@sanyamk23
Copy link
Copy Markdown
Contributor

Summary

This PR fixes an XML injection vulnerability in xmlrpc.client.dumps() where the methodname was interpolated directly into the <methodName> tag without escaping.

Details

The methodname is now passed through the module's escape() helper function before being added to the XML request body. This prevents attackers from injecting arbitrary XML markup if they can control the method name.

Verification

  • Confirmed that a payload like 'foo</methodName><injected attr="evil"/><methodName>bar' is correctly escaped as 'foo&lt;/methodName&gt;&lt;injected attr="evil"/&gt;&lt;methodName&gt;bar'.
  • Verified that standard method names (alpha-numeric) continue to work without modification.
  • Verified that special characters in method names are correctly recovered when unmarshalled.

Fixes gh-148954

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Apr 24, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@sanyamk23 sanyamk23 force-pushed the fix-xmlrpc-methodname-sanitization branch from 4c5e015 to 4e67dfd Compare April 24, 2026 17:25
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 24, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Comment thread Lib/test/test_xmlrpc.py Outdated
Comment thread Lib/test/test_xmlrpc.py Outdated
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @sethmlarson @StanFromIreland (I think this was a GHSA right? I didn't follow the discussion so there might be more that you wanted to add).

Comment thread Misc/NEWS.d/next/Security/2026-04-24-19-54-00.gh-issue-148954.v1.rst Outdated
@StanFromIreland
Copy link
Copy Markdown
Member

FTR: this was GHSA-w5gj-44cx-wmcj.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels May 9, 2026
@serhiy-storchaka
Copy link
Copy Markdown
Member

@sanyamk23, please sing the CLA.

@serhiy-storchaka
Copy link
Copy Markdown
Member

@sanyamk23, we cannot merge this PR until you sign the CLA.

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) June 6, 2026 21:15
@serhiy-storchaka serhiy-storchaka changed the title gh-148954: sanitize methodname in xmlrpc.client.dumps() to prevent XML injection gh-148954: Escape methodname in xmlrpc.client.dumps() to prevent XML injection Jun 6, 2026
@serhiy-storchaka serhiy-storchaka merged commit ab93017 into python:main Jun 6, 2026
94 of 97 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @sanyamk23 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Jun 6, 2026

GH-151033 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 6, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Jun 6, 2026

GH-151034 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 6, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Jun 6, 2026

GH-151035 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xmlrpc.client lacks sanitization in methodname

4 participants