fix: prevent AES-CBC encryption, enforce GCM for all new data (#984)#1041
Closed
franco-zalamena-iterable wants to merge 1 commit intomasterfrom
Closed
fix: prevent AES-CBC encryption, enforce GCM for all new data (#984)#1041franco-zalamena-iterable wants to merge 1 commit intomasterfrom
franco-zalamena-iterable wants to merge 1 commit intomasterfrom
Conversation
#984) AES/CBC/PKCS5Padding is vulnerable to Padding Oracle Attacks. Ensure TRANSFORMATION_LEGACY (AES/CBC) is only used when decrypting previously stored data for migration purposes. All new encryption uses AES/GCM/NoPadding (TRANSFORMATION_MODERN). Changes: - encrypt() always calls encryptModern(); the old CBC fallback is removed - encryptLegacy() is deleted; AES/CBC can no longer be used for writes - decryptLegacy() is kept (read-only migration path) with a prominent security comment explaining why CBC must not be used for encryption - Added decryptAndMigrate() helper that decrypts legacy CBC data and immediately re-encrypts it with GCM so callers can persist the updated ciphertext, eliminating future CBC reads - Removed dead code: generateIV(), GCM_IV_LENGTH, CBC_IV_LENGTH, unused @TargetApi annotations and SecureRandom import - Added TRANSFORMATION_LEGACY comment documenting decryption-only intent Made-with: Cursor
Contributor
Author
PR AnalysisProblem: Ideal fix plan:
What the PR did:
Assessment:
|
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.
Problem
IterableDataEncryptorcontained anencryptLegacy()path that usedAES/CBC/PKCS5Padding(TRANSFORMATION_LEGACY) for encryption on older Android versions. CBC mode (with PKCS5 padding) is vulnerable to Padding Oracle Attacks and must never be used for encryption.Changes
encrypt()always uses GCM — removed the SDK-version branch that fell back to CBC; sinceminSdkVersionis 21 (> KITKAT 19) this branch was already dead code, but its existence was a latent risk.encryptLegacy()deleted —AES/CBCcan no longer be used for any write path.decryptLegacy()retained (read-only) — decorated with a prominent security comment explaining it exists solely for backward-compatible decryption of data written by older SDK versions.decryptAndMigrate()added — decrypts a value and, if it was CBC-encrypted, immediately re-encrypts it with GCM and returns the new ciphertext. Callers can persist the updated ciphertext to eliminate future CBC reads entirely.generateIV(),GCM_IV_LENGTH,CBC_IV_LENGTH, unused@TargetApiannotations, andSecureRandomimport.TRANSFORMATION_LEGACYcomment — clearly documents that this constant is for decryption-only migration use.Security Impact
decryptAndMigrate()helper so apps can automatically upgrade persisted CBC ciphertexts to GCM on first read.Test plan
decrypt()encrypt()always produces GCM ciphertext (isModern flag = 1)decryptAndMigrate()returns a GCM ciphertext when given a CBC inputdecryptAndMigrate()returns the original ciphertext unchanged when input is already GCMMade with Cursor