Skip to content

Reject control characters in HTTP header values - #894

Open
Aschenbath wants to merge 1 commit into
cherrypy:mainfrom
Aschenbath:fix/reject-header-control-characters-720
Open

Aschenbath wants to merge 1 commit into
cherrypy:mainfrom
Aschenbath:fix/reject-header-control-characters-720

Conversation

@Aschenbath

Copy link
Copy Markdown

What kind of change does this PR introduce?

  • 🐞 bug fix
  • 🐣 feature
  • 📋 docs update
  • 📋 tests/coverage improvement
  • 📋 refactoring
  • 💥 other

What do these changes do?

Reject NUL and embedded CR while reading raw header lines, before whitespace trimming can hide them. This applies to ordinary and continuation lines. The existing CRLF check continues to reject bare LF.

Are there changes in behavior for the user?

Requests containing CR, LF or NUL in field values receive 400 Bad Request, as required by RFC 9110 §5.5. Spaces, horizontal tabs and opaque non-ASCII bytes remain accepted.

Is it a substantial burden for the maintainers to support this?

The change adds a local validation check without dependencies. Twelve real-socket cases exercise control characters in the middle and at the edges of values, continuation lines and valid inputs. Eight fail before the fix; all twelve pass afterward.

Validation through tox on Windows/Python 3.12: 211 passed, 11 existing skips, 4 existing expected failures, and two TLS client-auth error-text failures. This TLS failure category also occurs with unmodified server.py. All applicable pre-commit hooks passed; existing tox reporting snippets fail afterward on unescaped Windows paths. No checks were relaxed.

AI assistance: Codex implemented and tested this change locally.

Related issue number

Fixes #720.

Checklist

Tip

New to open source contributions? Making a lovely PR is a great read.

  • I wrote descriptive pull request text above
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences
  • I think the code is well written
  • Unit tests for the changes exist
  • Integration tests for the changes exist (if applicable)
  • I used the same coding conventions as the rest of the project
  • The new code doesn't generate linter offenses
  • Project documentation (in docs/) and inline docstrings reflect the changes
  • My commits each have a descriptive title and a body explaining the why
    (see good commit messages)
  • I have added a change log entry
    (can be done once the PR number is known; alternatively, you can
    use a related issue number if one exists)
  • I'm planning to squash related commits together before final merge
  • I have read the contribution guide and the
    code of conduct

CR, LF and NUL in field values can be interpreted differently by
HTTP recipients. RFC 9110 section 5.5 requires rejecting or replacing
them before processing. Checking before whitespace trimming also
catches carriage returns at the edges of a value.

cherrypy#720

Assisted-by: LLM
@agentscanapp

agentscanapp Bot commented Nov 20, 2026

Copy link
Copy Markdown

Automation signals

Activity patterns show signs of automation.

View full analysis →

Evidence
  • Fork spike: 17 forks within 24 hours
  • High PR volume (weekly): 84 PRs within a single 7-day window, 10 of them to repos it can push to
  • Very high PR volume (daily): 33 PRs within a single 24-hour window
  • Fork branch then PR within seconds: 30 fork branches followed by upstream PRs within 89s, out of 46 branches created in total

Last 5 PRs:

This is an automated analysis by AgentScan

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided A mark meaning that a new change log entry is present within the patch. label Nov 20, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cheroot | 🛠️ Build #36039638 | 📁 Comparing ff061df against latest (e652c2a)

  🔍 Preview build  

5 files changed · + 1 added · ± 4 modified

+ Added

± Modified

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.11%. Comparing base (e652c2a) to head (ff061df).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #894      +/-   ##
==========================================
- Coverage   76.11%   76.11%   -0.01%     
==========================================
  Files          41       42       +1     
  Lines        4932     4957      +25     
  Branches      561      562       +1     
==========================================
+ Hits         3754     3773      +19     
- Misses       1040     1045       +5     
- Partials      138      139       +1     

@webknjaz

Copy link
Copy Markdown
Member

What's your motivation with the contributions in the project? Where did you personally face the behavior you're changing? What are your long term participation plans? Why didn't you attempt participating in earlier contribution efforts that seem to be touching this like #832?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:automation-signals bot:chronographer:provided A mark meaning that a new change log entry is present within the patch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NUL and CR incorrectly permitted within header values

2 participants