Content-Length: 312345 | pFad | https://github.com/python/cpython/issues/148954

ad xmlrpc.client lacks sanitization in `methodname` · Issue #148954 · python/cpython · GitHub
Skip to content

xmlrpc.client lacks sanitization in methodname #148954

Description

@DarkaMaul

Bug report

Bug description:

Summary

dumps() interpolates the method name directly into <methodName> tags without XML escaping. If an application derives methodname from user input, an attacker can inject XML markup into the request body.

Details

The method name is interpolated into a tuple that is later joined into the final XML string:

if methodname:
# a method call
data = (
xmlheader,
"<methodCall>\n"
"<methodName>", methodname, "</methodName>\n",
data,
"</methodCall>\n"
)

The tuple is serialized via "".join(data). The method name is written raw into XML without calling the module's escape() helper (used elsewhere, e.g., for string values in dump_unicode).

Reproducer

import xml.etree.ElementTree as ET
from xmlrpc.client import dumps

def main():
    payload = 'foo</methodName><injected attr="evil"/><methodName>bar'
    result = dumps((), methodname=payload)

    root = ET.fromstring(result)

    method_names = root.findall("methodName")
    assert len(method_names) == 2, (
        f"Expected 2 <methodName> elements from injection, got "
        f"{len(method_names)}"
    )

    print("Generated XML:")
    print(result)

if __name__ == "__main__":
    main()

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/148954

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy