Skip to content

Commit 45fceef

Browse files
authored
fix: enforce strong secrets for AUTH and JWT in configuration (#471)
* fix: enforce strong secrets for AUTH and JWT in configuration Updated the configuration logic to throw errors if the AUTH and JWT environment variables are not set or are using default values. This ensures that strong secrets are provided for secure application operation. * fix: add missing JWT to api-main and AUTH to reader-main docker-compose
1 parent 13bbb66 commit 45fceef

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ services:
3737
environment:
3838
PG_URI: 'postgresql://default:password@postgres:5432/postgres'
3939
AUTH: dev
40+
JWT: dev-jwt-secret
4041
ports:
4142
- 3000:3000
4243
healthcheck:

packages/api-main/src/config.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import crypto from 'node:crypto';
21
import process from 'node:process';
32

43
import dotenv from 'dotenv';
@@ -33,8 +32,8 @@ export function useConfig(): Config {
3332
}
3433

3534
if (!process.env.JWT) {
36-
console.log(`JWT was not set, defaulting to a randomized byte hex string.`);
37-
process.env.JWT = crypto.randomBytes(128).toString('hex');
35+
console.error(`Failed to specify JWT, no JWT secret provided`);
36+
throw new Error(`JWT must be set to a strong secret`);
3837
}
3938

4039
if (typeof process.env.JWT_STRICTNESS === 'undefined') {
@@ -50,8 +49,8 @@ export function useConfig(): Config {
5049
config = {
5150
PORT: process.env.PORT ? Number.parseInt(process.env.PORT) : 3000,
5251
PG_URI: process.env.PG_URI,
53-
AUTH: process.env.AUTH ?? 'default',
54-
JWT: process.env.JWT ?? 'default-secret-key',
52+
AUTH: process.env.AUTH as string,
53+
JWT: process.env.JWT as string,
5554
JWT_STRICTNESS: process.env.JWT_STRICTNESS as JWT_STRICTNESS,
5655
DISCORD_WEBHOOK_URL: process.env.DISCORD_WEBHOOK_URL,
5756
};

packages/reader-main/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ services:
1111
BATCH_SIZE: 50
1212
MEMO_PREFIX: dither.
1313
RECEIVER: atone1uq6zjslvsa29cy6uu75y8txnl52mw06j6fzlep
14+
AUTH: dev
1415
# LOG: process.env.LOG === 'true' ? true : false,
1516
command: [pnpm, start]

packages/reader-main/src/config/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export function useConfig(): typeof config {
1313
return config;
1414
}
1515

16-
if (typeof process.env.AUTH === 'undefined') {
17-
console.warn(`AUTH env variable is set to default, ensure you provide an authorization key for reader communication`);
16+
if (!process.env.AUTH || process.env.AUTH === 'default') {
17+
console.error(`Failed to specify AUTH, no authorization secret provided`);
18+
throw new Error(`AUTH must be set to a strong secret`);
1819
}
1920

2021
config = {
@@ -25,7 +26,7 @@ export function useConfig(): typeof config {
2526
RECEIVER: process.env.RECEIVER,
2627
SENDER: process.env.SENDER,
2728
LOG: process.env.LOG === 'true',
28-
AUTH: process.env.AUTH ?? 'default',
29+
AUTH: process.env.AUTH,
2930

3031
ECLESIA_GRAPHQL_ENDPOINT: process.env.ECLESIA_GRAPHQL_ENDPOINT,
3132
ECLESIA_GRAPHQL_SECRET: process.env.ECLESIA_GRAPHQL_SECRET,

0 commit comments

Comments
 (0)