AAK-STARTUP-HOOK-DOCKERFILE-001
Dockerfile adds a Python startup hook, or sets PYTHONSTARTUP in an MCP server image
| Field | Value |
|---|---|
| Severity | MEDIUM |
| Category | SUPPLY_CHAIN |
| Shipped | v0.6.28 |
| Scanner | agent_audit_kit/scanners/startup_hooks.py |
| OWASP MCP | MCP04:2025 (Software Supply Chain Attacks & Dependency Tampering) |
| OWASP Agentic | ASI04 (Agentic Supply Chain Vulnerabilities), ASI05 (Unexpected Code Execution) |
What it catches
A build step that puts code where Python runs it at every start, in every container started from the image:
COPY cook.pth /usr/local/lib/python3.12/site-packages/
RUN echo 'import hook' > /usr/local/lib/python3.12/site-packages/hook.pth
RUN cp tools/hook.py /usr/local/lib/python3.12/site-packages/sitecustomize.py
A COPY or ADD of a .pth, sitecustomize.py or usercustomize.py, a RUN that
writes one through a redirect, tee, cp, mv, install or ln, and
ENV PYTHONSTARTUP in an image that runs an MCP server are reported.
PYTHONSTARTUP names a file every interactive Python session in the image runs
first; a debugging shell inside a server container is one.
An image is taken to run an MCP server when an mcp word, fastmcp or
modelcontextprotocol appears in a CMD, ENTRYPOINT, RUN or LABEL, when a
manifest beside the Dockerfile declares an MCP SDK, or when an .mcp.json sits
beside it.
What it does not catch
- A package that
pip installinstalls with such a file inside it: scan the built image's files for that (see Scan a container image's files). - A directory copy that happens to contain a hook, unless the directory is on
PYTHONPATH(AAK-STARTUP-HOOK-SITECUSTOMIZE-001 reads that case). - A file written by a script the RUN calls, and a path built from
ARGor$VAR.
How to fix
Remove the step, or move what the hook does into the application's entry point. If the image must carry it, keep its source in the repository and review changes to it like code.
Registry reference
This section is generated from the rule registry (agent_audit_kit/rules/builtin.py) when the documentation is built, so it follows the scanner. The rest of the page is hand-written; where the two disagree, the registry is what runs.
- Severity
- MEDIUM
- Category
- Supply Chain (
supply-chain) - Scanner
agent_audit_kit/scanners/startup_hooks.py- Auto-fixable
- No.
- SARIF name
DockerfilePythonStartupHook
What it detects
A Dockerfile or Containerfile copies a .pth, sitecustomize.py or usercustomize.py into the image, writes one in a RUN step, or sets ENV PYTHONSTARTUP in an image that runs an MCP server. A .pth or a sitecustomize in the image's site-packages runs at every Python start in every container started from it, and PYTHONSTARTUP runs a file at the start of every interactive Python session in it. A build step that places one is either a deliberate hook, which belongs in the application's own start-up code, or how a compromised build slips code into every process.
How to fix (registry)
Remove the step, or move what the hook does into the application's entry point where it is visible and tested. If the image must carry the hook, keep its source in the repository, pin its content and review changes to it like code.
To confirm the finding is gone, report only this rule:
agent-audit-kit scan . --rules AAK-STARTUP-HOOK-DOCKERFILE-001
Limitations
Reads every file named Dockerfile, Containerfile, Dockerfile.*, Containerfile.* or *.dockerfile outside AAK's skip directories, joining continuation lines and skipping heredoc bodies; a parser directive that changes the escape character is not read. Reports a COPY or ADD whose source or destination names a .pth, sitecustomize.py or usercustomize.py (or a .pyc of either), or a .start file under a site-packages or dist-packages path; a RUN that writes one through a redirect, tee, cp, mv, install or ln; and ENV PYTHONSTARTUP when the image looks like it runs an MCP server: an mcp word, fastmcp or modelcontextprotocol in a CMD, ENTRYPOINT, RUN or LABEL, an MCP SDK declared in a manifest beside the Dockerfile, or an .mcp.json there. PYTHONSTARTUP takes effect only in interactive sessions. A package that pip install or npm install installs with such a file, a directory copy that contains one (unless the directory is on PYTHONPATH, see AAK-STARTUP-HOOK-SITECUSTOMIZE-001), a file written by a script the RUN calls, and a path built from ARG or $VAR are not seen. A Dockerfile over 1 MB is not read.
References
- OWASP MCP Top 10: MCP04:2025 (Software Supply Chain Attacks & Dependency Tampering)
- OWASP Agentic Top 10: ASI04 (Agentic Supply Chain Vulnerabilities), ASI05 (Unexpected Code Execution (RCE))
- Adversa AI MCP Top 25 (AAK-defined ids): ADV-SUPPLY-05 (Dangerous Install Script)
- Incidents and advisories: BERRIAI-LITELLM-2026-10-21
- CSA AI Controls Matrix (AICM): STA-08, IVS-04