contextleak
Your .gitignore won't save your Docker image. contextleak checks whether the
sensitive files sitting in your build context — .env, private keys,
credentials, cloud configs — would actually be COPY'd/ADD'd into your image,
by simulating .dockerignore matching against every COPY/ADD instruction in
your Dockerfile.
pip install contextleak
cd your-project
contextleak
Scanned 214 files in build context (12 excluded by .dockerignore), 4 COPY/ADD instruction(s).
LEAK: 2 instruction(s) would copy sensitive files:
[COPY line 8] COPY . /app (stage: stage-1)
- .env (environment file, usually holds secrets)
- certs/server.key (private key material)
[ADD line 11] ADD config/ /etc/myapp/
- config/credentials.json (file name suggests stored credentials)
Exit code 1 when a leak is found, 0 when clean — drop it into CI.
Install
pip install contextleak
Requires Python 3.9+. Zero dependencies (stdlib only).
Usage
contextleak [context] [-f DOCKERFILE] [--ignore-file IGNORE] [--json]
context— build context directory (default: current directory).-f, --dockerfile— Dockerfile path (default:<context>/Dockerfile).--ignore-file— ignore file path (default:<context>/.dockerignore).--json— machine-readable output for CI pipelines.
What it does:
- Parses the Dockerfile's
COPY/ADDinstructions (multi-stage aware;COPY --from=<stage>copies come from another stage, not the context, so they are skipped). - Simulates
.dockerignorematching with Docker's own semantics — patterns anchored to the context root,**crossing directories,!negation with last-match-wins, directory patterns excluding their contents. - Expands each
COPY/ADDsource glob against the files that would actually be sent to the daemon. - Flags sensitive names:
.env/.env.*,*.pem,*.key, SSH private keys,*credential*,*secret*,*token*,.npmrc,.pypirc, Terraform state and*.tfvars, kubeconfigs, service-account files, and the.gitdirectory.
It also warns when an instruction references files that .dockerignore (or
absence) removed — that's a build that fails or silently copies nothing.
Differentiation
Tools like Trivy scan the finished image for known vulnerabilities (CVEs in
packages). contextleak checks a different, earlier layer: the build
context. A secret doesn't need a CVE to hurt you — if your .env is
COPY'd into the image at build time, it ships with every push of that image,
and no vulnerability scanner will flag it because it's your own file, not a
known-vulnerable package. One cut, one job: does your build context leak
secrets into the image? Nothing else.
License
MIT — see LICENSE.
Metadata
Release files for contextleak 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| contextleak-0.1.0.tar.gz | 12.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| contextleak-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.0 kB
Release files / contextleak-0.1.0.tar.gz
| Download URL | contextleak-0.1.0.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1f49771d6d7153c7dbf544256a4ce38086bb59945a6f54127d00b1122644067
|
|
BLAKE2b-256 checksum How to use checksums |
41a3945d43a8e7fed5ac28c0307033953657c8248323ca3326a87df23fb69ddc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / contextleak-0.1.0-py3-none-any.whl
| Download URL | contextleak-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02d27c49817c581b1b699b96e5f5fdad12049b06d79d4ae2814b8c1275e13b90
|
|
BLAKE2b-256 checksum How to use checksums |
f28de7dac3936cf28060445c27c1a09900451e92ccc0133685fba790dc89e4a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|