Files
alkhttp/tasks/server/review-002-srv11-srv12-router-ordering.md
T

3.5 KiB

id, name, status, depends_on, scope, risk, impact, level, tags
id name status depends_on scope risk impact level tags
review-002-srv11-srv12-router-ordering Router-layering fixes — double token resolution on WS and mcp, decoy 405 on extra routes (SRV-11, SRV-12) completed
narrow medium component implementation
server
review-002
stealth

Description

Two review-002 findings in server/adapter.rs's build_router — both are axum route_layer/merge-ordering semantics (empirically verified in review 002 with an axum 0.8.9 harness; route_layer wraps routes registered before the call):

  • SRV-11: the router-wide bearer_auth_middleware layer (:328) wraps the WS route (registered earlier at :307-317 with its own ws_bearer_auth) and the /mcp nest (own layer at :288-292) — the token resolves twice on both, and the code comment claims the opposite ("resolves the token exactly once"). Benign today (ag stashes agree), but a provider with token-use side effects double-counts.
  • SRV-12: method_not_allowed_fallback(decoy_method_not_allowed) (:322) covers only routers registered before the extras merge — wrong-method probes on extra routes return axum's bare 405 (no body, no Server: nginx), the exact stealth probe SRV-07's fix neutralized for the default surface.

Acceptance Criteria

  • SRV-11: the WS route resolves the token exactly once (drop the router-wide layer's application to it — e.g. verify with an axum-semantics-confirmed mechanism: register the WS route after the route_layer call, or exclude via per-route wrapping) and /mcp likewise (keep exactly one auth layer for it); the corrected comment states axum's actual route_layer semantics
  • SRV-11 test: a counting IdentityProvider — one WS upgrade request resolves the token exactly once (and one /mcp request likewise, feature-gated)
  • SRV-12: method_not_allowed_fallback(decoy_method_not_allowed) re-applied after the extras merge; test: wrong-method probe on an extra route carries the decoy body + Server: nginx header
  • Re-verify the existing router tests (extra-routes auth, decoy 405 default-surface, reserved-path panics) still pass — the merge-order changes must not regress SRV-01's guarantee
  • cargo test, cargo clippy --all-targets -- -D warnings, cargo fmt --check pass

References

  • docs/reviews/002-post-remediation-review.md (Part A', SRV-11, SRV-12; hot-spot 2 in the server pass)
  • src/server/adapter.rs:274-345 (build_router), :296-320 (comment + WS route), :322 (405 fallback), :328 (router-wide layer)
  • tasks/server/review-001-extra-routes-auth.md (the SRV-01 ordering this must preserve), tasks/server/review-001-hyper-server-knobs.md (SRV-07's decoy-405 work)

Notes

Order-sensitivity warning (from the server pass): "any future route addition must re-derive these semantics empirically" — after fixing, add the counting test + the extra-route 405 test so the invariants are pinned, not just commented. The SRV-01 opt-out shape (inner layers win) must remain exactly as tested. Keep the SRV-10 fold-in fix (historical) intact — this task is about the comment being false and the double-resolve being real.

Summary

WS upgrade route + /mcp nest moved after the router-wide bearer route_layer (single token resolution each; WS MethodRouter fallback carries the decoy 405); method_not_allowed_fallback re-applied after the extras merge (SRV-12). 6 counting/shape tests pin the ordering invariants.