From 176e1c85aff0104cc88b4c609a422af6d66f7a0e Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Fri, 20 Nov 2026 09:25:18 +0000 Subject: [PATCH 1/2] build: bake the pinned nuclei template set into the image nuclei carries no templates in the binary: on first run it clones projectdiscovery/nuclei-templates into $HOME/nuclei-templates. Where the process cannot reach github.com that install fails softly. It logs nuclei-templates are not installed, installing... Could not find template '.../nuclei-templates': no templates found in path and exits 0, so a scan starts against an empty template set and looks like a broken tool rather than a missing one. Egress to github.com is exactly what an allowlist blocks, and an agent-run scan never has the root home the image is built with: the executor's HOME is /app/data/exec-home (server/execpriv_unix.go). Bake the set in the tools stage at a fixed path, pinned by tag and asserted by commit so a moved tag fails the build, and point NUCLEI_TEMPLATES_DIR at it in the runtime stage. The lookup then does not depend on HOME or on the user the process runs as, and no runtime egress is needed. v10.5.1 is 14,104 YAML templates / 84 MB on disk, against the image's current ~6.5 GB. The build now asserts the count twice: more than 10,000 files in the tools stage, and a non-empty `nuclei -tl -silent` listing in the runtime stage, which is what catches the env var being dropped later. --- Dockerfile | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 183f8cb..87993ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -102,6 +102,30 @@ RUN set -eux; \ if [ "$commit" != "$SQLMAP_COMMIT" ]; then echo "sqlmap commit mismatch: want $SQLMAP_COMMIT got $commit" >&2; exit 1; fi; \ rm -rf /opt/sqlmap/.git +# -------------------------------------------------------- nuclei templates --- +# nuclei ships no templates in the binary: on first run it clones +# projectdiscovery/nuclei-templates into $HOME/nuclei-templates. Where the process +# cannot reach github.com that install fails softly — it logs "nuclei-templates are +# not installed, installing...", then "no templates found in path", and exits 0, so a +# scan starts with an empty template set and looks like a broken tool. That is the +# normal case behind an egress allowlist, and the case for every agent-run scan: the +# executor's HOME is /app/data/exec-home, not the root-owned home the image is +# built with. Bake the set at a fixed path instead, and point nuclei at it with +# NUCLEI_TEMPLATES_DIR in the runtime stage, so the lookup does not depend on HOME or +# on which user the process runs as. Tag and commit are both pinned and asserted: a +# moved tag fails the build rather than silently changing the template set. +ARG NUCLEI_TEMPLATES_VERSION=v10.5.1 +ARG NUCLEI_TEMPLATES_COMMIT=79fb682760ab3d5b0e22afbb44709353cbebf023 +RUN set -eux; \ + git clone --quiet --depth 1 --branch "$NUCLEI_TEMPLATES_VERSION" \ + https://github.com/projectdiscovery/nuclei-templates /opt/nuclei-templates; \ + commit="$(git -C /opt/nuclei-templates rev-parse HEAD)"; \ + if [ "$commit" != "$NUCLEI_TEMPLATES_COMMIT" ]; then echo "nuclei-templates commit mismatch: want $NUCLEI_TEMPLATES_COMMIT got $commit" >&2; exit 1; fi; \ + rm -rf /opt/nuclei-templates/.git; \ + count="$(find /opt/nuclei-templates -name '*.yaml' | wc -l)"; \ + echo "baked nuclei templates: $count"; \ + test "$count" -gt 10000 + # ---------------------------------------------------------------- runtime --- FROM python:3.12-slim-bookworm ARG TARGETARCH @@ -131,13 +155,22 @@ RUN set -eux; \ tar -xJf "/tmp/$asset" -C /usr/local --strip-components=1 --no-same-owner; \ rm -f "/tmp/$asset" /tmp/SHASUMS256.txt; \ node --version; npm --version -# Pinned, checksum-verified recon binaries and the sqlmap checkout from the tools stage. +# Pinned, checksum-verified recon binaries and the sqlmap checkout from the tools stage, +# plus the baked nuclei template set (see the tools stage for why it is baked). COPY --from=tools /out/ /usr/local/bin/ COPY --from=tools /opt/sqlmap /opt/sqlmap +COPY --from=tools /opt/nuclei-templates /opt/nuclei-templates +# Read by nuclei in preference to $HOME/nuclei-templates, so root and the executor +# resolve the same set. The directory stays root-owned and world-readable; scans +# never need to write to it. +ENV NUCLEI_TEMPLATES_DIR=/opt/nuclei-templates RUN set -eux; \ ln -s /opt/sqlmap/sqlmap.py /usr/local/bin/sqlmap; \ nuclei -version >/dev/null; httpx -version; subfinder -version; katana -version; \ - ffuf -V >/dev/null; dalfox --version >/dev/null; sqlmap --version >/dev/null + ffuf -V >/dev/null; dalfox --version >/dev/null; sqlmap --version >/dev/null; \ + templates="$(nuclei -tl -silent | wc -l)"; \ + echo "nuclei templates visible at build time: $templates"; \ + test "$templates" -gt 10000 # bbot recursive recon orchestrator (#117): blacklanternsecurity/bbot, AGPL-3.0 # (same license as ARTEX; standalone CLI dependency, not linked code). Pinned From 12d208dd537f1e385ee785d6d3233d2ff18e97f5 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Sun, 22 Nov 2026 15:00:44 +0000 Subject: [PATCH 2/2] build: keep the baked nuclei template set frozen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bake asserted the pinned commit but nothing stopped nuclei from replacing the set afterwards, at either end of the image's life. Build: `nuclei -tl` runs the automatic nuclei/templates update check before it lists, so the check could download the latest release into the layer we were about to inspect. `-duc` (-disable-update-check) makes it a read. Runtime: a start with network access runs the same check, and a tree with no version metadata counts as outdated, so it rewrites /opt/nuclei-templates in the container's writable layer — tens of MB for a set the bake already provides. DISABLE_NUCLEI_TEMPLATES_PUBLIC_DOWNLOAD=true is the switch nuclei reads (internal/runner/options.go sets PublicTemplateDisableDownload from it; both installTemplatesAt and updateTemplatesAt return early on DisablePublicTemplates, pkg/installer/template.go), so neither path touches the tree. Verified on a full image build of this Dockerfile (nuclei v3.11.1, template set v10.5.1 / 79fb682): - build time: `nuclei -tl -silent -duc` -> 13,899 templates, check passes. - frozen: digest over all 14,481 files under /opt/nuclei-templates (84 MB) is identical before and after `nuclei -tl -silent`, `nuclei -target 127.0.0.1:1` and a scan against an unresolvable target, with network available. - unprivileged: as uid 4242 with HOME=/tmp/exec-home the same listing still returns 13,899 templates, tree unchanged — the lookup does not depend on HOME. - counterfactual: with DISABLE_NUCLEI_TEMPLATES_PUBLIC_DOWNLOAD cleared, one `nuclei -tl -silent` rewrites the tree (84 MB -> 91 MB, digest changes, count moves 13,687 -> 13,808). That is what the variable prevents. --- Dockerfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87993ab..698e5eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -162,13 +162,20 @@ COPY --from=tools /opt/sqlmap /opt/sqlmap COPY --from=tools /opt/nuclei-templates /opt/nuclei-templates # Read by nuclei in preference to $HOME/nuclei-templates, so root and the executor # resolve the same set. The directory stays root-owned and world-readable; scans -# never need to write to it. -ENV NUCLEI_TEMPLATES_DIR=/opt/nuclei-templates +# never need to write to it. The second variable keeps the set frozen: without it a +# start with network access runs the routine template update against the public +# repository, which rewrites the baked tree (and, on a slow link, adds tens of MB to +# the writable layer for a result the bake already provides). +ENV NUCLEI_TEMPLATES_DIR=/opt/nuclei-templates \ + DISABLE_NUCLEI_TEMPLATES_PUBLIC_DOWNLOAD=true +# -duc is what keeps this a check rather than an update: `nuclei -tl` runs the +# automatic nuclei/templates update check first, so it could replace the pinned set +# with the latest release inside the layer we are about to inspect. RUN set -eux; \ ln -s /opt/sqlmap/sqlmap.py /usr/local/bin/sqlmap; \ nuclei -version >/dev/null; httpx -version; subfinder -version; katana -version; \ ffuf -V >/dev/null; dalfox --version >/dev/null; sqlmap --version >/dev/null; \ - templates="$(nuclei -tl -silent | wc -l)"; \ + templates="$(nuclei -tl -silent -duc | wc -l)"; \ echo "nuclei templates visible at build time: $templates"; \ test "$templates" -gt 10000