Skip to content

fix: remove hardcoded auth token and type-juggling bypass in legacy_auth.php#105

Open
hacktron-app-stg[bot] wants to merge 1 commit into
add-legacy-auth-phpfrom
hacktron/fix-169b8815
Open

fix: remove hardcoded auth token and type-juggling bypass in legacy_auth.php#105
hacktron-app-stg[bot] wants to merge 1 commit into
add-legacy-auth-phpfrom
hacktron/fix-169b8815

Conversation

@hacktron-app-stg

Copy link
Copy Markdown

Vulnerability

legacy_auth.php:8 embedded a hardcoded authentication token ("0e462097431906509019562988736854") and compared the client-supplied token against it with a loose == comparison. Because the stored value is an "0e"-prefixed string, PHP's type juggling treats it as numeric zero, so a request like curl -X POST -d "token=0" .../legacy_auth.php satisfies $_POST['token'] == $stored and sets $_SESSION['auth'] = true, bypassing authentication. The literal also functions as a real, committed credential.

Fix

  • Removed the hardcoded token; the expected value is now read from getenv('LEGACY_AUTH_TOKEN').
  • Replaced the loose == comparison with a strict, constant-time check: is_string(...) guard + hash_equals().
  • Authentication is denied when the token env var is unset or empty.

This addresses the reported hardcoded-secret / type-juggling finding (VULN 1) with a minimal change. The other intentionally-vulnerable demo lines in the file were left untouched as they are outside this finding's scope.

Verification

Reviewed the data flow ($_POST['token'] → loose ==$_SESSION['auth']) to confirm the bypass, then confirmed the new code path can no longer be satisfied by type-juggled input and no longer contains an embedded credential. php -l was unavailable in the sandbox (PHP not installed), so linting could not be run; the edit is a straightforward syntactic replacement.


Automated fix by Hacktron for finding: https://staging.hacktron.ai/testestesttest/findings/169b8815-9ed0-4dd8-900e-99b03b81d881

The hardcoded "0e"-prefixed MD5 token combined with a loose == comparison
allowed a PHP type-juggling authentication bypass (e.g. token=0). Source the
expected token from the environment and compare with a strict type check plus
constant-time hash_equals().
@hacktron-app-stg
hacktron-app-stg Bot requested a review from maekuss July 23, 2026 04:15
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.

0 participants