fix: specify authTagLength in AES-GCM createDecipheriv calls#3881
fix: specify authTagLength in AES-GCM createDecipheriv calls#3881NLmejiro wants to merge 1 commit intosimstudioai:mainfrom
Conversation
Fixes missing authTagLength parameter in createDecipheriv calls using AES-256-GCM mode. Without explicit tag length specification, the application may be tricked into accepting shorter authentication tags, potentially allowing ciphertext spoofing. CWE-310: Cryptographic Issues (gcm-no-tag-length)
|
@NLmejiro is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
PR SummaryMedium Risk Overview This standardizes the expected GCM auth tag size during decryption to reduce acceptance of malformed/short tags and align behavior across these call sites. Written by Cursor Bugbot for commit 84fe778. This will update automatically on new commits. Configure here. |
Greptile SummaryThis PR hardens AES-256-GCM decryption across three files by explicitly passing Key points:
Confidence Score: 5/5This PR is safe to merge — changes are minimal, correct, and strictly additive to security without breaking backward compatibility. All three changes are identical one-line additions of { authTagLength: 16 } to createDecipheriv calls. The fix is consistent with the encrypt side (which already produces 16-byte tags by default), introduces no new logic paths, and no P0/P1 issues were found. No files require special attention — all changes are straightforward and correct. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Decryptor
participant NodeCrypto as Node.js crypto
Caller->>Decryptor: decryptApiKey/decryptSecret(encryptedValue)
Decryptor->>Decryptor: parse iv, ciphertext, authTag from "iv:ciphertext:authTag"
Decryptor->>NodeCrypto: createDecipheriv('aes-256-gcm', key, iv, { authTagLength: 16 })
Note over NodeCrypto: authTagLength: 16 enforces tag must be exactly 16 bytes
Decryptor->>NodeCrypto: decipher.setAuthTag(authTag)
Note over NodeCrypto: Throws if authTag.length is not 16
Decryptor->>NodeCrypto: decipher.update(encrypted) + decipher.final()
Note over NodeCrypto: final() verifies GCM tag and throws if invalid
NodeCrypto-->>Decryptor: plaintext
Decryptor-->>Caller: decrypted plaintext
Reviews (1): Last reviewed commit: "fix: specify authTagLength in AES-GCM de..." | Re-trigger Greptile |
…tency Complements #3881 by adding explicit authTagLength: 16 to the encrypt side as well, ensuring both cipher and decipher specify the tag length. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… calls (#3883) * fix: specify authTagLength in AES-GCM decipheriv calls Fixes missing authTagLength parameter in createDecipheriv calls using AES-256-GCM mode. Without explicit tag length specification, the application may be tricked into accepting shorter authentication tags, potentially allowing ciphertext spoofing. CWE-310: Cryptographic Issues (gcm-no-tag-length) * fix: specify authTagLength on createCipheriv calls for AES-GCM consistency Complements #3881 by adding explicit authTagLength: 16 to the encrypt side as well, ensuring both cipher and decipher specify the tag length. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: clean up crypto modules - Fix error: any → error: unknown with proper type guard in encryption.ts - Eliminate duplicate iv.toString('hex') calls in both encrypt functions - Remove redundant string split in decryptApiKey (was splitting twice) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * new turborepo version --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Lakee Sivaraya <71339072+lakeesiv@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai> Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com> Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Co-authored-by: NLmejiro <kuroda.k1021@gmail.com>
Summary
Specifies explicit
authTagLength: 16parameter increateDecipherivcalls using AES-256-GCM mode.Vulnerability
CWE-310 (Cryptographic Issues) — missing authentication tag length specification in GCM mode decryption. Without an explicit expected tag length, an attacker may be able to spoof ciphertexts using a shorter-than-expected authentication tag.
Affected Files
apps/sim/lib/api-key/crypto.tsapps/sim/lib/core/security/encryption.tspackages/db/scripts/migrate-block-api-keys-to-byok.tsFix
```typescript
// Before
crypto.createDecipheriv('aes-256-gcm', key, iv)
// After
crypto.createDecipheriv('aes-256-gcm', key, iv, { authTagLength: 16 })
```