Check authorization before input validation#173
Open
otazniksk wants to merge 1 commit intotomaj:masterfrom
Open
Check authorization before input validation#173otazniksk wants to merge 1 commit intotomaj:masterfrom
otazniksk wants to merge 1 commit intotomaj:masterfrom
Conversation
Moves checkAuth() call before ParamsProcessor in ApiPresenter::run() to prevent unauthenticated clients from probing API validation rules. Previously, requests with missing/invalid auth would return "400 wrong input" when the body was also invalid, leaking information about required fields and validation rules to unauthenticated callers. Per OWASP ASVS V4.1.1, authorization must be enforced before request processing. Trade-off: error handlers (handleAuthorization, handleAuthorizationException) now receive an empty params array on auth failure. Debugging context is lost on failed auth, but authorization itself does not use params (ApiAuthorizationInterface::authorized() takes no arguments), so the security behavior is unchanged.
Author
|
The failing PHPStan checks are pre-existing errors in They reproduce on clean Happy to open a separate PR to fix them if you'd like. |
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.
Problem
In
ApiPresenter::run(), input parameter validation is executed before authorization check:https://github.com/tomaj/nette-api/blob/3.4.0/src/Presenters/ApiPresenter.php#L87-L99
This is a regression from v2.x where auth was checked first:
https://github.com/tomaj/nette-api/blob/2.13.0/src/Presenters/ApiPresenter.php#L73-L83
Security impact
An unauthenticated client can probe API validation rules without providing a valid token. Requests with missing/invalid auth + invalid body return
400 wrong inputinstead of401, leaking information about:Per OWASP ASVS 4.0.3 (V4.1.1 Access Control), authorization must be enforced before request processing.
Suggested fix
Move
checkAuth()beforeParamsProcessorinApiPresenter::run().Version
tomaj/nette-api3.4.0