Skip to content

Conversation

@christopherholland-workday

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

  1. Booted up Flowise locally and signed up (using 5 salt rounds)
  2. Made code updates to use 10 rounds, but made a temporary change to the code to throw an exception after the check (if (hashNeedsUpgrade(user.credential!, minRounds))) confirming that the check worked and determined there were insufficient salt rounds
  3. Removes the exception from the code, login succeeded and so did subsequent logins

Today, the application defaults to 5 salt rounds, increasing to 10 which is suggested by OWASP.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Increased Salt Rounds for New Passwords: The default number of salt rounds used for hashing new passwords has been increased from 5 to 10, aligning with OWASP recommendations for enhanced security.
  • Automatic Password Hash Upgrade: A new mechanism has been implemented to automatically detect if an existing user's password hash was created with fewer than 10 salt rounds. Upon successful login, if the hash is deemed weaker, it will be re-hashed with the current minimum of 10 rounds and saved back to the database.
  • New Encryption Utility Functions: Two new utility functions, getBcryptRoundsFromHash and hashNeedsUpgrade, have been added to encryption.util.ts to facilitate the inspection and upgrade of password hashes.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +583 to 585
const salt = bcrypt.genSaltSync(parseInt(process.env.PASSWORD_SALT_HASH_ROUNDS || '10'))
// @ts-ignore
const hash = bcrypt.hashSync(data.user.password, salt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to parse the number of salt rounds from environment variables is duplicated here and in other parts of the codebase (e.g., encryption.util.ts). To ensure consistency and improve maintainability, this should be centralized into a single helper function, for example in encryption.util.ts.


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'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

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.

3 participants