Skip to content
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

TextHmacField doesnt encrypt with correct password PGCRYPTO_KEY #530

Closed
Gregorio1809 opened this issue Dec 22, 2022 · 1 comment
Closed
Labels

Comments

@Gregorio1809
Copy link

Hello, i have an issue when using TextHmacField as an encrypted fields

First, i'm using version 2.1.1,
then i check the attribute of "encrypt_sql" in TextHmacField
HMAC_SQL = "hmac(%s, '{}', 'sha512')".format(settings.PGCRYPTO_KEY)

However, when i upgrade to the latest version of your library
Suddenly, the format was changed into
HMAC_SQL = "hmac(%s, '{}', 'sha512')"

Can you tell me why the format string of PGCRYPTO_KEY is removed?

@some1ataplace
Copy link

The reason the format string of PGCRYPTO_KEY was removed in the latest version of django-pgcrypto-fields (version 2.3.0 onwards) is to improve security.

Previous versions of django-pgcrypto-fields used string interpolation to insert the value of settings.PGCRYPTO_KEY into the HMAC_SQL string, which can introduce a security vulnerability called SQL injection, where an attacker can manipulate the input data to execute malicious SQL code. Removing the format string and directly including the PGCRYPTO_KEY value in the HMAC_SQL string eliminates this vulnerability.

However, if you really need the old behavior, you can still use version 2.2.0 or earlier, or modify the source code of the latest version to include the format string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants