Skip to content

Take the API token from the header and nowhere else - #732

Merged
blaipr merged 1 commit into
mainfrom
fix/api-token-header-only
Aug 13, 2026
Merged

Take the API token from the header and nowhere else#732
blaipr merged 1 commit into
mainfrom
fix/api-token-header-only

Conversation

@blaipr

@blaipr blaipr commented Aug 13, 2026

Copy link
Copy Markdown
Member

The bug

RestApiRequest states that the auth token comes from the Authorization header, and it does — when one is there. With no header, or one that is not a Bearer, nothing was assigned, so an authToken the caller had put in the query string or the body stayed in the parameter bag and was handed on as the token.

Nothing was exploitable through it: the value still had to match a stored token to be worth anything. The guarantee simply was not one.

The fix

Drop the parameter instead of leaving it, so a token that did not come from the header is absent rather than merely unusable. exists('authToken') answers no — which is what the two existing tests on that already asked for, and which is the difference that matters to a naive check.

Testing

A data-provided test covering the four ways a header can fail to supply one — absent, another scheme, Bearer with nothing after it, and a bare token without the scheme — each with a forged authToken in the query string. All four fail against the old code with Failed asserting that 'forged-token' is null.

Unit suite green: 3085. API integration tests: 227 green. PHPStan and PHPCS clean.

The class says the auth token comes from the Authorization header. It did when
one was there — but with no header, or one that is not a Bearer, nothing was
assigned, so an authToken the caller had put in the query string or the body
stayed in the parameter bag and was handed on as the token.

Nothing was exploitable through it: the value still had to match a stored token.
The guarantee simply was not one.

Drop it instead of leaving it, so a token that did not come from the header is
absent rather than merely unusable — exists() answers no, which is what the two
tests on that already asked for.
@blaipr
blaipr merged commit fc9fcee into main Aug 13, 2026
8 checks passed
@blaipr
blaipr deleted the fix/api-token-header-only branch August 13, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant