镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

ext/standard: notice on long passwords in bcrypt - #23076

Closed
Sjord wants to merge 3 commits into
php:masterfrom
Sjord:bcrypt-72-notice
Closed

Sjord wants to merge 3 commits into
php:masterfrom
Sjord:bcrypt-72-notice

Conversation

@Sjord

@Sjord Sjord commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

@Sjord

Sjord commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

This could also apply to crypt. However, with crypt there is not a distinction between creating the hash and verifying the hash, as there is with password_hash / password_verify, which means that anyone that can access to login screen can trigger the notice by entering a long password. That makes the notice less meaningful and bigger chance of BC break.

@Sjord

Sjord commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@nikic @narfbg @ircmaxell I am looking into this again, and you seemed to have objected last time. Do you feel the same now?

This is mostly for the case where some static string is prepended to the password before being passed to password_hash, and not so much for the case where users actually use 72 character passwords.

@narfbg

narfbg commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for the ping, @Sjord.

I do still think that warnings would do more harm than good.

However, I might not be against a fail-closed approach where an exception is thrown. Not to say that I'd outright support that (the BC break can be too big a price to pay) but it would solve most of the problems I have with the warning idea.

@Sjord

Sjord commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

password_hash and password_verify are supposed to take a user's password. For both this is clear from the documentation. In that case, it is really rare and no problem if it's longer than 72 bytes.

However, in the FreshRSS bug (and more or less the Okta bug) mentioned above, they don't just supply the password, but prepend a nonce or a username. This is a bad idea and not a supported way of using password_hash/verify.

I think throwing an error is warranted. For FreshRSS this would mean severe BC break: their authentication method stops working when they upgrade their PHP version. Perhaps that's acceptable? It could be better than that users can bypass the authentication altogether. And if you use functions in undocumented and unsupported ways, you can expect BC break.

@Sjord

Sjord commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

We could add a new algorithm to password_hash:

  • existing PASSWORD_BCRYPT silently truncates;
  • new PASSWORD_BCRYPT_EX throws exception when password is longer than 72 characters.

Then at some point we make PASSWORD_BCRYPT_EX the default, but it would be easy to avoid BC break by specifying PASSWORD_BCRYPT algorithm.

@Sjord

Sjord commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

@Sjord

Sjord commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

This is on hold, at least until we make a decision on PASSWORD_BCRYPT_SHA256.

@Sjord Sjord closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants