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

Reject password inputs looking like raw bcrypt #9

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Conversation

Alkarex
Copy link
Member

@Alkarex Alkarex commented Nov 8, 2023

If a password arrives in the authorization header as a string looking like bcrypt (according to standard Modular Crypt Format) instead of normal-looking plain-text, then reject the authentication.
This is to avoid being able to pass the crypted version of the password, in case it was leaked.

If a password arrives in the authorization header as a string looking like bcrypt (according to standard Modular Crypt Format) instead of normal-looking plain-text, then reject the authentication.
This is to avoid being able to pass the crypted version of the password, in case it was leaked.
@Alkarex Alkarex requested a review from quackzar November 8, 2023 15:38
test.sh Outdated

test=$(
cat <<'EOF' | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6"'
{"req":{"headers":{"authorization":"Basic dGVzdDokMnkkMTAkNVRTWkRsZG9KN014RFpkdEsvU0cyTzNjd09ScUxEaEhhYllsS1g5T3NNLlcvWi9vTHdLVzY="}}}
Copy link
Member

Choose a reason for hiding this comment

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

It might be less opaque if the test input isn't hardcoded in base64 but just calls the base64 command as a subshell or using a variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Here you are c6842f5

* Is the password matching the Modular Crypt Format of bcrypt
*/
function isBcryptMcf(hash) {
return (typeof hash === 'string') && hash.match(/^\$2[abxy]?\$/);
Copy link
Member

Choose a reason for hiding this comment

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

While unlikely, we now reject some passwords if they match that regex. While unlikely, it might be an issue for some esoteric password generators.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes indeed. There is the same behaviour in e.g. Apache htpasswd approach, which I try to be compatible with

Copy link
Member

Choose a reason for hiding this comment

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

That would probably be the better solution then

@Alkarex Alkarex merged commit 8ef3226 into main Nov 15, 2023
@Alkarex Alkarex deleted the reject-mcf-input branch November 15, 2023 14:41
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.

2 participants