Skip to content

Lesson 12 of 20 · 15m

Secrets, logs, and the debug modes that leak them

Secrets leak through git history, debug-mode error pages, browser-bundled env vars, logs, and crash reports — rotation and filtering are the fixes.

A secret in .env is only as private as everywhere it gets copied — and it gets copied into logs, error pages, browser bundles, git history, image layers, and crash reports far more often than into anything designed to hold it.

Git history doesn't forget

git rm .env && git commit removes the file, not the history — every clone and fork still carries the key. The only fix is rotation: the committed value is public, act like it. This is common enough that GitHub runs push protection and secret scanning platform-wide, and gitleaks/trufflehog exist as CI steps. .gitignore is a lint, not a control — it stops the commit when someone remembers, which is why the scanner runs after the mistake.

Docker images are the same trap in a different medium: --build-arg values persist in docker history, and COPY .env bakes the file into a layer every pushed image carries. Secrets passed at build time belong to multi-stage builds where the layer holding them never ships — or better, to runtime env entirely.

Debug modes are not a local problem

Django's DEBUG=True renders settings, environment variables, and SQL text on every error page. Laravel's Ignition shipped a debug-mode file editor, and in February 2021 CVE-2021-3129 turned it into unauthenticated remote code execution on facade/ignition — exploit kits picked through Laravel fleets within days. Mass scanners in the same era harvested publicly served .env files — APP_KEY, database credentials, mail passwords — from apps that never denied the dotfile at nginx. DEBUG and .env are deployment posture: they're configuration, so they fail in configuration, not in code review.

The bundle is public

import.meta.env.VITE_*, NEXT_PUBLIC_*, and REACT_APP_* are compile-time constants inlined into assets shipped to every browser. A VITE_SUPABASE_SERVICE_ROLE_KEY is readable in devtools by anyone who loads the page. The prefix is the whole guard: whatever the bundler inlines is public by construction, and the only thing keeping a service key server-side is never referencing it from client code. Check dist/ output for the key's name — grep beats intent.

Secrets in URLs deserve their own sentence: ?api_key= lands in nginx access logs, proxy logs, browser history, and Referer headers. Keys belong in Authorization headers, which is where every real provider puts them. Two more places secrets materialize that nobody greps: process arguments (mysql -p$PASS is visible to every user in ps output — use config files or stdin) and CI logs, where set -x echoes expanded variables into the build transcript forever.

Logs and crash reports

console.log(req.body) and request-logging middleware write Authorization headers, passwords, and tokens to disk indefinitely; Rails carries config.filter_parameters because "don't log secrets" loses without it. Error trackers are the same pipe: an exception's context — SQL text, request headers, locals — carries secrets into Sentry unless you strip them (before_send/sanitizer callbacks). And the page users see on a 500 should be a trace ID, not a stack trace: absolute paths, framework versions, and query text in an error response are free reconnaissance.

Practice

Secrets live in env or a manager, referenced by name — never in source, never under VITE_/NEXT_PUBLIC_, never printed, never in a query string. Scope them too: a restricted Stripe rk_ key or a token with three scopes costs nothing and bounds the blast radius of the leak you're eventually going to have. Rotate on any commit or log exposure; deletion doesn't un-copy. Filter parameters, sanitize crash payloads, keep debug off outside localhost, deny dotfiles in nginx, and grep the built bundle for each secret's name. The audit is mechanical: repo, nginx conf, logging conf, image history, crash-report config, bundle — anywhere a secret appears outside the secret store is the bug.

Keep reading

Related articles from the SudoSecurity blog.