Repository navigation
fix(axum-rest-api-server): [#2653] reject an unreadable Authorization header - #2656
Conversation
…rization header Add a regression test of the auth middleware: an Authorization value that is not visible ASCII together with a valid token query must be rejected with 'unknown token provided'. The test fails on the current code (200 instead of 500); the fix follows in a separate commit. Co-authored-by: Copilot <[email protected]>
…ization header An Authorization value that is not visible ASCII made to_str() fail and .ok() turned the failure into 'no header', so a valid token query authenticated the request. Reject it with 'unknown token provided', like any other invalid header, and document the rule in the module docs. Co-authored-by: Copilot <[email protected]>
… recheck Add the red and green test evidence (R1) and the like-for-like real-tracker recheck (V2) to manual-verification-evidence.md, and mark T3 to T5, the checkpoints and the acceptance criteria done. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The narrow fix implements the agreed behavior, preserves response compatibility, and includes targeted regression coverage with documented verification.
No open issues 🎉
What changed in this PR
Fixes #2653 by making REST API authentication reject unreadable Authorization headers instead of falling back to a valid query token, while preserving legacy error responses.
Changes:
- Distinguishes malformed headers from absent headers and documents the precedence rule.
- Adds a middleware regression test using Tower’s
utilfeature. - Records failing/passing test results and before-and-after real-tracker verification.
| File | Description |
|---|---|
packages/axum-rest-api-server/src/v1/middlewares/auth.rs |
Rejects unreadable headers, documents behavior, and adds regression coverage. |
packages/axum-rest-api-server/Cargo.toml |
Adds Tower test utilities as a development dependency. |
docs/issues/open/2653-rest-api-auth-ignores-unreadable-authorization-header/manual-verification-evidence.md |
Records regression results and the real-tracker recheck. |
docs/issues/open/2653-rest-api-auth-ignores-unreadable-authorization-header/ISSUE.md |
Marks implementation and verification tasks complete. |
Review effort: Balanced
|
ACK a3176f5 |
…ssues/closed 68833b8 chore(issues): archive closed issue #2653 spec to docs/issues/closed (Jose Celano) Pull request description: Archives the spec for issue #2653 (closed on GitHub by #2656) from `docs/issues/open/` to `docs/issues/closed/`. - Verified issue #2653 is `CLOSED` on GitHub - Updated frontmatter (`status: done`, `spec-path`, `last-updated-utc`), the evidence file's `issue-spec` path, the workflow checkpoint and the progress log - Searched for the old path: no live reference remains - Pre-commit hooks passed ACKs for top commit: josecelano: ACK 68833b8 Tree-SHA512: 6b6b37047afa27c9237d62861d0a6bf07833ab02b2fd202cc9d811dc9db52990284b935d5c4623b60fa2a3cd998fedcee868ba9fae6e1f4d21ddbb43bd45a593
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at a3176f5bc4e1c9e8695a27c7dc79705a9c297256 (post-merge). Recomputed from the bytes at the merged head, against the base 3b781c628; the PR merged on 2026-10-26 at 16:50:48Z as 945d482d3.
Label: POST_MERGE_FINDINGS — Review requested at 2026-10-26 15:41:48Z. The PR merged before this round ran; any findings below stand at the merged head for a follow-up, and no ACK follows a merged PR.
Change and tests: traced all extractor branches before and after. Absent headers still permit query authentication; exact Bearer yields an empty token; Bearer strips only that prefix; other readable schemes still reject. The changed to_str() error returns UnknownTokenProvided before the query fallback. The existing response mapping produces 500 and the literal legacy rejection body. The new router test supplies both causal inputs and asserts status and body; restoring the old extractor would return the handler's 200, failing the assertion. No socket, timer or external dependency is involved. Module documentation matches the changed precedence rule.
Claims and records: three commits, four files, +178/-44 recomputed. The test commit precedes the fix; the evidence commit follows both. R1 names those states and its red line matches the test commit. V2 identifies the last production-change subject and records the two expected response changes; the other five probes agree with the unchanged branches. These are internally consistent recorded observations, not independently rerun measurements. The spec completion ticks for implementation are supported by the diff; historical execution claims cannot be established from source alone. No archive or new audit record is added. Changed Markdown has no relative Markdown links. Metadata timestamps precede the carrying commit.
Hygiene: all three subjects use the package or issues scope and issue tag; bodies match their diffs, author and committer identities match, and diff whitespace checks are clean. Attribution footer lines are present; no prohibition was found in the applicable commit rules. The closing-pattern scan finds only the intended issue 2653 in the description. New vocabulary was compared with the project dictionary; spelling execution remains downstream.
The review bot: review 5652907639 has no actionable finding or inline thread. Its narrow correctness assessment agrees with the branch analysis above. This implements the decision delivered by PR #2654; PR #2667 subsequently broadens the middleware tests without changing this decision.
Findings: none.
Checked, no finding: unreadable-header rejection, query precedence, unchanged readable-header parsing, legacy error response, regression sensitivity, dependency use, commit sequence and closure target. No build or runtime verification was performed in this read-only lane.
Checks
On the loop's compute hub at the merged head, against the base 3b781c628 (receipt server-gates-sojka-474; the PR merged as 945d482d3): pre-commit profile gate exit 0 (97 s); linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 16 errors / 4 warnings at the merged head and 16 / 4 at the base re-measured, the same 20 diagnostics by path and category; cargo test at the merged head: torrust-tracker-axum-rest-api-server 73 passed, 0 failed (exit 0, 52 s; 72 at the base); cargo clippy over torrust-tracker-axum-rest-api-server with all targets and features and -D warnings: exit 0, 0 diagnostics. GitHub checks at this head at posting time: "Publish (Development): completed/skipped; Publish (Release): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Package Coverage (torrust-tracker-axum-rest-api-server): completed/success; Docker E2E: completed/skipped; Workspace Packaging: completed/success; Documented Clippy Allows: completed/success; Unit (nightly): completed/success; Layer Boundary Bans: completed/success; Unit (stable): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on ubuntu-latest (stable): completed/success; Build on windows-latest (nightly): completed/success; Build on windows-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Build on macos-latest (stable): completed/success; Test (Docker) (release): completed/success; Generate Coverage Report: completed/success; Discover Package Coverage: completed/success; Docs Lint: completed/success". At posting, develop is 968099d93.
Summary
Fixes #2653: the REST API authentication middleware treated an
Authorizationheader that is not readable text (not visible ASCII) as absent, so a validtokenquery parameter then authenticated the request, while other invalid headers (Basic x,bearer <token>) were rejected withunknown token provided.The maintainer decided to reject such a header like any other invalid one. The
tokenquery parameter is a legacy method planned for removal in version 2 of the API, and a garbled header should not fall back to it. The response status and body of the failures are unchanged.Closes #2653.
Changes
test(axum-rest-api-server): [#2653] reject an unreadable Authorization header: a regression test of theauthmiddleware through a minimal router. It fails on the previous code (200instead of500) and addstowerwith theutilfeature as a dev-dependency.fix(axum-rest-api-server): [#2653] reject an unreadable Authorization header:extract_bearer_token_from_headerreturnsunknown token providedwhento_str()fails, and the module documentation states the rule.docs(issues): [#2653] record the regression test and the final recheck: the red and green test evidence and the real-tracker recheck in the issue-local evidence file.Verification
curlprobes before and after the fix. Before: the unreadable header with a valid?tokenanswered200. After:500 unknown token provided, and the unreadable header alone changed fromunauthorizedtounknown token provided. The other probes are unchanged. Details are inmanual-verification-evidence.md(V1 and V2).cargo test -p torrust-tracker-axum-rest-api-server: all tests pass.linter alland./contrib/dev-tools/git/hooks/pre-push.shpass.