fix(email-connectors): require dedicated ENCRYPTION_KEY with HKDF derivation and throw on decryption failure

オープン
#34 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
backend, security

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

backend bug good first issue
Problem Description

In packages/email-connectors/src/crypto.ts (lines 7–19 and 38–56):

  1. Session secret fallback: getEncryptionKey() falls back to NEXTAUTH_SECRET / AUTH_SECRET and derives the AES-256-GCM key using an unsalted sha256(secret). Rotating NEXTAUTH_SECRET for session security would break all stored connector API keys.
  2. 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
  1. Encryption uses a dedicated ENCRYPTION_KEY environment variable only—never NEXTAUTH_SECRET or AUTH_SECRET.
  2. The 32-byte AES-256-GCM key is derived using crypto.hkdfSync with a domain-specific info string instead of unsalted sha256.
  3. 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.ts
  • packages/email-connectors/src/crypto.spec.ts
  • .env.example (document ENCRYPTION_KEY)

Solution / Implementation Guide
  1. Require dedicated ENCRYPTION_KEY (crypto.ts):
    • Update getEncryptionKey() to read only process.env.ENCRYPTION_KEY (throw a clear error if missing, and remove NEXTAUTH_SECRET / AUTH_SECRET fallbacks).
    • Add ENCRYPTION_KEY to .env.example (e.g. generate-with-openssl-rand-hex-32).
  2. 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),
      )
      
  3. Fail loudly on invalid/tampered ciphertext (crypto.ts & crypto.spec.ts):
    • In decryptApiKey(), throw an explicit error if parts.length !== 3 (for non-empty strings) or if decipher.final() / auth-tag verification fails, instead of returning ''.
    • Update packages/email-connectors/src/crypto.spec.ts to set ENCRYPTION_KEY and assert that decryptApiKey throws on wrong-key or corrupted ciphertext.
主要言語
TypeScript
スター
2
フォーク
1
平均マージ
6分
マージ済み PR(30日)
27

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sumamakhan761/tryinstance のほかの issue

sumamakhan761/tryinstance の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。