fix(security): don't propagate ValueError from Crypto::decrypt() fallback#60735
Open
miaulalala wants to merge 1 commit into
Open
fix(security): don't propagate ValueError from Crypto::decrypt() fallback#60735miaulalala wants to merge 1 commit into
miaulalala wants to merge 1 commit into
Conversation
2 tasks
f281f96 to
e930c63
Compare
…back When decrypting a v3 ciphertext with a mismatched secret, the first attempt throws an Exception (HMAC mismatch). The fallback then calls decryptWithoutSecret() with an empty string, which causes hash_hkdf() to throw a ValueError. Since ValueError extends \Error rather than \Exception, it bypassed the catch block and propagated as an unhandled error, crashing the whole request. Wrap the fallback in its own try/catch(\Throwable) and rethrow the original Exception so callers get a meaningful HMAC mismatch error. Signed-off-by: Anna Larch <anna@nextcloud.com> AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
e930c63 to
29f43d8
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
Crypto::decrypt()first tries with the current secret (fails with HMAC mismatch), then falls back to an empty stringhash_hkdf('sha512', ''), which throws aValueErrorValueErrorextends\Error, not\Exception, so it bypassed thecatch (Exception $e)block and propagated as an unhandled error, crashing the entire requestdecryptWithoutSecret()call in its owncatch (\Throwable)and rethrow the original HMAC exceptionTest plan
NOCOVERAGE=1 ./autotest.sh sqlite tests/lib/Security/CryptoTest.phptestDecryptWithWrongSecretThrowsHmacExceptionNotValueErrorcovers the regression: encrypts with secret-A, decrypts with secret-B, asserts a properException('HMAC does not match.')is thrown rather than aValueError🤖 Generated with Claude Code