# Secrets in Logs and Build Artifacts
> Credentials that leak not through source code but through the *by-products* of running and building it: application and server logs, CI job logs, error telemetry and dumps, container image layers, build caches and published packages or bundles. Each by-product is another copy of the secret, usually with broader access and longer retention than the original.
## How it works
A secret in a repo is a known problem with known scanners ([[Hardcoded Secrets]], [[Secrets in Git History]]). By-products are harder because nobody writes the secret into them on purpose: a logger serialises an object, a build tool snapshots the environment, `COPY . .` takes the whole working tree. GitGuardian's "follow one key" walk-through has the same credential sitting on a laptop, in a repo, *echoed into a pipeline log*, in a ticket and in a teammate's config, with no single tool watching all five ([[raw/blog.gitguardian.com/why-secrets-slip-through-every-layer-of-your-security-stack-11522|GitGuardian, why secrets slip]]).
Two properties make by-products dangerous:
- **Wider audience than the source.** Logs are data at rest, but "typically afforded broader access than direct access to your databases"; logging a password is effectively storing it in plaintext ([[raw/allan.reyes.sh/keeping-secrets-out-of-logs-8922|Reyes, Keeping Secrets Out of Logs]]). Public CI logs, public images and npm/PyPI packages are readable by anyone.
- **Deleting the copy does not end the leak.** Image layers are immutable, rebuilt tags multiply one secret, and caches outlive the job. Only revocation ends it ([[Credential Rotation and Revocation]]).
### Runtime by-products: application and server logs
Reyes groups the common causes into six patterns ([[raw/allan.reyes.sh/keeping-secrets-out-of-logs-8922|Reyes]]):
| Cause | What happens |
|---|---|
| Direct logging | A debug line such as `Logger.info("session HERE", { temp })` for a session cookie that never gets removed |
| Kitchen sinks | Catching an SDK error and logging `{ e }` serialises its `config` and `response` objects, credentials included |
| Configuration changes | Flipping the global level from `WARN` to `DEBUG` releases fields the system was never designed to hide |
| Embedded secrets | A magic-link token in the URL path lands in plain HTTP access logs even though no code logs it |
| Telemetry | Error monitoring such as Sentry ships local-variable context, so a DB password appears in the dashboard even when the code never logs the exception |
| User input | Users type passwords into the username field, which is why AWS login alerts show `HIDDEN_DUE_TO_SECURITY_REASONS` |
Environment variables make this worse. They show up in error logs, rich debug output and crash reports, are inherited by every child process, and Express in non-production mode returns full stack traces in the response body. CVE-2019-5483 in the `seneca` toolkit leaked environment variables, cloud keys included ([[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|nodejs-security]]). OWASP likewise warns that env vars "may be included in logs or system dumps", and that an attacker who can crash a process and read the memory dump may extract secrets from it ([[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|OWASP Secrets Management CS]]).
**Diagnostic endpoints.** Spring Boot Actuator exposes only `/health` over HTTP by default, secures the other endpoints when Spring Security is on the classpath, and masks every value from `/env` and `/configprops` as `******`. Each default is switched off by a single property or bean (e.g. `show-values`, a permissive security config, widened exposure), none of which looks dangerous alone; together they turn an env-injected API key (from a Kubernetes Secret via `secretKeyRef`) into a plaintext HTTP response. Any env-held secret is also readable by the same user from `/proc/<pid>/environ` and inherited by child processes ([[raw/medium.com/how-your-apis-key-ends-up-readable-through-actuator-4-mistakes-to-avoi-15941|Bytebantz, Actuator]]; partial note, member-only article).
**Prompts sent to AI inference.** Secrets pasted into prompts (or read by agents and forwarded) become a by-product held by every hop: Dragos's canary study found three inference providers breached for months, Zero Data Retention-flagged prompts copied and read, and planted AWS keys abused within hours. A privacy flag binds only the first hop ([[raw/thehackernews.com/openrouter-drops-3-providers-after-researchers-catch-months-of-prompt-15915|THN, OpenRouter]]; [[Leaked Cloud Credentials]]).
### CI/CD job logs
- **tj-actions/changed-files (CVE-2025-30066, March 2025).** The compromised action dumped runner memory and printed workflow secrets into job logs as a double-encoded base64 blob. On public repositories those logs were public, so the leak needed no exfiltration server; Wiz found dozens of affected public repos, including large enterprises ([[raw/wiz.io/github-action-tj-actions-changed-files-supply-chain-attack-everything-4039|Wiz]], [[tj-actions changed-files Compromise]]).
- **Masking is a string match.** GitHub masks registered secret values, but any transformation (base64 twice) prints the raw value. Credentials the attacker *creates* during the job, such as a new cloud access key, are not registered and print in clear ([[raw/wiz.io/code-to-cloud-attacks-from-github-pat-to-cloud-control-plane-9098|Wiz, PAT to cloud]], [[GitHub Actions Security]]).
- Log retention cuts both ways: deleting the workflow removes the logs, but Wiz advises downloading logs from the exposure window first for the investigation.
### Build caches
Rust's Miri stored **all** environment variables under `target/`. Projects that cache `target/` in GitHub Actions let main-branch jobs write that cache and PRs read it, so anyone who had landed one PR could extract secrets from the cache and hide the evidence with a follow-up push. The fix keeps only `CARGO_*` (minus `CARGO_*_TOKEN`) and `OUT_DIR`; an ecosystem scan found one vulnerable repo. The Rust team's general warning: many tools "assume the entire environment can be written to the filesystem", so jobs that write to shared caches should not see secrets at all ([[raw/blog.rust-lang.org/github-actions-leaking-secrets-when-miri-output-is-cached-12241|Rust blog]]). BuildKit's inline and registry caches (`--cache-from`, `BUILDKIT_INLINE_CACHE=1`) are another layer store that travels between machines ([[raw/luis-sena.medium.com/creating-the-perfect-python-dockerfile-7511|Sena, Python Dockerfile]]).
### Container images and layers
- **Layers are append-only.** A secret pulled in with `ARG` or `COPY` stays in the image history even if a later layer deletes it; anyone who pulls the image can unpack the layers ([[raw/aikido.dev/securing-docker-images-11805|Aikido]]). OWASP: never hardcode secrets with `ENV` or `ARG`, they "leak with the container definitions" ([[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|OWASP]]).
- **Flare, Docker Hub, November 2025.** Scanning one month of uploads found 10,456 images with at least one key, about 4,000 of them AI-model keys; 42% held five or more secrets; 101 companies identified, including a Fortune 500 firm and a national bank. Common carriers were `.env` files, hardcoded tokens in Python and `config.json`/YAML, and image manifests. Much of it came from personal or contractor ("shadow IT") accounts outside corporate monitoring. One leaked GitHub token had `admin:org` and `admin:enterprise` scopes. About 25% of developers removed the secret within 48 hours, but in 75% of removals the key was never revoked ([[raw/flare.io/thousands-of-secrets-exposed-on-docker-hub-4067|Flare]], [[raw/bleepingcomputer.com/10-000-docker-hub-images-leaking-credentials-4066|BleepingComputer]], [[raw/theregister.com/10k-docker-images-spray-live-cloud-creds-4065|The Register]]).
- **The working tree, not the index.** `COPY . .` ships git-ignored files. GitGuardian found Claude Code's `.claude/settings.local.json` in 543 public Docker Hub image repos and 7,625 tags (72% under `/app`, `/workspace` or `/usr/src`): 613 distinct secrets, 99 valid. One valid Cloudflare token appeared in 559 tags; one database password in 643 tags across seven repos. Deleting the file from the repo does nothing for images already pushed ([[raw/blog.gitguardian.com/claude-code-settings-local-json-secrets-17-months-of-exposure-on-githu-13955|GitGuardian]], [[AI Coding Assistant Risks]]).
- An earlier study cited by nodejs-security put roughly 10% of Docker Hub images as leaking sensitive data ([[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|nodejs-security]]). A credential in an image layer was also the Codecov root cause ([[CI-CD Pipeline Attacks]]).
### Packaged and shipped artifacts
- **Bundles.** Storybook CVE-2025-68429: `storybook build` run in a directory containing `.env` bundled those values into the static build, readable by anyone once published ([[raw/miggo.io/cve-2025-68429-storybook-env-secrets-exposure-4064|Miggo]]). On the live web, 62% of JavaScript credential exposures existed only in bundled files and 16% came through third-party inclusions ([[raw/gsmaragd.github.io/keys-on-doormats-exposed-api-credentials-on-the-web-ccs-2026-15764|Keys on Doormats]]). Bundle-level patterns are covered in [[Hardcoded Secrets]] and [[JavaScript Analysis]].
- **Source maps.** Production `.map` files reconstruct readable original source. Checking is "close to the cheapest test": append `.map` to the bundle URL ([[raw/medium.com/the-debugging-file-nobody-removed-before-shipping-secrets-exposed-thro-12663|source map write-up]]). In the Trint HackerOne report, searching the public source map for `REACT_APP_ZENDESK_SECRET` revealed a JWT signing secret ([[raw/hackerone.com/hackerone-trint-insecure-client-side-jwt-generation-4106|Trint]], [[JWT Secret Cracking]]). Unit 42 saw ARTEX-style AI tooling target routes from downloaded source maps and OpenAPI specs almost immediately ([[raw/unit42.paloaltonetworks.com/artex-and-ai-powered-red-teaming-tools-what-defenders-need-to-know-14337|Unit 42]]).
- **npm/PyPI tarballs.** Claude Code 2.1.88 (March 2026) went to npm with a 59.8 MB source map holding 513,000 lines of TypeScript, internal prompts and feature flags, because of a missing `.npmignore` line ([[raw/okoone.com/the-hidden-ai-security-flaw-behind-four-major-supply-chain-attacks-8378|Okoone]]). nodejs-security names an API token exposed in a pushed npm package as a typical way env-held secrets get compromised ([[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|nodejs-security]]).
- **Mobile binaries** (APK/IPA) carry the same problem; see [[Android App Security]] and [[iOS App Security]].
## Detection
- **Scan images by unpacking layers**, not only manifests; Flare's results came from pulling, extracting and scanning image files ([[raw/flare.io/thousands-of-secrets-exposed-on-docker-hub-4067|Flare]]). Include personal and contractor registries in monitoring. Tooling is listed in [[Secret Scanning]].
- **Scan for generic secrets too.** In `settings.local.json`, 63% of occurrences came from generic detectors (passwords, bearer tokens, high-entropy strings); prefix-only scanners miss them ([[raw/blog.gitguardian.com/claude-code-settings-local-json-secrets-17-months-of-exposure-on-githu-13955|GitGuardian]]).
- **CI logs:** after a suspect action run, search the step output for encoded blobs (Wiz's tj-actions check looked for a double-encoded base64 string under "Get changed files"), and alert on attempts to dump secrets to logs ([[raw/wiz.io/github-action-tj-actions-changed-files-supply-chain-attack-everything-4039|Wiz]], [[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|OWASP]]).
- **Application logs:** sensitive-data scanners presume the leak already happened, so treat them as defense in depth. Decide whether they gate or scan asynchronously, whether they verify, and how to sample: Reyes recommends a minimum sample per log type rather than one global rate, because logs follow a power law ([[raw/allan.reyes.sh/keeping-secrets-out-of-logs-8922|Reyes]]).
- **Recon:** request `<bundle>.js.map` for every production script and grep it for env-style names ([[raw/hackerone.com/hackerone-trint-insecure-client-side-jwt-generation-4106|Trint]]).
## Prevention
**Logs** (Reyes's ten "lead bullets"; no single one suffices):
- One logging path only, so data entering it can be controlled; minimise or redact before data is passed around.
- Wrap secrets in domain primitives (`new Secret("...")`) and read-once objects instead of raw strings.
- Add a `redact()` step to the logger's formatter pipeline that drops risky paths (`headers`, `request`, `email.to`) and redacts known patterns; measured at under 1% of clock time, but watch for self-ReDoS.
- Make the same controls *error* in tests rather than redact, and point scanners at captured `stdout`/`stderr`.
- Run a log pre-processor (e.g. Vector) that redacts in-stream and sends a sample to TruffleHog or an LLM for verification before logs are stored.
- Taint-check secret sources flowing into log sinks in CI (Semgrep), and train teams to report leaks ([[raw/allan.reyes.sh/keeping-secrets-out-of-logs-8922|Reyes]]).
- Keep Actuator `/env`, `/configprops` and similar endpoints unexposed or behind authentication, and leave value masking on ([[raw/medium.com/how-your-apis-key-ends-up-readable-through-actuator-4-mistakes-to-avoi-15941|Bytebantz, Actuator]]).
- Scrub credential formats from LLM prompts and choose upstream inference providers explicitly; treat any prompt-borne secret as shared ([[raw/thehackernews.com/openrouter-drops-3-providers-after-researchers-catch-months-of-prompt-15915|THN, OpenRouter]]).
- Prefer mounted files or a sidecar over env vars; zero secret memory after use in high-risk environments ([[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|OWASP]], [[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|nodejs-security]]).
**CI:**
- Do not rely on masking. Scope secrets to the steps that need them; jobs that write public or PR-readable caches get no secrets; clear caches and rotate after exposure ([[raw/blog.rust-lang.org/github-actions-leaking-secrets-when-miri-output-is-cached-12241|Rust blog]]).
- Avoid passing runtime secrets through the pipeline at all; let the deployed service fetch its own with a platform identity, and authenticate runners with OIDC ([[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|OWASP]], [[Workload Identity Federation]]).
**Images:**
- Use BuildKit secret or SSH mounts (`RUN --mount=type=secret`) for build-time credentials so they never land in a layer; inject runtime secrets from a manager as a file or env at deploy time ([[raw/aikido.dev/securing-docker-images-11805|Aikido]], [[Vaults and Secret Stores]]).
- Multi-stage builds keep build tooling and intermediate files out of the final image ([[raw/aikido.dev/securing-docker-images-11805|Aikido]], [[raw/luis-sena.medium.com/creating-the-perfect-python-dockerfile-7511|Sena]]).
- `.dockerignore` `.git`, `.env*`, local config and agent folders such as `.claude/` so a broad `COPY` cannot pick them up ([[raw/aikido.dev/securing-docker-images-11805|Aikido]], [[raw/blog.gitguardian.com/claude-code-settings-local-json-secrets-17-months-of-exposure-on-githu-13955|GitGuardian]]).
- Scan before pushing to any public registry; stop using long-lived static keys ([[raw/theregister.com/10k-docker-images-spray-live-cloud-creds-4065|The Register]]).
**Packages and bundles:**
- Review what actually ships in each package (one missing `.npmignore` line published Claude Code's source map), and take source maps, OpenAPI specs and token-bearing config files off internet-facing apps ([[raw/okoone.com/the-hidden-ai-security-flaw-behind-four-major-supply-chain-attacks-8378|Okoone]], [[raw/unit42.paloaltonetworks.com/artex-and-ai-powered-red-teaming-tools-what-defenders-need-to-know-14337|Unit 42]]).
- Build static sites in CI from platform env vars rather than a directory with `.env`, and upgrade Storybook ([[raw/miggo.io/cve-2025-68429-storybook-env-secrets-exposure-4064|Miggo]]).
**After any leak:** rotate first. Removing the artifact, deleting the log or rebuilding the image is cleanup, not remediation ([[Credential Rotation and Revocation]]).
## Related
- [[Secrets Management]]
- [[Hardcoded Secrets]] · [[Secrets in Git History]] · [[Secret Scanning]] · [[Developer Workstation Secrets]] · [[Leaked Cloud Credentials]]
- [[CI-CD Pipeline Attacks]] · [[GitHub Actions Security]] · [[tj-actions changed-files Compromise]] · [[Pwn Requests]] · [[Software Supply Chain Security]]
- [[JavaScript Analysis]] · [[AI Coding Assistant Risks]] · [[Vaults and Secret Stores]] · [[Workload Identity Federation]]
## Sources
- [[raw/allan.reyes.sh/keeping-secrets-out-of-logs-8922|Keeping Secrets Out of Logs]]
- [[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|Secrets Management - OWASP Cheat Sheet Series]]
- [[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|Do Not Use Secrets in Environment Variables]]
- [[raw/blog.gitguardian.com/why-secrets-slip-through-every-layer-of-your-security-stack-11522|Why Secrets Slip Through Every Layer of Your Security Stack]]
- [[raw/wiz.io/github-action-tj-actions-changed-files-supply-chain-attack-everything-4039|GitHub Action tj-actions/changed-files supply chain attack]]
- [[raw/wiz.io/code-to-cloud-attacks-from-github-pat-to-cloud-control-plane-9098|Code to Cloud Attacks: From GitHub PAT to Cloud Control Plane]]
- [[raw/blog.rust-lang.org/github-actions-leaking-secrets-when-miri-output-is-cached-12241|GitHub Actions leaking secrets when Miri output is cached]]
- [[raw/luis-sena.medium.com/creating-the-perfect-python-dockerfile-7511|Creating the Perfect Python Dockerfile]]
- [[raw/aikido.dev/securing-docker-images-11805|Securing Docker images]]
- [[raw/flare.io/thousands-of-secrets-exposed-on-docker-hub-4067|Thousands of Secrets Exposed on Docker Hub]]
- [[raw/bleepingcomputer.com/10-000-docker-hub-images-leaking-credentials-4066|10,000+ Docker Hub Images Leaking Credentials]]
- [[raw/theregister.com/10k-docker-images-spray-live-cloud-creds-4065|10K Docker Images Spray Live Cloud Creds]]
- [[raw/blog.gitguardian.com/claude-code-settings-local-json-secrets-17-months-of-exposure-on-githu-13955|Claude Code settings.local.json Secrets: 17 months of exposure on GitHub & Docker Hub]]
- [[raw/miggo.io/cve-2025-68429-storybook-env-secrets-exposure-4064|CVE-2025-68429: Storybook .env Secrets Exposure]]
- [[raw/gsmaragd.github.io/keys-on-doormats-exposed-api-credentials-on-the-web-ccs-2026-15764|Keys on Doormats: Exposed API Credentials on the Web (CCS 2026)]]
- [[raw/medium.com/the-debugging-file-nobody-removed-before-shipping-secrets-exposed-thro-12663|The Debugging File Nobody Removed Before Shipping]]
- [[raw/hackerone.com/hackerone-trint-insecure-client-side-jwt-generation-4106|HackerOne: Trint insecure client-side JWT generation]]
- [[raw/okoone.com/the-hidden-ai-security-flaw-behind-four-major-supply-chain-attacks-8378|The hidden AI security flaw behind four major supply chain attacks]]
- [[raw/unit42.paloaltonetworks.com/artex-and-ai-powered-red-teaming-tools-what-defenders-need-to-know-14337|ARTEX and AI-Powered Red Teaming Tools]]
- [[raw/medium.com/how-your-apis-key-ends-up-readable-through-actuator-4-mistakes-to-avoi-15941|How Your APIs Key Ends Up Readable Through Actuator: 4 Mistakes to Avoid]]
- [[raw/thehackernews.com/openrouter-drops-3-providers-after-researchers-catch-months-of-prompt-15915|OpenRouter Drops 3 Providers After Researchers Catch Months of Prompt Theft at AI Hosting Firms]]