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

hash_secret with salt version set to non-bcrypt version returns an empty string instead of raising BCrypt::Errors::InvalidSalt #133

Open
DZittersteyn opened this issue Mar 11, 2016 · 0 comments

Comments

@DZittersteyn
Copy link

There is some interesting behavior going on when generating a hash with a salt that fits the validation regex, but has a version that doesn't exist, in that it returns the empty string instead of raising:

> salt = "$2a$10$TD5b9p9vdGsuEwKyrtSua."
> BCrypt::Engine.hash_secret("test", salt, 10).to_s
=> "$2a$10$TD5b9p9vdGsuEwKyrtSua.sh9lprEf.VOyagv/sm7PbdPVT46i.1K"

> salt = "$2x$10$TD5b9p9vdGsuEwKyrtSua."
> BCrypt::Engine.hash_secret("test", salt, 10).to_s
=> "$2x$10$TD5b9p9vdGsuEwKyrtSua.sh9lprEf.VOyagv/sm7PbdPVT46i.1K"

> salt = "$00$10$TD5b9p9vdGsuEwKyrtSua."
> BCrypt::Engine.hash_secret("test", salt, 10).to_s
=> ""

This behavior doesn't appear to be covered by specs, and looks to be slightly dangerous if undetected. Would it be a good idea to change the regex at https://github.com/codahale/bcrypt-ruby/blob/master/lib/bcrypt/engine.rb#L81
from
/^\$[0-9a-z]{2,}\$[0-9]{2,}\$[A-Za-z0-9\.\/]{22,}$/
to
/^\$2[abxy]\$[0-9]{2,}\$[A-Za-z0-9\.\/]{22,}$/
, or am I missing some use-case here?

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

No branches or pull requests

1 participant