

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Managing Secrets
incomplete
2: Injecting Secrets at Runtime
incomplete
3: Protecting Secrets
incomplete
4: Build Artifacts and Deployment Hygiene
incomplete
5: Limiting Build Context
incomplete
6: Source Code and Config Leaks
incomplete
7: Public File Leaks
incomplete
8: Server-Side Request Forgery
incomplete
9: Defending Against SSRF
incomplete
10: Open Redirects
incomplete
11: Risks of Dependencies
incomplete
12: Auditing Dependencies
incomplete
13: Dependency Maintenance
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Apps need secrets at runtime, but those secrets shouldn't live in source code. A common approach is to inject them through environment variables.
Your code should typically centralize access to environment variables. A small helper gives every required value the same validation behavior:
export function requireEnv(name: string): string {
const value = process.env[name];
if (!value) {
throw new Error(`Missing required environment variable: ${name}`);
}
return value;
}
export const ticketProviderKey = requireEnv("TICKET_PROVIDER_KEY");
You should read required configuration during startup. If TICKET_PROVIDER_KEY is missing, fail immediately instead of waiting to fail when a customer tries to buy a ticket. That's safer and easier to debug.
To be clear, secrets don't need to use environment variables, and environment variables can still be handled insecurely. The important part is that secrets are not committed to source code. Inject them when the app starts from a protected source.
Bearly Secure signs PawPal references with a key committed directly in src/integrations/pawpal.ts. Replace that hard-coded key with required runtime configuration.
PAWPAL_API_KEY=pawpal_test_local npm run dev
Run and submit the CLI tests from the project root.