Skip to content

fix(hosting): match uvicorn's strict CIDR parsing for trusted proxies - #1150

Merged
antosubash merged 2 commits into
mainfrom
claude/project-thread-lg6bda
Nov 29, 2026
Merged

antosubash merged 2 commits into
mainfrom
claude/project-thread-lg6bda

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Requested by Anto · project thread

Summary

Split 1 of 3 from #1137, independent of the other two.

TrustedPeers (used by ForwardedHostMiddleware) parsed trusted_proxy entries with strict=False, so 10.0.0.5/24 trusted all of 10.0.0.0/24. uvicorn's ProxyHeadersMiddleware parses the same entry strictly and treats it as a literal that matches nothing, which meant ForwardedHost could trust peers that ProxyHeaders did not.

  • Parse strictly, like uvicorn.
  • Behaviour change: such an entry now trusts no peer for ForwardedHost too, and a WARNING naming the intended network (did you mean 10.0.0.0/24?) is logged when the middleware is built, so the entry no longer fails silently. ProxyHeaders behaviour is unchanged (it was already strict).
  • CHANGELOG (Security), docs/framework/middleware.md and docs/reference/env-vars.md updated.

Test plan

  • New TestPeers::test_cidr_with_host_bits_set_trusts_no_peer (asserts no trust plus the warning)
  • framework/hosting/tests pass, except 3 frontend typecheck tests that also fail on main in this sandbox (no npm install)
  • ruff format/check, ty, file-size
  • CI green

Generated by Claude Code

TrustedPeers parsed trusted_proxy entries with strict=False, so a CIDR
with host bits set (10.0.0.5/24) trusted the whole /24 in
ForwardedHostMiddleware while uvicorn's ProxyHeadersMiddleware treated
the same entry as a literal that matches nothing. ForwardedHost could
therefore trust peers ProxyHeaders did not.

Parse strictly, like uvicorn, and log a WARNING naming the intended
network so the now-inert entry does not fail silently.

Split out of #1137.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw
@antosubash antosubash self-assigned this Nov 25, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8f3c7d9
Status: ✅  Deploy successful!
Preview URL: https://ece6a93c.simple-module-python.pages.dev
Branch Preview URL: https://claude-project-thread-lg6bda.simple-module-python.pages.dev

View logs

@antosubash
antosubash marked this pull request as ready for review November 29, 2026 08:23
@antosubash antosubash added the shipped /ship passed on the head commit label Nov 29, 2026
@antosubash

Copy link
Copy Markdown
Owner Author

/ship passed on 8f3c7d9

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-29T08:28:55.845500Z 8f3c7d9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@antosubash
antosubash merged commit 9eefa46 into main Nov 29, 2026
18 checks passed
@antosubash
antosubash deleted the claude/project-thread-lg6bda branch November 29, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shipped /ship passed on the head commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants