Skip to content

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

Closed

Description

@serhiy-storchaka

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

Activity

  1. picnixz commented on Oct 26, 2025

    @picnixz
    Member

    Yes we need because those versions are still supported from a security perspective. So only 3.9-3.14 fixes.

  2. changed the title [-]OOM vulnerability in the CGI server on Windows[/-] [+]OOM a potential denial of service in the CGI server on Windows[/+] on Nov 18, 2025
  3. added a commit that references this issue on Nov 18, 2025
  4. added
    3.15bugs and security fixes
    and removed on Nov 18, 2025
  5. added a commit that references this issue on Dec 1, 2025
  6. added 4 commits that reference this issue on Dec 1, 2025
  7. added a commit that references this issue on Dec 1, 2025
  8. gpshead commented on Dec 2, 2025

    @gpshead
    Member

    @colesbury flagged a buildbot failure - #119455 (comment)

    looks like the select is non-blocking rather than blocking when we still needed more data. https://github.com/python/cpython/pull/119455/files#r2580013415

  9. added and removed
    3.15bugs and security fixes
    on Dec 2, 2025
  10. added 3 commits that reference this issue on Dec 2, 2025
  11. added 2 commits that reference this issue on Dec 2, 2025
  12. added a commit that references this issue on Dec 2, 2025
  13. added a commit that references this issue on Dec 2, 2025
  14. added 3 commits that reference this issue on Dec 3, 2025
  15. added 4 commits that reference this issue on Dec 5, 2025
  16. removed
    3.14bugs and security fixes
    on Dec 5, 2025
  17. added a commit that references this issue on Dec 5, 2025
  18. added a commit that references this issue on Dec 15, 2025
  19. added 2 commits that reference this issue on Jan 25, 2026
  20. encukou commented on Jan 26, 2026

    @encukou
    Member

    All the backports are merged now.

  21. vstinner commented on May 13, 2026

    @vstinner
    Member

    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.

  22. added 2 commits that reference this issue on Sep 2, 2026
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 life3.11only security fixes3.12only security fixes3.13only security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directorytopic-IOtype-securityA security issue

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions