Skip to content

gh-142533: Document CRLF injection vulnerability in http.server and wsgiref modules#143395

Merged
vstinner merged 8 commits intopython:mainfrom
tadejmagajna:gh-142533-document-server-header-vulnerability
Apr 2, 2026
Merged

gh-142533: Document CRLF injection vulnerability in http.server and wsgiref modules#143395
vstinner merged 8 commits intopython:mainfrom
tadejmagajna:gh-142533-document-server-header-vulnerability

Conversation

@tadejmagajna
Copy link
Copy Markdown
Contributor

@tadejmagajna tadejmagajna commented Jan 3, 2026

This change documents the CRLF injection vulnerability for http headers in http.server and wsgiref modules.

Initial report in #142533 focused on http.server only, though further discussion suggested also addressing a closely related vulnerability in wsgiref referenced in related issues #55880 and #72964.

After discussing #142605, we pivoted from a direct fix to a documentation update because a fix would disrupt users who rely on using the vulnerability for non-malicious purposes.

The change documents the low-level vulnerability (i.e. absence of checking for CRLF) in mehod-specific sections while describing the high level implications (i.e. assuming sanitized input) under the "Security considerations" section.


📚 Documentation preview 📚: https://cpython-previews--143395.org.readthedocs.build/

@bedevere-app bedevere-app bot added awaiting review docs Documentation in the Doc dir labels Jan 3, 2026
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Jan 3, 2026
@picnixz picnixz self-requested a review January 4, 2026 01:15
@aisk
Copy link
Copy Markdown
Member

aisk commented Jan 4, 2026

Hi, according to the Dev Guide, the document only changes don't need a news entry file.

Comment on lines +290 to +292
This method does not reject input containing CRLF sequences allowing the
possibility of CRLF injection, where a single method call can inject
multiple arbitrary headers.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This method does not reject input containing CRLF sequences allowing the
possibility of CRLF injection, where a single method call can inject
multiple arbitrary headers.
This method does not reject input containing CRLF sequences.

Only mention the possibility of CRLF injection in the security consideration section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. Addressed for both modules

Comment on lines +266 to +268
This method does not reject input containing CRLF sequences allowing the
possibility of CRLF injection, where a single method call can inject
multiple arbitrary headers.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines +900 to +901
Security considerations
-----------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format this the same as we did for Http.server, that is: add a label and enough blank lines.

@tadejmagajna tadejmagajna requested a review from picnixz January 6, 2026 23:12
@tadejmagajna
Copy link
Copy Markdown
Contributor Author

@picnixz thank you for the suggestions. I believe this is addressed now.

vstinner
vstinner previously approved these changes Jan 19, 2026
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner
Copy link
Copy Markdown
Member

cc @SethMichaelLarson @gpshead @serhiy-storchaka: Do you want to double check this change?

@tadejmagajna
Copy link
Copy Markdown
Contributor Author

tadejmagajna commented Mar 10, 2026

Thank you for review approval to both.

The first GitHub profile mentioned in the comment above says in their bio we likely meant @sethmlarson so tagging them here.

@hugovk hugovk added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Mar 11, 2026
@vstinner vstinner dismissed their stale review March 11, 2026 11:44

wsgiref was modified in the meanwhile to reject control characters including newline characters.


Content-Disposition: attachment; filename="bud.gif"

This method does not reject input containing CRLF sequences.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true, please check the update wsgiref code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the vulnerability was addressed while this change was in review. Thank you.

I removed my wsgiref.rst changes, while leaving http.server.rst change in place as it remains relevant.

@tadejmagajna tadejmagajna requested a review from vstinner April 1, 2026 21:22
requests, this makes it possible for files outside of the specified directory
to be served.

The :meth:`BaseHTTPRequestHandler.send_header` method assumes sanitized input
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and send_response_only()

@tadejmagajna tadejmagajna requested a review from vstinner April 2, 2026 19:41
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner merged commit 617f4cc into python:main Apr 2, 2026
30 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Apr 2, 2026
@miss-islington-app
Copy link
Copy Markdown

Thanks @tadejmagajna for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 2, 2026
…er doc (pythonGH-143395)

(cherry picked from commit 617f4cc)

Co-authored-by: Tadej Magajna <tmagajna@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 2, 2026

GH-148020 is a backport of this pull request to the 3.14 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 2, 2026
…er doc (pythonGH-143395)

(cherry picked from commit 617f4cc)

Co-authored-by: Tadej Magajna <tmagajna@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Apr 2, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 2, 2026

GH-148021 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Apr 2, 2026
@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 2, 2026

Since wsgiref was modified recently to reject control characters, I hesitated to propose changing http.server to reject also control characters such as CRLF. But Serhiy is right, http.server users are responsible to pass data encoded for HTTP and so wrap long lines with CRLF: #142533 (comment). So it's better to document the vulnerability rather than fixing it.

http.server has now a long history, it's late to change how data is encoded without breaking existing code.

@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 2, 2026

PR merged, thanks for your contribution. I backported the doc change to 3.13 and 3.14 branches.

vstinner added a commit that referenced this pull request Apr 2, 2026
…ver doc (GH-143395) (#148020)

gh-142533: Document CRLF injection vulnerabilities in http.server doc (GH-143395)
(cherry picked from commit 617f4cc)

Co-authored-by: Tadej Magajna <tmagajna@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Apr 2, 2026
…ver doc (GH-143395) (#148021)

gh-142533: Document CRLF injection vulnerabilities in http.server doc (GH-143395)
(cherry picked from commit 617f4cc)

Co-authored-by: Tadej Magajna <tmagajna@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants