fix(auth): correctly size keys for encrypted token passwords - #63804
Open
joshtrichards wants to merge 8 commits into
Open
fix(auth): correctly size keys for encrypted token passwords#63804joshtrichards wants to merge 8 commits into
joshtrichards wants to merge 8 commits into
Conversation
joshtrichards
requested review from
icewind1991
and removed request for
a team
August 30, 2026 12:51
This was referenced Aug 30, 2026
Validate the encrypted password length before generating a key, use the RSA-OAEP plaintext limit when selecting the key size, and avoid generating 4096-bit keys when encrypted password storage is disabled. Signed-off-by: Josh <josh.t.richards@gmail.com>
Check the result of OpenSSL public-key encryption and fail explicitly instead of encoding and storing missing or invalid ciphertext. This also provides a controlled failure when a token created with a 2048-bit key cannot accommodate a subsequently changed, longer password. Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Replace and strengthen testGenerateTokenLongPassword(): - validate the new message - confirm that no token is inserted - rename test for clarity - use constant rather than hard-coded arbitrary 500 Signed-off-by: Josh <josh.t.richards@gmail.com>
Cover both sides of 214-byte password boundary. These tests specifically catch the old incorrect 250 threshold: the 215-byte case would fail under the old implementation. Signed-off-by: Josh <josh.t.richards@gmail.com>
This verifies both that the maximum is not applied and that a 4096-bit key is not generated unnecessarily. Signed-off-by: Josh <josh.t.richards@gmail.com>
Adds a short-to-long transition regression test for encryptPassword(). Verifies an existing 2048-bit existing token fails explicitly when password is storage is enabled and the password is changed to a >214-byte password. Assisted-by: Copilot:gpt-5.6-sol Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
joshtrichards
force-pushed
the
jtr/fix-auth-newToken
branch
from
August 31, 2026 01:04
2823f1b to
9003ba1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Correct the RSA key-size selection used to encrypt passwords associated with authentication tokens.
A 2048-bit RSA key using OAEP with SHA-1 can encrypt up to 214 bytes, but the existing code only selected a 4096-bit key for passwords longer than 250 bytes. Passwords between 215 and 250 bytes could therefore be assigned a key that was too small, causing password encryption to fail. Because that failure was not checked, the code subsequently attempted to Base64-encode an unset ciphertext value.
This change:
auth.storeCryptedPassword) is enabled;openssl_public_encrypt()before encoding or storing its output.Checking the encryption result also provides a controlled failure when an existing token with a 2048-bit key cannot accommodate a subsequently changed, longer password. The short-to-long password transition was already a problem, as reported in #45090, but its encryption failure was not handled explicitly. Regenerating existing token key pairs to accommodate a new, longer password (and defining the associated user experience) remain outside the scope of this PR.
Tests
Added unit coverage for:
TODO
Checklist
3. to review, feature component)stable32)AI (if applicable)