Repository navigation
Conversation
Only WrongKeyOrModifiedCiphertextException and EnvironmentIsBrokenException were caught. A malformed key raised Defuse's BadFormatException, which does not implement CryptExceptionInterface, and whose stack trace contains the key string. Throw InvalidKeyException instead, without chaining the defuse exception, and wrap any other defuse exception as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closed
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 of Changes
Cipher\Crypto::encrypt()/decrypt()only catchWrongKeyOrModifiedCiphertextExceptionandEnvironmentIsBrokenException. A malformed key (e.g. a truncated or hand-editedgetPrivate()string) makesDefuse\Crypto\Key::loadFromAsciiSafeString()throwDefuse\Crypto\Exception\BadFormatException, which does not implementCryptExceptionInterface, socatch (CryptExceptionInterface $e)does not catch it. Withzend.exception_ignore_args=0, its stack trace also contains the key string.This PR catches it and throws
InvalidKeyException('The key is not a valid crypto key.')without chaining the defuse exception, so neither the message nor the trace of the thrown exception contains the key. Any other defuseCryptoExceptionis wrapped inEncryptionException/DecryptionException(also unchained). Correct keys and ciphertexts behave as before.Marking key parameters with
#[\SensitiveParameter](also suggested for this problem) is done in a separate PR together with the otherKeyhardening, because it changes the same method signatures.Testing Instructions
CryptoTest::testMalformedKeyIsRejectedWithoutExposingIt(forencryptanddecrypt) uses a malformed key withzend.exception_ignore_args=0and expects anInvalidKeyExceptionwithout a previous exception whose string form does not contain the key. Before the change,BadFormatExceptionescapes.Documentation Changes Required
docs/overview.md("Handling failures"):InvalidKeyExceptionis also thrown for a malformedcryptokey.🤖 Generated with Claude Code