Use strict comparisons throughout _checkNonce() validation#596
Open
flightlesstux wants to merge 1 commit intopassbolt:masterfrom
Open
Use strict comparisons throughout _checkNonce() validation#596flightlesstux wants to merge 1 commit intopassbolt:masterfrom
flightlesstux wants to merge 1 commit intopassbolt:masterfrom
Conversation
_checkNonce() validated GPG nonce format using loose != comparisons throughout. All values originate from explode() so they are strings; loose integer/string coercion was doing the right thing in practice, but PHP's type juggling rules make loose comparisons a maintenance hazard — a future refactor could silently change the semantics. Changes: - count($result) != 4 → !== 4 - $version != $version2 → !== - $version != 'gpgauthv1.3.0' → !== - $version != Validation::uuid($uuid) → !Validation::uuid($uuid) (Validation::uuid returns bool; comparing against $version was semantically wrong — it happened to work via coercion only) - $length != 36 → !== '36' ($length is a string from explode; strict compare requires '36')
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
GpgAuthenticator::_checkNonce()validates the GPG nonce format using loose!=comparisons at every check. All values come fromexplode('|', $nonce)and are therefore strings, so loose coercion happens to produce correct results today — but PHP's type juggling rules make this fragile.The UUID check is additionally wrong at the operand level:
Validation::uuid()returnstrue/false. The comparison works only because'gpgauthv1.3.0' == trueand'gpgauthv1.3.0' != falsehappen to be correct under loose coercion. This is an accident of PHP semantics, not intentional logic.Fix
Replace every loose
!=with strict!==, and fix the UUID check to test the validation result directly:Notes
$lengthis a string fromexplode(), so the strict comparison target changes from integer36to string'36'. The validation behaviour is identical.