Fixed #181 -- Improved Host validation for malformed colon values. - #182
Conversation
Greptile SummaryThis PR tightens Host header validation for malformed authority values. The main changes are:
|
| Filename | Overview |
|---|---|
| src/quater/security.py | Updates host normalization to reject malformed ports and bare IPv6 request authorities before allowed-host matching, while preserving configured bare IPv6 allow-list support. |
| tests/unit/test_allowed_hosts.py | Adds unit coverage for malformed unbracketed hosts, bracketed IPv6 ports, bare IPv6 authorities, wildcard behavior, and malformed allowed-host patterns. |
| tests/integration/test_cross_transport_behavior.py | Adds cross-transport assertions that malformed Host syntax is rejected consistently across ASGI, WSGI, and RSGI before handlers run. |
| docs/en/dev/changelog.md | Documents the host validation fix and examples of rejected malformed authorities and accepted bracketed IPv6 forms. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant C as Client
participant Ad as ASGI/WSGI/RSGI Adapter
participant Sec as security.py
participant Auth as Auth
participant H as Handler
C->>Ad: Request with Host / :authority
Ad->>Sec: prepare_request_security(request, config)
Sec->>Sec: _validate_singleton_request_headers()
Sec->>Sec: _normalize_host(host / authority)
alt malformed authority or disallowed host
Sec-->>Ad: 400 Invalid Host header
else valid normalized host
Sec->>Sec: _validate_allowed_host()
Sec->>Auth: continue to authentication
Auth->>H: invoke route handler
H-->>Ad: response
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant C as Client
participant Ad as ASGI/WSGI/RSGI Adapter
participant Sec as security.py
participant Auth as Auth
participant H as Handler
C->>Ad: Request with Host / :authority
Ad->>Sec: prepare_request_security(request, config)
Sec->>Sec: _validate_singleton_request_headers()
Sec->>Sec: _normalize_host(host / authority)
alt malformed authority or disallowed host
Sec-->>Ad: 400 Invalid Host header
else valid normalized host
Sec->>Sec: _validate_allowed_host()
Sec->>Auth: continue to authentication
Auth->>H: invoke route handler
H-->>Ad: response
end
Reviews (2): Last reviewed commit: "Fixed #181 -- Improved Host validation f..." | Re-trigger Greptile
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
==========================================
+ Coverage 92.63% 92.82% +0.18%
==========================================
Files 66 66
Lines 6546 6565 +19
Branches 1113 1116 +3
==========================================
+ Hits 6064 6094 +30
+ Misses 291 286 -5
+ Partials 191 185 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Host header validation now rejects malformed authority values before auth or handlers run. Bad ports such as
localhost:badand bare IPv6 values such as::1now return400 Invalid Host header, even whenallowed_hosts=["*"]; valid bracketed IPv6 hosts such as[::1]and[::1]:8000still work.Linked Issue
Fixes #181
Contributor Checklist
acceptedbefore I started.issue_{issue_number}.Checks Run