fix(encryption): remove aad parameter from decrypt methods - #1007
Open
realcodesiman wants to merge 2 commits into
Open
fix(encryption): remove aad parameter from decrypt methods#1007realcodesiman wants to merge 2 commits into
realcodesiman wants to merge 2 commits into
Conversation
decryptText/decryptObject now read the aad off the stored blob instead of requiring the caller to reconstruct it, since only 1 of the 22 production decrypt call sites derived one and duplicating that string between writer and reader was a correctness footgun with no real payoff. encryptText/encryptObject keep their aad parameter to stamp the value at write time. The one place that read .aad directly (the appointment-token purpose check) keeps its own parameter and comparison, since that guards token purpose separation rather than crypto authentication and now does so alone. Also reverts platform-credential's required-aad schema and its now-inaccurate rationale, since decrypt no longer needs a caller- derived aad to bind against.
Code-review follow-up for the aad-on-blob change: the row-scoped aad template was hand-written in three writer sites (upsertForUser, upsertPlatform, rotate-encryption-key.ts) and had to stay identical by convention. Extract it into credentialAad in packages/database/src/partials/credential.ts so a drift between writers can no longer silently change what future rows are stamped with. Also fixes the rotation script's stale "silently excluded" comment — the unparseable-row warning it introduces is what makes that exclusion loud.
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
decryptText/decryptObjectno longer take anaadparameter — they readencryptedData.aadoff the stored blob instead, since only 1 of 22 production decrypt call sites derived and passed one, and duplicating that derivation between writer and reader was a correctness footgun (a drift between the two strings meant a hard decrypt failure) with no real payoff.encryptText/encryptObjectare unchanged and keep theiraadparameter, since something still has to stamp the value at write time..aaddirectly — the appointment-token purpose check inverifyAppointmentToken— keeps its ownaadparameter and pre-decrypt string comparison, since that guards token-purpose separation (schedule vs. cancel vs. webview tokens) rather than crypto authentication, and is now the sole mechanism enforcing it.platform-credential's required-aadschema constraint and its rationale comment, since decrypt no longer needs a caller-derived aad to bind against — a blob with no aad is a legitimate case again, not an error.Changes
packages/encryption/src/encryption.ts— dropaadparam fromdecryptText/decryptObject; readencryptedData.aadinternally; AES-GCM still authenticates the aad against the ciphertext/tag, so a tampered aad still fails, but an intact blob copied onto a different logical row is no longer detected (accepted trade-off)packages/encryption/src/appointment-token-utils.ts— drop the now-removed 3rd arg fromdecryptObject; keep the purpose-labelaadparam and pre-decrypt comparison, with an updated comment noting it's now load-bearing alonepackages/business/src/platform-credential/service.ts—_decryptno longer derives a row-scoped aad; write paths (upsertForUser/upsertPlatform) still stamp one but drop the now-unnecessarycredentialEncryptedSchema.parse()wrapperpackages/database/src/partials/credential.ts—aadback to.optional(); kept the unrelatediv/text/taglength tightening, which mirrorsencryptedDataSchemaand turns malformed rows into clear parse failures at the storage boundarypackages/database/scripts/rotate-encryption-key.ts— drop the aad arg from the decrypt call; keep the aad derivation for re-encrypting rotated rows; keep theunparseablerow warning bucketencryption,database, andbusinesspackages to match the new signatures and invariants, including a new tampered-aad test locking in that the aad is still authenticated, not merely echoedTest plan
pnpm --filter @chatbotx.io/encryption test— 27/27 passingpnpm --filter @chatbotx.io/database test— 423/423 passingpnpm --filter @chatbotx.io/business test— 1063/1063 passingpnpm --filter worker test— 1562/1562 passingpnpm --filter @chatbotx.io/encryption check-types,@chatbotx.io/database check-types,@chatbotx.io/business check-types,worker check-types— all cleanpnpm lint— cleandecryptObject/decryptTextcalls