509 Commits
Author SHA1 Message Date
Gregory P. Smith d59d96853b gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301)
DefaultCookiePolicy only applied its domain checks to cookies with
version 0 or a positive version.

ANT-2026-TA36I7V7
2026-10-25 07:01:05 +00:00
blago1 9f52b443c0 gh-150751: Ignore optional whitespace around Content-Length in http.client (GH-159156)
gh-150752 started validating the Content-Length value against the
RFC 9112 grammar (1*DIGIT), but the compat32 header parser keeps
trailing SP/HTAB in the field value, so "Content-Length: 5 " is now
treated as a missing header. HTTPResponse then assumes that the
connection will close and read() blocks until the server closes it,
which never happens on a keep-alive connection.

RFC 9112, section 5.1 says that optional whitespace around a field
value is excluded by parsers. Strip SP/HTAB before the grammar check;
values such as "+5", "5_0" and "5 0" are still rejected.
2026-10-14 14:50:35 +02:00
João Gabriel Pieroli da SilvaandLorenaMBorges 8138bf11a5 gh-159044: Restore string conversion for HTTP tunnel header values (GH-159216)
Co-authored-by: LorenaMBorges <lborgescomp@gmail.com>
2026-10-13 19:24:45 -04:00
metsw24-max 2eb2af805c gh-150751: validate http.client Content-Length and chunk-size (GH-150752)
RFC 9112 defines Content-Length as 1*DIGIT and chunk-size as 1*HEXDIG, but int() also accepts a sign, underscores, surrounding whitespace and an 0x prefix, so malformed framing values were parsed instead of rejected.
2026-10-08 14:40:51 +02:00
Victor Stinner 1855c6c40b gh-155358: Use named attributes with urllib.parse module (#155364)
urlparse(), replace:

* parts[0] => parts.scheme
* parts[1] => parts.netloc
* parts[2] => parts.path

urlsplit(), replace:

* parts[0] => parts.scheme
* parts[1] => parts.netloc
* parts[2] => parts.path
2026-08-31 18:03:33 +00:00
Serhiy Storchaka a4a5a06767 gh-61366: Write session cookies in the curl and Wget format (GH-155602)
Write 0 in the expiration time field for session cookies.
curl and Wget ignore the line if this field is empty.
2026-08-12 09:29:19 +00:00
e37cf4955e gh-61366: Read session cookies written by curl and Wget (GH-11792)
Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-08-12 07:33:04 +00:00
1cf7d89828 gh-82039: Relax cookiejar.py case-sensitive regex for the inconsequential first line of the cookie file (GH-15673)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-08-11 17:01:52 +00:00
Victor Stinner 2e519ddf41 gh-155358: Use named attributes with os module (#155366)
Replace os.stat() result:

* st[1] => st.st_ino
* st[6] => st.st_size
* st[ST_MTIME] => st_mtime: change int type to float
2026-08-10 20:31:53 +02:00
Victor Stinner f8cfa0cd59 gh-155358: Use named attributes with pwd and grp modules (#155362)
* Replace pwd[0] with pwd.pw_name
* Replace pwd[2] with pwd.pw_uid
* Replace grp[0] with grp.gr_name
* Replace grp[2] with grp.gr_gid
* Replace pwd[3] with pwd.pw_gid
2026-08-10 20:30:40 +02:00
Serhiy StorchakaandClaude Fable 5 2ab620b41a gh-54930: Send a status line in error responses to malformed request lines (GH-152980)
Previously such error responses were sent in the bare HTTP/0.9 style,
without a status line and headers.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 13:48:23 +03:00
Gregory P. Smith 41cc78a7a4 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.

---

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.
2026-06-28 12:06:41 -07:00
Seth Larson 461b1d9631 gh-149144: Use decodeURIComponent() for UTF-8 support in js_output() (GH-149157) 2026-05-14 23:10:39 +02:00
Hugo van KemenadeandSavannah Ostrowski 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
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
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 Duandblurb-it[bot] 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 LarsonandIllia Volochii 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 KemenadeandBrian Schubert 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
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
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 KemenadeandStan Ulbrych 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 BurnsandSenthil Kumaran 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
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
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
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
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