Image layers are scanned for hardcoded credentials and secrets
Why it matters
Secrets baked into Docker image layers are permanently readable by anyone with registry pull access — including future employees, CI systems, and compromised tokens (OWASP A02, CWE-540). Docker layer history exposes every ARG, ENV, and RUN instruction even after a subsequent RUN unset — the value persists in the lower layer. NIST 800-53 SC-28 requires protection of information at rest; credentials in registry layers violate that control and are disclosed with every docker history command. This is one of the most common paths to credential exposure in containerized environments.
Severity rationale
Critical because credentials baked into image layers are exfiltrated by anyone with registry read access — no runtime exploit required.
Remediation
Use multi-stage builds to ensure secrets never land in the final image layer. In Dockerfile:
# Build stage — secret is accessible here
FROM node:20 AS builder
ARG PRIVATE_TOKEN
RUN git clone https://${PRIVATE_TOKEN}@github.com/org/private-repo.git /src
RUN cd /src && npm ci && npm run build
# Runtime stage — secret never copied
FROM node:20-alpine
COPY --from=builder /src/dist /app
CMD ["node", "/app/index.js"]
For runtime secrets, inject via Kubernetes Secrets (secretKeyRef) or a secrets manager (Vault, AWS Secrets Manager). Never use ENV SECRET=value in the final stage — use docker secret or runtime injection instead.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Infrastructure Hardening Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-540 — Inclusion of Sensitive Information in Source Code
- owasp:2021 · A02 — Cryptographic Failures
- nist:rev5 · SC-28 — Protection of Information at Rest
- external · CIS-Docker-4.10 — CIS Docker Benchmark v1.6 §4.10 — Do not store secrets in Dockerfiles
- soc2:2017 · C1.1 — Identification and protection of confidential information
Taxons
History
- 2026-04-18·v1.0.0·Initial import from infrastructure-hardening·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (C1.1) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2