Skip to content

Use constant-time comparison for REST API access tokens #2143

Closed

Description

@josecelano

Classification

Low-severity hardening (CWE-208 class). Not a confirmed vulnerability. No CVE, no security advisory.

Summary

The REST API authentication middleware (packages/axum-rest-api-server/src/v1/middlewares/auth.rs) compared the caller-supplied access token against each configured token with plain == inside Iterator::any. Both may exit early, so in principle response timing could reveal how many leading bytes of a guess were correct, turning a brute-force search into a byte-by-byte one. This was reported through the coordinated-disclosure channel by source review; the reporter did not measure a timing difference.

Maintainer assessment

  • Code path confirmed in develop and in every released version through v3.0.0-rc.1.
  • Independent reproduction: negative. A release-build micro-benchmark (2M iterations, 32- and 128-byte tokens, x86-64/glibc) showed no position-dependent timing in plain ==; glibc's memcmp compares inputs of this size with wide SIMD loads, leaving nothing to observe before network jitter. Full evidence is in the spec's reproduction.md.
  • Severity set by maintainers as hardening/low. The reporter's suggested CVSS ~7.4 assumed an observable signal that neither party produced. The finding is nevertheless correct that the comparison had no constant-time contract; the observed safety is a property of the current libc/CPU, not of our code.
  • The suggested subtle crate was vetted as untrusted input: already resolved in Cargo.lock at the same checksum via sqlx, zero dependencies, dalek-cryptography, no advisories. A std-only alternative was rejected as offering weaker guarantees with no footprint benefit.

Change

authenticate now folds subtle::ConstantTimeEq::ct_eq over all configured tokens with bitwise OR and converts to bool once, so for a fixed supplied-token length neither token content nor which configured token matches affects timing. Unit tests added; existing contract tests unchanged and passing.

Out of scope

REST API rate limiting (valid defense-in-depth, to be proposed independently), token-length leakage, and the ?token= query-string authentication path.

Operational note

No user action is required. As always, bind the REST API to a private interface or place it behind a reverse proxy.

Credit

Reported by Abdurazzoqov Javohir (@abdurazzoqovjavohir700-dev). Thank you.

Specification

docs/issues/open/<number>-rest-api-constant-time-token-comparison/ISSUE.md (added by the PR that closes this issue).

Activity

  1. added
    Code Cleanup / Refactoring
    Security
    on Sep 4, 2026
  2. self-assigned this
    on Sep 4, 2026
  3. added a commit that references this issue on Sep 4, 2026
  4. added 2 commits that reference this issue on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Code Cleanup / RefactoringSecurity

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions