Take the API token from the header and nowhere else - #732
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
RestApiRequeststates that the auth token comes from theAuthorizationheader, and it does — when one is there. With no header, or one that is not aBearer, nothing was assigned, so anauthTokenthe 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,
Bearerwith nothing after it, and a bare token without the scheme — each with a forgedauthTokenin the query string. All four fail against the old code withFailed asserting that 'forged-token' is null.Unit suite green: 3085. API integration tests: 227 green. PHPStan and PHPCS clean.