security: implement secure IP retrieval with TRUSTED_PROXIES support (closes #139)

This commit is contained in:
ralksta
2026-04-24 22:14:53 +02:00
parent 3c5715e0b0
commit 771cee517a
6 changed files with 64 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ export interface Env {
CACHE_TTL: number;
RATE_LIMIT_RPM: number;
AUTH_SECRET?: string;
TRUSTED_PROXIES: string[];
}
function parseEnv(): Env {
@@ -44,6 +45,10 @@ function parseEnv(): Env {
CACHE_TTL: Math.max(0, cacheTtl),
RATE_LIMIT_RPM: Math.max(1, rateLimit),
AUTH_SECRET: process.env.AUTH_SECRET,
TRUSTED_PROXIES: (process.env.TRUSTED_PROXIES || '')
.split(',')
.map((ip) => ip.trim())
.filter((ip) => ip !== ''),
};
}