Repository navigation
fix(id-web): Origin check compares host and port (fixes #814) - #823
Conversation
host_only() stripped the port from both Origin and Host, so http://localhost:9999 passed as same-origin for a UI on localhost:3000. Step 3 of the guard now compares a port-preserving normalised authority (authority_normalized: lower-cased host, explicit port kept, IPv6 re-bracketed). Deliberate no-port rule, documented in the module docs: a port-less authority only matches another port-less authority (no scheme-default-port expansion). The Host allow-list (step 2) still uses host_only() unchanged. Tests: different_port_origin_is_refused, portless_origin_does_not_match_explicit_port_host, ipv6_origin_port_is_compared. cargo test --features web --lib web::security:: = 14 passed / 0 failed; rustfmt clean.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 28 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Fixes #814. The id web UI's Origin check compared only the host of
OriginvsHost—host_only()strips:portfrom both — soOrigin: http://localhost:9999passed as same-origin for a UI served onlocalhost:3000, defeating the CSWSH/CSRF layer for the loopback (token-less) default.Solution
authority_normalized()inpkgs/id/src/web/security.rs: lower-cases the host, keeps an explicit port, re-brackets IPv6 literals.authority_normalized(origin_authority(origin))againstauthority_normalized(Host). Step 2 (Host allow-list) still useshost_only()unchanged.http://localhostdoes not matchlocalhost:3000.Tests
New regression tests:
different_port_origin_is_refused,portless_origin_does_not_match_explicit_port_host,ipv6_origin_port_is_compared(same-port IPv6 passes, different-port refused).Local verification (first-hand):
cargo test --features web --lib web::security::→ 14 passed / 0 failed (11 pre-existing + 3 new);cargo fmt --checkon the file clean. Note: a fresh worktree needs aweb/distplaceholder for the RustEmbed derive to compile locally (gitignored build output) — CI builds the real assets.Acceptance mapping: different-port (incl.
[::1]) → 403 ✓; same-authority any-case passes ✓ (existingsame_origin_is_allowed_cross_origin_is_not+ new IPv6 case);Origin: nullstill refused ✓ (existing test); docs updated ✓.Need help on this PR? Tag
@codesmith-botwith what you need.