498 Commits

Author SHA1 Message Date
Miss Islington (bot) aa06529dfb [3.15] gh-150743: Limit trailer lines and interim responses read by http.client (GH-150741) (#152523)
gh-150743: Limit trailer lines and interim responses read by http.client (GH-150741)

http.client read chunked-response trailer lines and skipped interim (1xx)
responses in unbounded loops, so a server streaming either forever would
hang the client even with a socket timeout set (data keeps arriving, so
the timeout never fires).

Trailer lines are now limited to max_response_headers (100 by default)
and interim responses to 100; HTTPException is raised past either limit.

Follow-up to gh-88188 for CVE-2021-3737, which bounded header lines
within an interim response but not these two sibling loops.
(cherry picked from commit 41cc78a7a4)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>

---

This issue was reported to us via [GHSA-w4q2-g22w-6fr4](https://github.com/python/cpython/security/advisories/GHSA-w4q2-g22w-6fr4) and was determined not to be high enough severity to handle privately.

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2026-06-28 19:35:27 +00:00
Miss Islington (bot) ed27363ddf [3.15] gh-149144: Use decodeURIComponent() for UTF-8 support in js_output() (GH-149157) (GH-149846)
gh-149144: Use decodeURIComponent() for UTF-8 support in js_output() (GH-149157)
(cherry picked from commit 461b1d9631)

Co-authored-by: Seth Larson <seth@python.org>
2026-05-15 00:38:11 +02:00
Hugo van Kemenade ef6f0635ce gh-142389: Add backticks to stdlib argparse help to display in colour (#149384)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
2026-05-04 22:23:18 +00:00
kishorhange111 246fe14e7c gh-148849: Deprecate http.cookies.BaseCookie.js_output() (GH-148978) 2026-05-04 12:51:17 +03:00
Anton Ian Sipos 836fbdaaf3 gh-135056: Add a --header CLI option to http.server (#135057)
Support custom headers in `python -m http.server` and `http.server.SimpleHTTPRequestHandler`.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-05-03 13:01:37 +02:00
Serhiy Storchaka c80e446e6b gh-149028: Revert gh-92936 changes (GH-149182)
* Revert "gh-92936: update `http.cookies` docs post GH-113663 (#137566)"

This reverts commit d86c2257a6.

* Revert "gh-92936: allow double quote in cookie values (#113663)"

This reverts commit d7dbde8958.
2026-04-30 22:19:46 +03:00
John Comeau cc5f8b5434 gh-113471: Add custom default Content-Type to http.server (#113475)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: donBarbos <donbarbos@proton.me>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-04-30 18:00:48 +03:00
Weilin Du 4a5d25c26c gh-135528: Support more second-level domain names in http.cookiejar (#135820)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-04-29 11:33:51 +00:00
Seth Larson 76b3923d68 gh-90309: Base64-encode cookie values embedded in JS 2026-04-22 19:22:31 +00:00
Seth Larson 05ed7ce7ae gh-146211: Reject CR/LF in HTTP tunnel request headers (#146212)
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
2026-04-10 15:21:42 +00:00
Hugo van Kemenade 2c8f26cf5c gh-146292: Add colour to http.server logs (GH-146293)
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
2026-04-08 14:10:05 +02:00
Stan Ulbrych 57e88c1cf9 gh-145599, CVE 2026-3644: Reject control characters in http.cookies.Morsel.update() (#145600)
Reject control characters in `http.cookies.Morsel.update()` and `http.cookies.BaseCookie.js_output`.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
2026-03-16 14:43:43 +01:00
Seth Michael Larson 95746b3a13 gh-143919: Reject control characters in http cookies
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
2026-01-20 21:23:42 +00:00
Hugo van Kemenade 170dac291e gh-76007: Deprecate __version__ attribute in http.server (#142658)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-12-13 15:32:13 +00:00
Serhiy Storchaka 5a4c4a033a gh-119451: Fix a potential denial of service in http.client (GH-119454)
Reading the whole body of the HTTP response could cause OOM if
the Content-Length value is too large even if the server does not send
a large amount of data. Now the HTTP client reads large data by chunks,
therefore the amount of consumed memory is proportional to the amount
of sent data.
2025-12-01 17:26:07 +02:00
Filip Łajszczak ce1bb85d28 gh-139434: Update selected RFC 2822 references to RFC 5322 (#139435)
Update selected RFC 2822 references to RFC 5322

RFC 2822 was obsoleted by RFC 5322 in 2008. This updates references
to use the current standard in documentation, docstrings, and comments.

It preserves RFC 2822 references in legacy API components to maintain their
historical context.

RFC 822 → RFC 2822 → RFC 5322 progression is explained where relevant.

In some places specific sections of RFC are referenced where it seems helpful.

Scout rule was applied in some places and RFC mentions format was
normalized in doc strings and comments.
2025-11-04 14:46:07 -05:00
R. David Murray 81cec22a9b gh-57665: Remove 'response_class' from getresponse docstring. (#140707)
Remove 'response_class' from getresponse docstring.

This variable is not documented as part of the API in the standard
library documentation; it should be considered as an implementation
detail and as such should not be included in the doc string.

Closes #57665.
2025-10-31 06:09:22 -07:00
Bénédikt Tran 13dc2fde8c gh-70765: avoid waiting for HTTP headers when parsing HTTP/0.9 requests (#139514) 2025-10-05 12:03:25 +00:00
Nick Burns d7dbde8958 gh-92936: allow double quote in cookie values (#113663)
* allow double quote in cookie values
* Update Lib/test/test_http_cookies.py

Co-authored-by: Senthil Kumaran <senthil@python.org>
2025-08-08 12:07:15 -07:00
Alexander Urieles 958657bbc3 gh-131724: Add a new max_response_headers param to HTTP/HTTPSConnection (GH-136814)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-07-20 13:53:54 +00:00
Jeremy Cline 2bd3895fca gh-127319: Disable port reuse on HTTP, XMLRPC, and logging TCP servers (GH-135405)
Prior to issue #120485 these servers did not allow port reuse, which
makes sense as the behavior of port reuse is surprising if you're not
expecting it. It's unclear to me why these services were switched to
allow port reuse, but I believe the desired behavior (unless subclasses
opt in) is to not allow port reuse.

See also: https://bugzilla.redhat.com/show_bug.cgi?id=2323170
2025-06-15 06:34:29 +01:00
ggqlq 2fd09b0110 gh-134168: fix http.server CLI support for IPv6 and --directory when serving over HTTPS (#134169) 2025-05-24 12:19:20 +00:00
ggqlq 605022aeb6 gh-131178: Add tests for http.server command-line interface (#132540) 2025-05-19 12:15:04 +00:00
Serhiy Storchaka 5cbc8c632e gh-133889: Only show the path of the URL in the SimpleHTTPRequestHandler page (GH-134135)
The query and fragment are ambiguous and not used.
2025-05-18 18:09:51 +00:00
Bénédikt Tran faac627e47 gh-133810: remove http.server.CGIHTTPRequestHandler and --cgi flag (#133811)
The CGI HTTP request handler has been deprecated since Python 3.13.
2025-05-17 09:58:16 +02:00
Serhiy Storchaka 2f1ecb3bc4 gh-134098: Fix handling %-encoded trailing slash in SimpleHTTPRequestHandler (GH-134099) 2025-05-17 10:11:34 +03:00
Hugo van Kemenade 4ac916ae33 gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
Serhiy Storchaka 7ebbd27144 gh-130631: Make join_header_words() more similar to the original Perl version (GH-130632)
* Always quote strings with non-ASCII characters.
* Allow some non-separator and non-control characters (like "." or "-")
  be unquoted.
* Always quote strings that end with "\n".
* Use the fullmatch() method for clarity and optimization.
2025-04-09 11:08:04 +03:00
Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) 0a10b45dd1 Docs: Replace dead hyperlink for CGI environment variables (#132137) 2025-04-06 10:12:48 +02:00
Semyon Moroz 37bc3865c8 gh-85162: Add HTTPSServer to http.server to serve files over HTTPS (#129607)
The `http.server` module now supports serving over HTTPS using the `http.server.HTTPSServer` class.
This functionality is also exposed by the command-line interface (`python -m http.server`) through the
`--tls-cert`, `--tls-key` and `--tls-password-file` options.
2025-04-05 08:49:48 +00:00
Petr Viktorin 9e474a98af gh-128982: Revert "#128982: Substitute regular expression in http.cookiejar.join_header_words for an efficient alternative (GH-128983)" and add tests (GH-130584)
* Revert "gh-128982: Substitute regular expression in `http.cookiejar.join_header_words` for an efficient alternative (GH-128983)"

This reverts commit 56e1900681.

* Add tests
2025-02-26 15:42:39 +01:00
Bénédikt Tran 56e1900681 gh-128982: Substitute regular expression in http.cookiejar.join_header_words for an efficient alternative (GH-128983)
The function does not anymore rely on a regular expression
to find alphanumeric characters and underscores.
2025-02-26 13:01:32 +01:00
Samuel GIFFARD 7dd0a7e52e gh-129408: http: Fix typo 'RFF' to RFC' in documentation (#129411) 2025-01-28 13:25:51 -05:00
Yury Manushkin 4d0d24f6e3 gh-112064: Fix incorrect handling of negative read sizes in HTTPResponse.read() (#128270)
The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer,
has not been handled before and led to waiting for the connection to close
for `keep-alive connections`. Now, this has been fixed, and passing negative values
to `HTTPResponse().read()` works the same as passing `None` value.
2025-01-28 11:37:32 +00:00
Giles Copp 9abbb58e3f gh-112713 : Add support for 'partitioned' attribute in http.cookies (GH-112714)
* Add support for 'partitioned' attribute in http.cookies

Co-authored-by: Giles Copp <gilesc@dropbox.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2025-01-24 22:31:52 +00:00
donBarbos 71de839ec9 gh-127089: Add missing description for codes in http.HTTPStatus (#127100)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2024-12-27 15:12:25 +01:00
Moshe Kaplan ea2b53739f Remove incorrect imports rationale comment in http.server (#128278)
Remove reference to gethostbyaddr(), because it's not actually used within this code.
2024-12-26 13:53:37 -08:00
Nano 359389ed51 gh-123401: Fix http.cookies module to support obsolete RFC 850 date format (#123405)
Co-authored-by: Wulian <1055917385@qq.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-11 13:28:19 +00:00
J. Nick Koston dd3c0fa3fd gh-126156: Improve performance of creating Morsel objects (#126157)
Replaces the manually constructed loop with a call to `dict.update`
2024-10-31 12:05:40 -07:00
Yorik Hansen 9684f40b9f gh-123430: Add dark mode support to pages generated by http.server (#123475)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-09-03 09:32:11 +03:00
Serhiy Storchaka 44e458357f gh-123067: Fix quadratic complexity in parsing "-quoted cookie values with backslashes (GH-123075)
This fixes CVE-2024-7592.
2024-08-17 16:30:52 +03:00
Serhiy Storchaka 1a0c7b9ba4 gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
Idan Kapustian 192d17c3fd gh-120485: Add an override of allow_reuse_port on classes subclassing socketserver.TCPServer (GH-120488)
Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
2024-06-16 13:15:03 +01:00
Geoffrey Thomas ef172521a9 Remove almost all unpaired backticks in docstrings (#119231)
As reported in #117847 and #115366, an unpaired backtick in a docstring
tends to confuse e.g. Sphinx running on subclasses of standard library
objects, and the typographic style of using a backtick as an opening
quote is no longer in favor. Convert almost all uses of the form

    The variable `foo' should do xyz

to

    The variable 'foo' should do xyz

and also fix up miscellaneous other unpaired backticks (extraneous /
missing characters).

No functional change is intended here other than in human-readable
docstrings.
2024-05-22 12:35:18 -04:00
Serhiy Storchaka d6fa1d4bee gh-66543: Add mimetypes.guess_file_type() (GH-117258) 2024-05-06 15:50:52 +03:00
Michiel W. Beijen 022ba6d161 gh-102247: http: support rfc9110 status codes (GH-117611)
rfc9110 obsoletes the earlier rfc 7231. This document also includes some
status codes that were previously only used for WebDAV and assigns more
generic names to these status codes.

ref: https://www.rfc-editor.org/rfc/rfc9110.html#name-changes-from-rfc-7231

- http.HTTPStatus.CONTENT_TOO_LARGE (413, previously
  REQUEST_ENTITY_TOO_LARGE)
- http.HTTPStatus.URI_TOO_LONG (414, previously REQUEST_URI_TOO_LONG)
- http.HTTPStatus.RANGE_NOT_SATISFYABLE (416, previously
  REQUEST_RANGE_NOT_SATISFYABLE)
- http.HTTPStatus.UNPROCESSABLE_CONTENT (422, previously
  UNPROCESSABLE_ENTITY)

The new constants are added to http.HTTPStatus and the old constant names are
preserved for backwards compatibility.

References in documentation to the obsoleted rfc 7231 are updated
2024-04-13 07:33:20 -07:00
Derek Higgins 465db27cb9 gh-100985: Consistently wrap IPv6 IP address during CONNECT (GH-100986)
Update _get_hostport to always remove square brackets
from IPv6 addresses. Then add them if needed
in "CONNECT .." and "Host: ".
2024-02-17 10:10:12 +00:00
Illia Volochii 41336a72b9 gh-113199: Make read1() and readline() of HTTPResponse close IO after reading all data (GH-113200) 2023-12-18 22:17:16 +02:00
Michael ce1096f974 gh-73561: Omit interface scope from IPv6 when used as Host header (#93324)
Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
2023-11-19 22:37:13 +00:00
Gregory P. Smith 59073c9ab8 gh-109096: Deprecate http.server.CGIHTTPRequestHandler (#109387)
Deprecate `http.server.CGIHTTPRequestHandler`.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-15 14:26:45 -07:00