fix(auth): trim CHAR-padded password_algo and password_salt#970
Open
AH-dark wants to merge 1 commit into
Open
Conversation
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
v2_user.password_algoandv2_user.password_saltare declared asCHAR(10).MySQL right-pads
CHARvalues with spaces on insert. The switch inHelper::multiPasswordVerifyuses strict equality:So a legacy v2board user whose
password_algois stored as'sha256 '(6 chars + 4 trailing spaces) NEVER matches
'sha256', falls through to thedefault:branch (password_verify), and can never log in. The saltedvariants are doubly broken because the padded salt corrupts the hash
recomputation.
Affected algorithms:
md5(3 chars),sha256(6 chars),md5salt(7 chars).sha256salt(10 chars) accidentally works because it exactly fills the column.Fix
VARCHAR(10)and runs anidempotent raw-SQL
TRIM()backfill for any existing space-padded rows.Helper::multiPasswordVerifynow defensively trims and null-coalesces$algoand$saltbefore the switch, and useshash_equals()fortiming-safe hex comparison.
HelperPasswordVerifyTestcovers all 5 verificationbranches plus padded / null / whitespace edge cases.
LoginServiceTestgains two integration cases that seedlegacy-padded rows and prove login succeeds end-to-end.
Helper signature is unchanged — fully backward compatible.
Migration
down()caveatRolling back to
CHAR(10)reintroduces the bug functionally. The downmethod is provided for completeness but is documented as a "do not run in
production without a follow-up data migration" path.
Verification
php artisan test— full suite green (SQLite default).varchar(10), padded rows trimmed.migrateis a no-op.