Skip to content

fix: replace SHA-256 with PBKDF2 for password hashing in auth template - #767

Merged
kojiwakayama merged 2 commits into
mainfrom
fix/auth-template-password-hashing
Mar 27, 2026
Merged

fix: replace SHA-256 with PBKDF2 for password hashing in auth template#767
kojiwakayama merged 2 commits into
mainfrom
fix/auth-template-password-hashing

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Summary

  • Replaces raw SHA-256 (unsalted, no cost factor) with PBKDF2-SHA256 (100k iterations, random salt) in the auth template
  • Uses only Web Crypto APIs — no external dependencies
  • Updates demo user hash in db.ts to match new format
  • Stores salt alongside hash in salt:hash format

This was the real security issue behind Aikido PR #756 (which was closed because its timing-safe comparison fix introduced an import shadowing bug). SHA-256 is unsuitable for password hashing — brute-forceable at billions/sec on commodity hardware.

Test plan

  • Scaffold auth feature with veryfront generate feature auth
  • Verify login works with demo credentials (email: user@example.com, password: password)
  • Verify password hashing produces different output each time (random salt)
  • Verify verification succeeds with correct password and fails with wrong password

The auth template used raw SHA-256 for password hashing with no salt and
no cost factor, making stored passwords trivially reversible via rainbow
tables. Password verification also used direct string comparison (===),
which is vulnerable to timing attacks.

Replace with PBKDF2-SHA256 (100k iterations, 16-byte random salt) using
the Web Crypto API — no external dependencies needed. Passwords are now
stored in "salt:hash" hex format. Verification uses constant-time byte
comparison to prevent timing side-channel attacks.

Addresses the real security issue behind PR #756 (Aikido review).
@kojiwakayama
kojiwakayama merged commit 59c0aad into main Mar 27, 2026
14 of 15 checks passed
@kojiwakayama
kojiwakayama deleted the fix/auth-template-password-hashing branch March 27, 2026 11:26
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.

1 participant