fix(email-connectors): require dedicated ENCRYPTION_KEY with HKDF derivation and throw on decryption failure
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
Research direction
Start with packages/email-connectors/src/crypto.ts and its tests in packages/email-connectors/src/crypto.spec.ts; check how the existing code reads keys, derives them, and handles malformed ciphertext. Update the tests to cover a missing ENCRYPTION_KEY, HKDF derivation, and wrong or corrupted keys, and document the environment variable in .env.example. Done when encryption uses the dedicated key and decryption failures throw explicit errors.
Written by the indexing model from the issue text.
Description
Problem Description
In packages/email-connectors/src/crypto.ts (lines 7–19 and 38–56):
- Session secret fallback:
getEncryptionKey()falls back toNEXTAUTH_SECRET/AUTH_SECRETand derives the AES-256-GCM key using an unsaltedsha256(secret). RotatingNEXTAUTH_SECRETfor session security would break all stored connector API keys. - Silent decryption failure:
decryptApiKey()catches all auth-tag/decryption errors and silently returns''(and returns non-3-part strings unencrypted as-is), hiding key mismatches or tampered/corrupted data.
(Note: packages/ai-connectors/src/crypto.ts has the same pattern and can be updated the same way.)
Expected Behavior
- Encryption uses a dedicated
ENCRYPTION_KEYenvironment variable only—neverNEXTAUTH_SECRETorAUTH_SECRET. - The 32-byte AES-256-GCM key is derived using
crypto.hkdfSyncwith a domain-specific info string instead of unsaltedsha256. decryptApiKey()throws an explicit error on malformed ciphertext or auth-tag/decryption failure instead of silently returning''or raw text.
Where to Look
packages/email-connectors/src/crypto.tspackages/email-connectors/src/crypto.spec.ts.env.example(documentENCRYPTION_KEY)
Solution / Implementation Guide
- Require dedicated
ENCRYPTION_KEY(crypto.ts):- Update
getEncryptionKey()to read onlyprocess.env.ENCRYPTION_KEY(throw a clear error if missing, and removeNEXTAUTH_SECRET/AUTH_SECRETfallbacks). - Add
ENCRYPTION_KEYto.env.example(e.g.generate-with-openssl-rand-hex-32).
- Update
- Use HKDF key derivation (
crypto.ts):- Replace
crypto.createHash('sha256').update(secret).digest()with:Buffer.from( crypto.hkdfSync('sha256', secret, 'instance-email-connectors-salt', 'instance-email-connectors-v1', 32), )
- Replace
- Fail loudly on invalid/tampered ciphertext (
crypto.ts&crypto.spec.ts):- In
decryptApiKey(), throw an explicit error ifparts.length !== 3(for non-empty strings) or ifdecipher.final()/ auth-tag verification fails, instead of returning''. - Update
packages/email-connectors/src/crypto.spec.tsto setENCRYPTION_KEYand assert thatdecryptApiKeythrows on wrong-key or corrupted ciphertext.
- In
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day