Skip to content

REST API authentication ignores an unreadable Authorization header #2653

Closed

Description

@josecelano

Goal

Reject an Authorization header whose value is not readable text (not visible ASCII), consistently with other invalid headers, and protect that behavior with a test.

Background

The REST API authentication middleware (packages/axum-rest-api-server/src/v1/middlewares/auth.rs) takes the token from the Authorization: Bearer <token> header or from the token query parameter, and documents that the header wins when both are present. extract_bearer_token_from_header reads the header with to_str().ok(). A value with bytes outside visible ASCII makes to_str() fail, and .ok() turns that into "no header", so the middleware silently falls back to the query parameter.

Observed with a throwaway in-process test (token tok):

Request Result
Unreadable Authorization value and ?token=tok 200, the handler runs
Authorization: Basic tok and ?token=tok, or Authorization: bearer tok 500, unknown token provided

An unreadable header is ignored, while a readable header with another scheme is rejected. This is an inconsistency with the documented contract, not a bypass: the query token must still be valid, and a request without a valid token is rejected in every case observed.

The token query parameter is a legacy authentication method planned for removal in version 2 of the API, because a URL is exposed over plain HTTP and is often written to logs, which makes the token easier to leak. An unreadable header should not fall back to that weaker path.

Decision

Reject: answer unknown token provided, like any other non-Bearer value, and never fall back to the query parameter.

Scope

  • Make extract_bearer_token_from_header reject an unreadable Authorization header with AuthError::UnknownTokenProvided.
  • Add a unit test of the middleware for this behavior.
  • Update the module documentation of auth.rs if the contract text changes.
  • Out of scope: changing the status or body of the failures (500 with the legacy body, kept for backward compatibility).

Acceptance Criteria

  • An unreadable Authorization header is rejected with unknown token provided, even with a valid token query parameter.
  • A unit test protects the behavior and fails for the previous behavior.
  • linter all and the package tests pass.
  • Manual reproduction and a like-for-like recheck on the real tracker are recorded in the issue-local manual-verification-evidence.md.

Found while planning the authentication middleware tests of #2637.

Activity

  1. added
    Bug
    on Oct 26, 2026
  2. added 3 commits that reference this issue on Oct 26, 2026
  3. self-assigned this
    on Oct 26, 2026
  4. added 5 commits that reference this issue on Oct 26, 2026
  5. added 2 commits that reference this issue on Oct 26, 2026
  6. added a commit that references this issue on Oct 26, 2026
  7. added 3 commits that reference this issue on Oct 27, 2026
  8. added 2 commits that reference this issue on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions