Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

fix(2FA): add `hex` key validation for `TWO_FACTOR_ENCRYPTION_KEY`

Rudy B.ebcc61c2b682
diff --git a/src/lib/two-factor/crypto.ts b/src/lib/two-factor/crypto.ts
index cc0cca056..3901351e4 100644
--- a/src/lib/two-factor/crypto.ts
+++ b/src/lib/two-factor/crypto.ts
@@ -5,7 +5,9 @@ const ALGORITHM = 'aes-256-gcm';
/** Loads and validates the 256-bit encryption key from TWO_FACTOR_ENCRYPTION_KEY. */
function getKey(): Buffer {
const hex = process.env.TWO_FACTOR_ENCRYPTION_KEY;
- if (!hex || hex.length !== 64) throw new Error('TWO_FACTOR_ENCRYPTION_KEY is missing or invalid');
+ if (!hex || hex.length !== 64 || !/^[0-9a-fA-F]{64}$/.test(hex)) {
+ throw new Error('TWO_FACTOR_ENCRYPTION_KEY is missing or invalid');
+ }
return Buffer.from(hex, 'hex');
}