Fix Security Vulnerability: Hash Notification Management Tokens with Bcrypt#8283
Fix Security Vulnerability: Hash Notification Management Tokens with Bcrypt#8283atul-upadhyay-7 wants to merge 1 commit into
Conversation
…vent offline brute-force (fixes JhaSourav07#8281)
|
@atul-upadhyay-7 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
This pull request addresses a critical security vulnerability by improving how notification management tokens are hashed. By switching from SHA-256 to bcrypt, it effectively mitigates risks associated with offline brute-force attacks. This change aligns with our previous decisions to enhance security, such as preventing raw internal error leakage and ensuring accurate data handling. Thank you for your contribution to improving our application's security! |
|
🚨 Hey @atul-upadhyay-7, the CI Pipeline is failing on this PR and it has been marked as Please fix the issues before this can be reviewed. Here's how: 1. Run checks locally before pushing: npm run format:check # Check Prettier formatting
npm run lint # Run ESLint
npm run typecheck # TypeScript type check
npm run test # Run unit tests (Vitest)
npm run build # Verify production build passes2. Auto-fix common issues: npm run format # Auto-fix formatting with Prettier
npm run lint -- --fix # Auto-fix lint errors where possible3. Check the full failure log here: Once you push a fix and the CI passes, the |
Aamod007
left a comment
There was a problem hiding this comment.
This PR is currently blocked because of failing CI checks. By changing the hashing mechanism to \�crypt\ (\lib/notification-management-token.ts), the generated hashes are no longer deterministic (since \�crypt\ automatically generates a random salt) and they do not output a 64-character hex string. This breaks our existing test assertions in \lib/notification-management-token.test.ts.
How to fix:
Please update the test assertions to remove the ^[a-f0-9]{64}$\ regex check, and remove the determinism test (
eturns a deterministic hash for the same input). Also, since bcrypt hashes are non-deterministic, you will need to update the token verification logic (wherever this hash is compared) to use \�crypt.compareSync()\ instead of simple string equality.
I am requesting changes until the CI is green.
Label Justification:
- \level:advanced: 3 files changed (including package dependencies).
- \ ype:security: Upgrades token hashing to bcrypt.
- \mentor:Aamod007: Assigned as required.
Description
Fixes #8281
The
/api/notifyroute was hashing notification management tokens using plain SHA-256 without a per-record salt. Because the token space is limited, this allowed an attacker with read access to the database (e.g., via backup leak or unrelated injection flaw) to recover tokens offline via brute-force or rainbow tables, and subsequently silently hijack user notification settings.This PR:
crypto.createHash('sha256')implementation withbcryptjsusing a work factor of 12.notificationscollection.Pillar
Visual Preview
N/A - Security backend change only.
Checklist before requesting a review:
CONTRIBUTING.mdfile.localhost:3000/api/streak?user=YOUR_USERNAME).npm run formatandnpm run lintlocally and resolved all errors (CI will fail otherwise).feat(themes): ...,fix(calculate): ...).README.mdif I added a new theme or URL parameter.