App validates required env vars at startup
Why it matters
An application that silently starts without a required environment variable will either crash at the specific moment the missing config is first used — mid-request, during a payment, or at checkout — or it will fall back to an undefined value and behave incorrectly without any error. OWASP A05 (Security Misconfiguration) covers misconfigured applications that fail silently. CWE-390 (Detection of Error Condition Without Action) applies when missing configuration is neither detected nor surfaced. Startup validation converts a runtime surprise into a deployment-time failure, where it is cheap to catch and easy to diagnose.
Severity rationale
Low because missing startup validation causes runtime failures at the point of use rather than at startup, making configuration errors harder to diagnose and increasing MTTR for deployment issues.
Remediation
Add a validation module that imports before any application logic and throws a descriptive error listing every missing variable. Import it as the first line of your server entry point.
// src/config.ts
const required = [
'DATABASE_URL',
'STRIPE_SECRET_KEY',
'JWT_SECRET',
'NEXTAUTH_SECRET',
] as const
for (const key of required) {
if (!process.env[key]) {
throw new Error(`Missing required environment variable: ${key}`)
}
}
export const config = {
databaseUrl: process.env.DATABASE_URL!,
stripeSecretKey: process.env.STRIPE_SECRET_KEY!,
jwtSecret: process.env.JWT_SECRET!,
} satisfies Record<string, string>
// src/server.ts — first import
import './config' // validation runs immediately on module load
For Next.js, place this in src/lib/env.ts and import from both next.config.ts and any server-side entry point.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Environment Security Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-390 — Detection of Error Condition Without Action
- owasp:2021 · A05 — Security Misconfiguration
Taxons
History
- 2026-04-18·v1.0.0·Initial import from environment-security·automated