security: replace SHA-256 password hashing with PBKDF2#659
Open
mmcintosh wants to merge 2 commits intoSonicJs-Org:mainfrom
Open
security: replace SHA-256 password hashing with PBKDF2#659mmcintosh wants to merge 2 commits intoSonicJs-Org:mainfrom
mmcintosh wants to merge 2 commits intoSonicJs-Org:mainfrom
Conversation
- Use PBKDF2-SHA256 with 600,000 iterations and per-user random salt - Store as pbkdf2:<iterations>:<salt_hex>:<hash_hex> format - Backwards compatible: legacy SHA-256 hashes still verify on login - Transparent migration: re-hash to PBKDF2 on successful login - Constant-time comparison for both PBKDF2 and legacy verification - Update seed-admin.ts to use new PBKDF2 hashing - Update unit tests for new hash format and legacy compatibility Fixes VULN-002
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.
Security: Replace SHA-256 Password Hashing with PBKDF2
Summary
Replaces the insecure SHA-256 password hashing with PBKDF2 (100,000 iterations, random 16-byte salt, constant-time comparison). Existing users are transparently migrated to the new format on their next login -- no downtime or forced password resets required.
Changes
1. PBKDF2 Password Hashing
crypto.subtle.deriveBits)pbkdf2:<iterations>:<salt_hex>:<hash_hex>2. Backward-Compatible Verification
verifyPassword()auto-detects hash format (PBKDF2 vs legacy SHA-256)pbkdf2:prefix) continue to work3. Transparent Hash Migration
/auth/login(API) and/auth/login/form(browser)4. Updated Unit Tests
pbkdf2:100000:...)isLegacyHash()detectionTechnical Details
Core Changes:
packages/core/src/middleware/auth.ts-- PBKDF2hashPassword(), legacyhashPasswordLegacy(), updatedverifyPassword()with format auto-detect and constant-time comparison,isLegacyHash()helperpackages/core/src/routes/auth.ts-- Transparent re-hash on login (both API and form routes)Updated Tests:
packages/core/src/__tests__/middleware/auth.test.ts-- 8 tests covering PBKDF2 format, random salt uniqueness, legacy verification,isLegacyHash()Other:
my-sonicjs-app/scripts/seed-admin.ts-- Updated to use PBKDF2 hashingTesting
Performance Impact
Breaking Changes
None. Fully backward compatible with existing SHA-256 hashes.
Migration Notes
password_hashcolumn is a text field that accepts the new longer format.seed-admin.Known Issues
None.
Demo / Screenshots
N/A -- no UI changes.
Related Issues
(Security hardening -- no linked issue)
Checklist