-
-
Notifications
You must be signed in to change notification settings - Fork 23.6k
Increase salt rounds for new passwords, and update hash with more salt rounds for old passwords #5665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Today, the application defaults to 5 salt rounds, increasing to 10 which is suggested by OWASP.
Summary of ChangesHello @christopherholland-workday, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the security posture of user authentication by upgrading the password hashing strategy. It increases the computational cost for new password hashes and introduces a seamless, on-login upgrade process for older, less secure hashes. This proactive approach ensures that all user credentials eventually meet a higher standard of cryptographic strength, making the system more resilient against brute-force and dictionary attacks. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a great security improvement. It increases the bcrypt salt rounds to the recommended value of 10 and implements a seamless upgrade path for existing users' passwords upon login. The changes are well-structured, introducing utility functions for checking and upgrading hashes. I have a few suggestions to reduce code duplication and improve maintainability, primarily around centralizing the logic for determining salt rounds and using the new getHash utility consistently.
| const salt = bcrypt.genSaltSync(parseInt(process.env.PASSWORD_SALT_HASH_ROUNDS || '10')) | ||
| // @ts-ignore | ||
| const hash = bcrypt.hashSync(data.user.password, salt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This manual password hashing logic is a duplicate of what the getHash function in encryption.util.ts provides. To improve maintainability and ensure hashing is done consistently across the application, you should use the getHash function here.
| const salt = bcrypt.genSaltSync(parseInt(process.env.PASSWORD_SALT_HASH_ROUNDS || '10')) | |
| // @ts-ignore | |
| const hash = bcrypt.hashSync(data.user.password, salt) | |
| // Replaced manual hashing with a call to the centralized getHash function. | |
| // @ts-ignore | |
| const hash = getHash(data.user.password); |
|
|
||
| // If the stored hash was created with fewer salt rounds than the current minimum | ||
| // (e.g. 5 before we increased to 10), rehash with the current rounds on successful login. | ||
| const minRounds = parseInt(process.env.PASSWORD_SALT_HASH_ROUNDS || '10', 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| export function getHash(value: string) { | ||
| const salt = bcrypt.genSaltSync(parseInt(process.env.PASSWORD_SALT_HASH_ROUNDS || '5')) | ||
| const salt = bcrypt.genSaltSync(parseInt(process.env.PASSWORD_SALT_HASH_ROUNDS || '10')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to parse the number of salt rounds from environment variables (including the default value of '10') is duplicated in account.service.ts. To centralize this logic and improve maintainability, consider creating a new helper function in this file, like getSaltRounds(), and use it in all relevant places.
Overview
Today, the application defaults to 5 salt rounds, increasing to 10 which is suggested by OWASP.
Additionally, adding a check to the login method to see if the existing has uses 10 rounds or not using the
bcrypt.getRounds()method, and updating the hash if it is less than 10 rounds.Testing Details
if (hashNeedsUpgrade(user.credential!, minRounds))) confirming that the check worked and determined there were insufficient salt rounds