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 (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 (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 (Reyes):

CauseWhat happens
Direct loggingA debug line such as Logger.info("session HERE", { temp }) for a session cookie that never gets removed
Kitchen sinksCatching an SDK error and logging { e } serialises its config and response objects, credentials included
Configuration changesFlipping the global level from WARN to DEBUG releases fields the system was never designed to hide
Embedded secretsA magic-link token in the URL path lands in plain HTTP access logs even though no code logs it
TelemetryError 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 inputUsers 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 (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 (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 (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 (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 (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 (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 (Rust blog). BuildKit’s inline and registry caches (--cache-from, BUILDKIT_INLINE_CACHE=1) are another layer store that travels between machines (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 (Aikido). OWASP: never hardcode secrets with ENV or ARG, they “leak with the container definitions” (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 (Flare, BleepingComputer, 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 (GitGuardian, AI Coding Assistant Risks).
  • An earlier study cited by nodejs-security put roughly 10% of Docker Hub images as leaking sensitive data (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 (Miggo). On the live web, 62% of JavaScript credential exposures existed only in bundled files and 16% came through third-party inclusions (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 (source map write-up). In the Trint HackerOne report, searching the public source map for REACT_APP_ZENDESK_SECRET revealed a JWT signing secret (Trint, JWT Secret Cracking). Unit 42 saw ARTEX-style AI tooling target routes from downloaded source maps and OpenAPI specs almost immediately (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 (Okoone). nodejs-security names an API token exposed in a pushed npm package as a typical way env-held secrets get compromised (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 (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 (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 (Wiz, 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 (Reyes).
  • Recon: request <bundle>.js.map for every production script and grep it for env-style names (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 (Reyes).
  • Keep Actuator /env, /configprops and similar endpoints unexposed or behind authentication, and leave value masking on (Bytebantz, Actuator).
  • Scrub credential formats from LLM prompts and choose upstream inference providers explicitly; treat any prompt-borne secret as shared (THN, OpenRouter).
  • Prefer mounted files or a sidecar over env vars; zero secret memory after use in high-risk environments (OWASP, 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 (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 (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 (Aikido, Vaults and Secret Stores).
  • Multi-stage builds keep build tooling and intermediate files out of the final image (Aikido, Sena).
  • .dockerignore .git, .env*, local config and agent folders such as .claude/ so a broad COPY cannot pick them up (Aikido, GitGuardian).
  • Scan before pushing to any public registry; stop using long-lived static keys (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 (Okoone, Unit 42).
  • Build static sites in CI from platform env vars rather than a directory with .env, and upgrade Storybook (Miggo).

After any leak: rotate first. Removing the artifact, deleting the log or rebuilding the image is cleanup, not remediation (Credential Rotation and Revocation).

Sources