fix: use hash_equals for legacy auth token comparison#107
Open
hacktron-app-stg[bot] wants to merge 1 commit into
Open
fix: use hash_equals for legacy auth token comparison#107hacktron-app-stg[bot] wants to merge 1 commit into
hacktron-app-stg[bot] wants to merge 1 commit into
Conversation
Replace the loose `==` comparison of the user-supplied token against a hardcoded "0e"-prefixed hash with hash_equals(), which performs a strict, length-checked, constant-time string comparison. This closes a type-juggling authentication bypass where inputs like "0e0" were coerced to 0 and matched the magic hash. The token is also coerced to a string before comparison.
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.
Vulnerability
legacy_auth.php:9validated the user-suppliedtokenagainst a hardcoded hash using PHP's loose comparison operator (==):The stored hash is "magic-hash" style:
0efollowed by digits only. PHP's==coerces such strings to floats in scientific notation, so"0e462..." == "0e123..."evaluates as0 == 0 => true. An attacker could POSTtoken=0e0(or any0e<digits>value) to bypass authentication and set$_SESSION['auth'] = true.Fix
hash_equals($stored, $token)for validation. It performs a strict, length-checked, constant-time string comparison, eliminating both the type-juggling bypass and a timing side channel.isset/is_stringguard so non-string inputs (e.g.token[]=...) cannot trigger coercion or a TypeError.Verification
$_POST['token']flows directly into the loose comparison sink at line 9. Confirmed the0e-prefixed hash makes the bypass reachable.hash_equalsrequires two strings and compares them byte-for-byte, so"0e0"no longer matches the stored hash.php -l(PHP is not installed in the sandbox), but the change is a minimal, syntactically valid substitution.Scope note: this PR only addresses the type-juggling finding on line 9. Other issues present in the file (extract() variable overwrite, preg_replace /e RCE, assert() RCE) are separate findings and intentionally left untouched.
Automated fix by Hacktron for finding: https://staging.hacktron.ai/testestesttest/findings/1857f818-c47a-4bb7-83ff-95ee0454719e