GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — OOM a potential denial of service in the CGI server on Windows · Issue #119452 · python/cpython

OOM a potential denial of service in the CGI server on Windows #119452

New issue
Copy link
New issue
Copy link
Closed
Closed
OOM a potential denial of service in the CGI server on Windows#119452
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IOtype-securityA security issueA security issue

Description

@serhiy-storchaka
serhiy-storchaka
opened on May 23, 2024
Issue body actions

When http.server.CGIHTTPRequestHandler on Windows (and other platforms without fork()) handles the POST request, it reads the whole body of the POST request in memory before sending it to the subprocess running the script. The underlying SocketIO allocates the amount of memory specified in the Content-Length header before actual reading the data, so a small request with incorrect Content-Length can cause consumption of the large amount of memory and CPU time and can be used in the DOS attack on the server.

Linked PRs

  • [3.14] gh-119452: Fix a potential virtual memory allocation denial of service in http.server #119455
  • [3.13] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) #142130
  • [3.12] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) #142131
  • [3.11] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) #142132
  • [3.10] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) #142133
  • [3.14] gh-119452: Block until data is read #142176
  • [3.14] gh-119452: Remove select, skip 'truncated' test #142178
  • [3.14] Try to fix the fix for gh-119452 #142180
  • [3.14] gh-119452: Read/write CGI data using worker threads #142181
  • [3.14] Revert "gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455)" #142184
  • [3.13] Revert "gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) (GH-142130)" #142185
  • [3.14] gh-119452: Fix a potential virtual memory allocation denial of service in http.server #142216
  • [3.13] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-142216) #142296
  • [3.12] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-142216) #142297
  • [3.11] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-142216) #142298
  • [3.10] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-142216) #142299
  • [3.14] gh-119452: test_large_content_length_truncated: Don't use the full LOOPBACK_TIMEOUT on Windows #156761
  • [3.13] gh-119452: test_large_content_length_truncated: Don't use the full LOOPBACK_TIMEOUT on Windows (GH-156761) #156851

Activity

Next
  1. serhiy-storchaka
    added
    type-securityA security issueA security issue
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.11only security fixesonly security fixes
    3.10 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    3.8 (EOL)end of lifeend of life
    topic-IO
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on May 23, 2024
  2. picnixz commented on May 23, 2024

    @picnixz
    picnixz
    on May 23, 2024
    Member
    More actions

    Correct me if I'm wrong, but the incriminated lines are the following right:

    cpython/Lib/http/server.py

    Lines 1226 to 1227 in c85e352

    if self.command.lower() == "post" and nbytes > 0:
    data = self.rfile.read(nbytes)

    If so, could I perhaps take on this one? (I never directly contributed to CPython so I think I can take this one to setup everything that's needed, unless you are already working on it).

  3. serhiy-storchaka
    added a commit that references this issue on May 23, 2024

    pythongh-119452: Fix OOM vulnerability in http.server

    8d16f15
  4. serhiy-storchaka commented on May 23, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on May 23, 2024
    MemberAuthor
    More actions

    Thank you for volunteering @picnixz, but I already have a solution. I have been somewhat delayed in publishing it because I discovered other problem: the large body was truncated on Windows, because SocketIO.read() is unbuffered and can return a partial data.

  5. picnixz commented on May 23, 2024

    @picnixz
    picnixz
    on May 23, 2024
    Member
    More actions

    No worries! I think you are much faster than me on that since I'm not really familiar with the http and IO-related codebase.

  6. cmaloney commented on Oct 26, 2025

    @cmaloney
    cmaloney
    on Oct 26, 2025
    Contributor
    More actions

    Given this code has been removed for 3.15 (gh-133810), do we need to fix this on older versions or can we close this issue?

  7. 32 remaining items

  8. miss-islington
    added a commit that references this issue on Dec 5, 2025

    [3.14] pythongh-119452: Fix a potential virtual memory allocation den…

    0411337
  9. hugovk
    removed
    3.14bugs and security fixesbugs and security fixes
    on Dec 5, 2025
  10. Yhg1s
    added a commit that references this issue on Dec 5, 2025

    [3.13] gh-119452: Fix a potential virtual memory allocation denial of…

    9303573
  11. Yhg1s
    added a commit that references this issue on Dec 15, 2025

    [3.12] gh-119452: Fix a potential virtual memory allocation denial of…

    d849cf5
  12. pablogsal
    added 2 commits that reference this issue on Jan 25, 2026

    [3.10] gh-119452: Fix a potential virtual memory allocation denial of…

    f2088a5

    [3.11] gh-119452: Fix a potential virtual memory allocation denial of…

    fa1aae0
  13. encukou commented on Jan 26, 2026

    @encukou
    encukou
    on Jan 26, 2026
    Member
    More actions

    All the backports are merged now.

  14. encukou
    closed this as completedon Jan 26, 2026
  15. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Jan 26, 2026
  16. vstinner commented on May 13, 2026

    @vstinner
    vstinner
    on May 13, 2026
    Member
    More actions

    The test is a little bit fragile. Example of failure on "AMD64 FreeBSD Refleaks 3.13" buildbot: https://buildbot.python.org/#/builders/1615/builds/1722

    ERROR: test_large_content_length_truncated (test.test_httpservers.CGIHTTPServerTestCase.test_large_content_length_truncated)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/buildbot/buildarea/3.13.ware-freebsd.refleak/build/Lib/test/test_httpservers.py", line 1028, in test_large_content_length_truncated
        res = self.request('/cgi-bin/file1.py', 'POST', b'x', headers)
      File "/buildbot/buildarea/3.13.ware-freebsd.refleak/build/Lib/test/test_httpservers.py", line 89, in request
        return self.connection.getresponse()
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
      File "/buildbot/buildarea/3.13.ware-freebsd.refleak/build/Lib/http/client.py", line 1450, in getresponse
        response.begin()
        ~~~~~~~~~~~~~~^^
      File "/buildbot/buildarea/3.13.ware-freebsd.refleak/build/Lib/http/client.py", line 336, in begin
        version, status, reason = self._read_status()
                                  ~~~~~~~~~~~~~~~~~^^
      File "/buildbot/buildarea/3.13.ware-freebsd.refleak/build/Lib/http/client.py", line 297, in _read_status
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
                   ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
      File "/buildbot/buildarea/3.13.ware-freebsd.refleak/build/Lib/socket.py", line 723, in readinto
        return self._sock.recv_into(b)
               ~~~~~~~~~~~~~~~~~~~~^^^
    ConnectionResetError: [Errno 54] Connection reset by peer
    

    One explanation is the hardcoded timeout of 1 ms in the test:

    with support.swap_attr(self.request_handler, 'timeout', 0.001):

    This timeout is too low if the machine running the test has high system load.

    For example, ./python -m test test_httpservers -v -m test_large_content_length_truncated -F -j10 fails quickly.

  17. zware
    added 2 commits that reference this issue on Sep 2, 2026

    [3.14] gh-119452: test_large_content_length_truncated: Don't use the …

    abab655

    [3.13] gh-119452: test_large_content_length_truncated: Don't use the …

    5854534
  18. icanhasmath
    added 3 commits that reference this issue on Oct 27, 2026

    3.9.25.x: catch socket.timeout in the pythongh-119452 CGI read loop

    c516861

    [3.10] pythongh-119452: Fix a potential virtual memory allocation den…

    34072c5

    3.9.25.x: catch socket.timeout in the pythongh-119452 CGI read loop

    ba4c2aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IOtype-securityA security issueA security issue

    Projects

    • Release and Deferred blockers 🚫
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.