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
Prevent timing attacks to guess Gradio passwords #7440
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/6601070af0bc8955e94479ad66aa426ba0215591/gradio-4.19.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@6601070af0bc8955e94479ad66aa426ba0215591#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
gradio/route_utils.py
Outdated
|
||
|
||
def compare_passwords_securely(input_password: str, correct_password: str) -> bool: | ||
return hmac.compare_digest(input_password, correct_password) |
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.
I think this only works for ASCII characters. We should convert to bytes first something like input_password.encode("utf-8")
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.
Ah nice catch
|
||
|
||
def compare_passwords_securely(input_password: str, correct_password: str) -> bool: | ||
return hmac.compare_digest(input_password.encode(), correct_password.encode()) |
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.
Default encoding is utf-8
Done @freddyaboulton if you could take another look! |
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.
Nice and quick fix @abidlabs !
This way we compare passwords is vulnerable to timing attack to guess the password. This PR uses
hmac
to prevent that, as described here: https://sqreen.github.io/DevelopersSecurityBestPractices/timing-attack/python