Overview
src/security/encryption/encryption.service.ts derives its AES-256 key via crypto.createHash('sha256').update(secret).digest(). SHA-256 is a fast, unaided hash with no work factor, making brute-force key derivation trivial. A proper KDF (PBKDF2, scrypt, or Argon2) must be used instead.
Specifications
Features:
- Derive the AES key using
crypto.scryptSync (or Argon2) with a persistent, randomly-generated salt stored separately from the key material.
Tasks:
- Replace
createHash('sha256') with crypto.scryptSync(secret, salt, 32).
- Store the salt in a separate env var (
ENCRYPTION_SALT) and validate its presence at startup.
- Document migration path for data encrypted with the old key.
- Add unit tests that verify key derivation uses scrypt parameters.
Impacted Files:
src/security/encryption/encryption.service.ts
.env.example
Acceptance Criteria
- Key derivation uses a KDF with configurable work factor.
- Startup fails if
ENCRYPTION_SECRET or ENCRYPTION_SALT are absent.
- Existing encrypted data can be migrated with a one-time re-encryption script.
Overview
src/security/encryption/encryption.service.tsderives its AES-256 key viacrypto.createHash('sha256').update(secret).digest(). SHA-256 is a fast, unaided hash with no work factor, making brute-force key derivation trivial. A proper KDF (PBKDF2, scrypt, or Argon2) must be used instead.Specifications
Features:
crypto.scryptSync(or Argon2) with a persistent, randomly-generated salt stored separately from the key material.Tasks:
createHash('sha256')withcrypto.scryptSync(secret, salt, 32).ENCRYPTION_SALT) and validate its presence at startup.Impacted Files:
src/security/encryption/encryption.service.ts.env.exampleAcceptance Criteria
ENCRYPTION_SECRETorENCRYPTION_SALTare absent.