Skip to content

Commit 8a13f34

Browse files
committed
security: require JWT_SECRET environment variable
BREAKING CHANGE: Server now fails to start if JWT_SECRET is not set. Previously fell back to insecure default "secret" which could allow JWT forgery attacks on misconfigured deployments. - Make JWT_SECRET required in config.rs with helpful error message - Update Makefile and CI workflows to set test secret - Update documentation to indicate JWT_SECRET is required
1 parent 91cb876 commit 8a13f34

5 files changed

Lines changed: 10 additions & 3 deletions

File tree

.github/workflows/pull-request-checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
defaults:
1212
run:
1313
working-directory: src
14+
env:
15+
JWT_SECRET: test_secret_for_ci
1416
steps:
1517
- uses: actions/checkout@v4
1618

.github/workflows/quality-checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
defaults:
1818
run:
1919
working-directory: src
20+
env:
21+
JWT_SECRET: test_secret_for_ci
2022
steps:
2123
- uses: actions/checkout@v4
2224

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ interface Request {
267267

268268
| Variable | Description |
269269
|----------|-------------|
270-
| `JWT_SECRET` | Secret key for JWT signing (min 32 chars recommended) |
270+
| `JWT_SECRET` | **Required.** Secret key for JWT signing (min 32 chars recommended). Server will fail to start if not set. |
271271
| `DOMAIN` | Base domain (e.g., `requestrepo.com`) |
272272
| `SERVER_IP` | Public IP for DNS responses |
273273

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test: test-backend test-frontend
6666

6767
.PHONY: test-backend
6868
test-backend:
69-
cd $(RUST_DIR) && cargo test
69+
cd $(RUST_DIR) && JWT_SECRET=test_secret_for_ci cargo test
7070

7171
.PHONY: test-frontend
7272
test-frontend:

src/src/utils/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ impl Config {
6161
let subdomain_alphabet = env::var("SUBDOMAIN_ALPHABET")
6262
.unwrap_or_else(|_| "0123456789abcdefghijklmnopqrstuvwxyz".to_string());
6363
let subdomain_alphabet_set = subdomain_alphabet.chars().collect();
64-
let jwt_secret = env::var("JWT_SECRET").unwrap_or_else(|_| "secret".to_string());
64+
let jwt_secret = env::var("JWT_SECRET").expect(
65+
"JWT_SECRET environment variable is required. \
66+
Generate a secure random string (32+ chars) and set it before starting the server.",
67+
);
6568
let txt_record = env::var("TXT").unwrap_or_else(|_| "Hello!".to_string());
6669
let http_port = env::var("HTTP_PORT")
6770
.unwrap_or_else(|_| "21337".to_string())

0 commit comments

Comments
 (0)