dify icon indicating copy to clipboard operation
dify copied to clipboard

feat: add configurable password hash iterations for enhanced security

Open BenjaminX opened this issue 2 months ago • 5 comments

Summary

Risk Hardware Evolution: Modern GPUs and specialized hardware (such as ASICs) can compute billions of hashes per second. 10,000 iterations provide insufficient cost for brute-force attacks.

Industry Standard Changes:

OWASP recommended at least 600,000 iterations for PBKDF2-SHA256 in 2023 NIST SP 800-63B recommends at least 10,000 iterations (this is a 2017 standard, now considered outdated) Some security experts suggest 1,000,000+ iterations should be used in 2025 Real-World Impact: If a database is breached, attackers using modern hardware can rapidly test common passwords and dictionary attacks. The time cost provided by 10,000 iterations is nearly negligible.

fix https://github.com/langgenius/dify/issues/28576

BenjaminX avatar Nov 19 '25 02:11 BenjaminX

Summary of Changes

Hello @BenjaminX, I'm Gemini Code Assist[^1]! 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 application's security posture by making the password hashing process configurable. It replaces a fixed, potentially outdated iteration count for PBKDF2-HMAC-SHA256 with a dynamic value sourced from application configuration. This change allows for easy updates to the hashing cost in response to new security recommendations and advancements in hardware, thereby strengthening protection against brute-force attacks on user passwords.

Highlights

  • Configurable Password Hashing: Introduced a new configuration setting, PASSWORD_HASH_ITERATIONS, to allow dynamic adjustment of the number of iterations used for PBKDF2 password hashing.
  • Enhanced Security Recommendations: The new configuration includes a description recommending 600,000+ iterations for 2025 standards, highlighting the need for increased security against modern brute-force attacks.
  • Dynamic Iteration Count: The hash_password function now retrieves the iteration count from the dify_config instead of using a hardcoded value, making the system more adaptable to evolving security requirements.
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 :thumbsup: and :thumbsdown: 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.

[^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.

gemini-code-assist[bot] avatar Nov 19 '25 02:11 gemini-code-assist[bot]

Thanks for the PR :)

  • Please link an existing issue or create a new issue and link it in the description.
  • Please add some tests for the changes as well.

crazywoola avatar Nov 21 '25 09:11 crazywoola

Thanks for the PR :)

  • Please link an existing issue or create a new issue and link it in the description.
  • Please add some tests for the changes as well.

https://github.com/langgenius/dify/issues/28576

Testing cases https://github.com/langgenius/dify/pull/28374/commits/103581fece02309bde3d6409e33b9174fbf7a5cd

BenjaminX avatar Nov 24 '25 05:11 BenjaminX

Thank you for your contribution. I noticed that the commit history of this PR contains many changes that should not be there. Could you please clean them up?

laipz8200 avatar Dec 10 '25 18:12 laipz8200

Thank you for your contribution. I noticed that the commit history of this PR contains many changes that should not be there. Could you please clean them up?

squash commits.

BenjaminX avatar Dec 12 '25 14:12 BenjaminX