Repository navigation
Description
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
developand in every released version throughv3.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'smemcmpcompares inputs of this size with wide SIMD loads, leaving nothing to observe before network jitter. Full evidence is in the spec'sreproduction.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
subtlecrate was vetted as untrusted input: already resolved inCargo.lockat the same checksum viasqlx, 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
docs(issues): open specs for #2142 and #2143
chore(issues): archive closed issue specs torrust#2142 and torrust#2143
Merge #2146: chore(issues): archive closed security remediation specs