

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.
Centralizing required configuration gives every secret the same validation behavior:
func requireEnvironmentVariable(environment map[string]string, name string) (string, error) {
value := environment[name]
if value == "" {
return "", fmt.Errorf("missing required environment variable: %s", name)
}
return value, nil
}
Read required configuration during startup. If PAWPAL_API_KEY is missing, fail immediately instead of waiting until a customer tries to check out. That's safer and easier to debug.
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 uses a PawPal API key committed in its configuration package. Replace that hard-coded key with required runtime configuration.
PAWPAL_API_KEY=pawpal_test_local go run ./cmd/server
Run and submit the CLI tests from the project root.