Skip to content

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

Merged
vstinner merged 8 commits into
python: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 into
python:mainfrom
tadejmagajna:gh-142533-document-server-header-vulnerability

Conversation

@tadejmagajna

@tadejmagajnatadejmagajna commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

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/

@aisk

aisk commented Jan 4, 2026

Copy link
Copy Markdown
Member

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

Comment threadDoc/library/http.server.rst Outdated
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
ContributorAuthor

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 threadDoc/library/wsgiref.rst Outdated
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 threadDoc/library/wsgiref.rst Outdated
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

Copy link
Copy Markdown
ContributorAuthor

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

vstinner
vstinner previously approved these changes Jan 19, 2026

@vstinnervstinner left a comment

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.

LGTM

@vstinner

Copy link
Copy Markdown
Member

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

@tadejmagajna

tadejmagajna commented Mar 10, 2026

Copy link
Copy Markdown
ContributorAuthor

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.

@hugovkhugovk 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 reviewMarch 11, 2026 11:44

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

Comment threadDoc/library/wsgiref.rst Outdated

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
ContributorAuthor

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.

Comment threadDoc/library/http.server.rst Outdated
Comment threadDoc/library/http.server.rst
Comment threadDoc/library/http.server.rst Outdated
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()

@vstinnervstinner left a comment

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.

LGTM

@vstinner
vstinner merged commit 617f4cc into python:mainApr 2, 2026
30 checks passed
@github-project-automationgithub-project-automationBot moved this from Todo to Done in Docs PRsApr 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

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-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Apr 2, 2026
@bedevere-app

Copy link
Copy Markdown

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

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Apr 2, 2026
@vstinner

Copy link
Copy Markdown
Member

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

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>
@tadejmagajna
tadejmagajna deleted the gh-142533-document-server-header-vulnerability branch April 22, 2026 21:14
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
…er doc (python#143395)
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docsDocumentation in the Doc dirskip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@tadejmagajna@aisk@vstinner@picnixz@hugovk