Skip to content

The worked pipeline

8 min readRecon Atlas

Stages are easier to follow once you see them wired together. This is the whole auto-triage pipeline in one script, auto-triage.sh, about 210 lines. It refuses to run without scope, policy and config files. It runs eight stages with a timeout each under one lock and one run log, and delivers critical and high findings at once and the rest in a digest. A test script proves that it sends nothing when scope is missing.


Stage Tool Noise Input Output Failure mode
0. Checks bash Passive scope/in-scope.txt, scope/out-of-scope.txt, scope/policy.env, etc/score.conf Nothing, or a FATAL line Any missing or invalid file: exit 3, nothing sent. Missing tool: exit 4. Lock held: exit 5
1. Enumerate subfinder Passive Wildcard roots from in-scope.txt hosts.txt, new-hosts.txt, state/hosts.txt Timeout after 30 min: partial list used. No in-scope hosts at all: exit 6
2. Resolve dnsx Light active hosts.txt resolved.txt Timeout after 20 min: partial list. Bad resolvers: fewer hosts, visible in the log count
3. Probe httpx Light active resolved.txt httpx.json, live.txt Timeout after 40 min: partial JSON. Redirects are not followed, so probing cannot leave scope
4. Score jq, awk Passive httpx.json, new-hosts.txt, state/cve-tech.txt, score.conf queue.tsv Broken regex in config: empty queue, scan skipped, logged
5. Scan nuclei Heavy active Top MAX_TARGETS of queue.tsv nuclei.jsonl Timeout after 90 min: partial findings kept. Empty queue: stage skipped
6. Dedup jq, sha1sum, grep Passive nuclei.jsonl, state/ledger.txt, state/suppress.txt new-findings.jsonl A changed Nuclei JSON field name: fingerprints change, old findings alert once more
7. Verify nuclei Light active new-findings.jsonl evidence/<fp>/, triage.tsv Re-run timeout after 2 min: finding kept as unconfirmed
8. Deliver notify Passive triage.tsv Messages, digest/queue.tsv, state/ledger.txt, current, state/heartbeat notify fails: fingerprint not added to the ledger, so the next run alerts again

It builds on the recon workflow and monitoring guide, and uses the scope filter from Part 4, the fingerprints from Part 2, the formula from Part 5 and the evidence layout from Part 6.

  1. Install the tools from field kit setup: subfinder, dnsx, httpx, nuclei, notify and anew, plus jq. flock, timeout and sha1sum ship with Debian and Ubuntu.

  2. Create the layout and save the script.

    Terminal window
    # Folders for the pipeline root and one program called "example"
    mkdir -p ~/pipeline/{bin,etc,tests} ~/pipeline/programs/example/scope
    Terminal window
    # After saving the script below as ~/pipeline/bin/auto-triage.sh, make it executable
    chmod +x ~/pipeline/bin/auto-triage.sh
  3. Write the three scope files from the program policy. The format is in Part 4. Include AUTOMATED_SCANNING=yes in policy.env only if the policy allows automated scanning.

  4. Save the scoring config from Part 5 as ~/pipeline/etc/score.conf.

  5. Seed the host list once, so the first run does not mark every host as new.

    Terminal window
    # Record today's hosts as already seen, without alerting (passive enumeration only)
    sed -nE 's/^\*\.([^ #]+).*/\1/p' ~/pipeline/programs/example/scope/in-scope.txt | subfinder -silent | PROGRAM=example ~/pipeline/bin/inscope | sort -u > ~/pipeline/programs/example/state/hosts.txt
  6. Run the fail-closed test, then the pre-flight, then one run while you watch.

    Terminal window
    # First run, watched: follow the run log as it is written
    PROGRAM=example ~/pipeline/bin/auto-triage.sh & sleep 2; tail -f ~/pipeline/programs/example/runs/*/run.log
  7. Schedule it (Part 3), and schedule auto-triage.sh digest once a day.

auto-triage.sh
#!/usr/bin/env bash
# auto-triage.sh: collect, dedup, score, scan, verify and deliver for ONE program.
# Usage: PROGRAM=example auto-triage.sh full run
# PROGRAM=example auto-triage.sh digest send and clear the digest queue
# Exit codes: 0 ok, 2 usage, 3 config or scope missing (fail closed),
# 4 missing tool, 5 another run holds the lock, 6 a required stage failed.
# Only point this at programs whose policy allows automated scanning.
set -uo pipefail
export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin:$HOME/.pdtm/go/bin"
# ---------- paths: everything for a program lives under one folder ----------
PIPE_ROOT="${PIPE_ROOT:-$HOME/pipeline}"
PROGRAM="${PROGRAM:-}"
MODE="${1:-run}"
STAMP=$(date -u +%Y-%m-%dT%H%M%SZ)
P="$PIPE_ROOT/programs/$PROGRAM"
SCOPE_IN="$P/scope/in-scope.txt"
SCOPE_OUT="$P/scope/out-of-scope.txt"
POLICY="$P/scope/policy.env"
SCORE_CONF="$PIPE_ROOT/etc/score.conf"
[[ -f "$P/etc/score.conf" ]] && SCORE_CONF="$P/etc/score.conf" # per-program override
RUN="$P/runs/$STAMP"
# ---------- logging: one run log, every line timestamped ----------
LOG=/dev/stderr
log() { printf '[%s] %s\n' "$(date -u +%FT%TZ)" "$*" >>"$LOG"; }
die() { log "FATAL $2"; [[ "$LOG" != /dev/stderr ]] && printf 'FATAL %s\n' "$2" >&2; exit "$1"; }
# ---------- fail closed: no program, no scope, no policy means no run ----------
[[ -n "$PROGRAM" && "$PROGRAM" =~ ^[a-z0-9_-]+$ ]] || die 2 "usage: PROGRAM=<name> $0 [run|digest]"
has_rules() { [[ -f "$1" ]] && grep -qvE '^[[:space:]]*(#|$)' "$1"; }
has_rules "$SCOPE_IN" || die 3 "scope: $SCOPE_IN missing or empty; refusing to run"
[[ -f "$SCOPE_OUT" ]] || die 3 "scope: $SCOPE_OUT missing; create it, even empty, on purpose"
[[ -f "$POLICY" ]] || die 3 "policy: $POLICY missing; refusing to guess rate limits"
[[ -f "$SCORE_CONF" ]] || die 3 "config: $SCORE_CONF missing"
# shellcheck source=/dev/null
source "$POLICY" # sets RATE, AUTOMATED_SCANNING, CONCURRENCY, NOTIFY_ID, NUCLEI_TAGS, MAX_TARGETS
[[ "${RATE:-}" =~ ^[0-9]+$ && "$RATE" -gt 0 ]] || die 3 "policy: RATE must be a positive integer"
[[ "${AUTOMATED_SCANNING:-}" == yes ]] || die 3 "policy: AUTOMATED_SCANNING is not yes; refusing active stages"
CONCURRENCY="${CONCURRENCY:-5}"; MAX_TARGETS="${MAX_TARGETS:-300}"
NOTIFY_ID="${NOTIFY_ID:-triage}"; NUCLEI_TAGS="${NUCLEI_TAGS:-exposure,misconfig,panel,takeover}"
for t in subfinder dnsx httpx nuclei anew notify jq flock timeout sha1sum; do
command -v "$t" >/dev/null || die 4 "missing tool: $t"
done
# ---------- lock: one run per program at a time, released when the script exits ----------
mkdir -p "$P"/{state,runs,evidence,digest,logs}
exec 9>"$P/state/.lock"
flock -n 9 || die 5 "another run for $PROGRAM holds the lock"
touch "$P/state"/{hosts.txt,ledger.txt,suppress.txt,cve-tech.txt}
# ---------- digest mode: send everything queued below high, then clear the queue ----------
if [[ "$MODE" == digest ]]; then
q="$P/digest/queue.tsv"
[[ -s "$q" ]] || { log "digest: queue empty"; exit 0; }
{ echo "Digest $PROGRAM $(date -u +%F): $(wc -l <"$q") findings"
awk -F'\t' '{c[$1]++} END {for (s in c) printf " %s: %d\n", s, c[s]}' "$q"
sort -t$'\t' -k1,1 "$q" | cut -f1,2,3 | head -40
} | notify -id "$NOTIFY_ID" -bulk -silent || die 6 "digest: notify failed, queue kept"
mv "$q" "$P/digest/sent-$STAMP.tsv"; exit 0
fi
mkdir "$RUN" 2>/dev/null || die 6 "run folder $RUN already exists"
mkdir "$RUN/logs"; LOG="$RUN/run.log"
log "start program=$PROGRAM rate=$RATE run=$RUN"
# stage <name> <seconds> <cmd...>: timeout on every tool, stderr to a per-stage log
stage() {
local name=$1 secs=$2; shift 2
timeout -k 30 "$secs" "$@" 2>>"$RUN/logs/$name.err"; local rc=$?
case $rc in 0) ;; 124) log "WARN $name timed out after ${secs}s" ;;
*) log "WARN $name exited $rc, see logs/$name.err" ;; esac
return $rc
}
# inscope: read hosts, host:port or URLs on stdin, print only in-scope lines.
# in-scope.txt lines: example.com (exact), *.example.com (subdomains), 192.0.2.0/24 (CIDR).
# out-of-scope.txt uses the same format and always wins.
inscope() {
awk -v IN="$SCOPE_IN" -v OUT="$SCOPE_OUT" '
function host(s) { sub(/^[A-Za-z]+:\/\//, "", s); sub(/[\/?#].*$/, "", s); sub(/:[0-9]+$/, "", s); return tolower(s) }
function n(ip, a) { split(ip, a, "."); return ((a[1] * 256 + a[2]) * 256 + a[3]) * 256 + a[4] }
function load(f, k, line, p) {
while ((getline line < f) > 0) {
sub(/#.*/, "", line); gsub(/[ \t\r]/, "", line); line = tolower(line)
if (line == "") continue
if (line ~ /\//) { split(line, p, "/"); nc[k]++; cb[k, nc[k]] = n(p[1]); cs[k, nc[k]] = 2 ^ (32 - p[2]) }
else if (line ~ /^\*\./) { ns[k]++; suf[k, ns[k]] = substr(line, 2) }
else ex[k, line] = 1
}
}
function hit(h, k, i, s, b) {
if ((k, h) in ex) return 1
for (i = 1; i <= ns[k]; i++) { s = suf[k, i]
if (length(h) > length(s) && substr(h, length(h) - length(s) + 1) == s) return 1 }
if (h ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) for (i = 1; i <= nc[k]; i++) {
b = cb[k, i] - cb[k, i] % cs[k, i]; if (n(h) >= b && n(h) < b + cs[k, i]) return 1 }
return 0
}
BEGIN { load(IN, "in"); load(OUT, "out") }
{ h = host($1); if (!hit(h, "out") && hit(h, "in")) print }'
}
# ---------- stage 1: passive enumeration (Passive) ----------
sed -nE 's/^[[:space:]]*\*\.([^[:space:]#]+).*/\1/p' "$SCOPE_IN" | sort -u >"$RUN/roots.txt"
if [[ -s "$RUN/roots.txt" ]]; then
stage enum 1800 subfinder -dL "$RUN/roots.txt" -all -silent >"$RUN/subfinder.txt"
fi
sed -E 's/#.*//; s/[[:space:]]//g' "$SCOPE_IN" | grep -vE '^$|/|\*' >>"$RUN/subfinder.txt" # exact hosts
inscope <"$RUN/subfinder.txt" | tr '[:upper:]' '[:lower:]' | sort -u >"$RUN/hosts.txt"
anew "$P/state/hosts.txt" <"$RUN/hosts.txt" >"$RUN/new-hosts.txt"
log "enum: $(wc -l <"$RUN/hosts.txt") in-scope hosts, $(wc -l <"$RUN/new-hosts.txt") new"
[[ -s "$RUN/hosts.txt" ]] || die 6 "enum produced no in-scope hosts; check logs/enum.err"
# ---------- stage 2: resolution (Light active, DNS only) ----------
stage resolve 1200 dnsx -l "$RUN/hosts.txt" -silent -t "$CONCURRENCY" >"$RUN/resolved-raw.txt"
inscope <"$RUN/resolved-raw.txt" | sort -u >"$RUN/resolved.txt"
# ---------- stage 3: HTTP probing (Light active). No -fr: a redirect can leave scope ----------
stage probe 2400 httpx -l "$RUN/resolved.txt" -sc -title -td -server -cl -ip -cdn \
-rl "$RATE" -t "$CONCURRENCY" -timeout 10 -retries 1 -j -silent >"$RUN/httpx.json"
jq -r 'select(.url != null) | .url' "$RUN/httpx.json" | inscope | sort -u >"$RUN/live.txt"
log "probe: $(wc -l <"$RUN/live.txt") live in-scope URLs"
# ---------- stage 4: scoring with the weights in score.conf (Passive, local only) ----------
jq -r '[.url, (.port // "" | tostring), (.status_code // 0 | tostring), (.title // "-"),
((.tech // []) | join(",")), (.content_length // 0 | tostring), (.cdn // false | tostring)]
| @tsv' "$RUN/httpx.json" | inscope >"$RUN/hosts.tsv"
awk -F'\t' -v OFS='\t' '
FILENAME == ARGV[1] { if ($0 ~ /^[a-z_]+=/) { split($0, kv, "="); sub(/[ \t]+#.*$/, "", kv[2]); w[kv[1]] = kv[2] } next }
FILENAME == ARGV[2] { isnew[$1] = 1; next }
FILENAME == ARGV[3] { if ($0 != "") fresh[tolower($0)] = 1; next }
FNR == 1 && FILENAME == ARGV[4] { pass++ }
pass == 1 { seen[$6]++; rows++; next }
{ u = $1; h = u; sub(/^[a-z]+:\/\//, "", h); sub(/[:\/].*$/, "", h); t = tolower($4); s = 0; why = ""
if ((h " " t) ~ w["kw_staging"]) { s += w["w_staging"]; why = why "staging," }
if (t ~ w["kw_panel"]) { s += w["w_panel"]; why = why "panel," }
if ($2 != "" && $2 != 80 && $2 != 443) { s += w["w_port"]; why = why "port" $2 "," }
if ($3 ~ w["odd_status"]) { s += w["w_status"]; why = why "status" $3 "," }
if (h in isnew) { s += w["w_new"]; why = why "new," }
if (rows >= 20 && seen[$6] == 1) { s += w["w_unique_len"]; why = why "unique-length," }
if ($7 == "true") { s += w["w_cdn"]; why = why "cdn," }
n = split(tolower($5), tech, ","); for (i = 1; i <= n; i++) { sub(/:.*/, "", tech[i])
if (tech[i] in fresh) { s += w["w_cve"]; why = why "fresh-cve," ; break } }
print s, u, $3, $4, (why == "" ? "-" : why) }
' "$SCORE_CONF" "$RUN/new-hosts.txt" "$P/state/cve-tech.txt" "$RUN/hosts.tsv" "$RUN/hosts.tsv" \
| sort -t$'\t' -k1,1nr >"$RUN/queue.tsv"
log "score: top entry: $(head -1 "$RUN/queue.tsv" | cut -f1,2)"
# ---------- stage 5: filtered Nuclei pass on the top-scored URLs (Heavy active) ----------
cut -f2 "$RUN/queue.tsv" | head -n "$MAX_TARGETS" | inscope >"$RUN/scan-targets.txt"
if [[ -s "$RUN/scan-targets.txt" ]]; then
stage scan 5400 nuclei -l "$RUN/scan-targets.txt" -tags "$NUCLEI_TAGS" -s medium,high,critical \
-etags dos,fuzz,intrusive -rl "$RATE" -c "$CONCURRENCY" -bs "$CONCURRENCY" \
-timeout 10 -retries 1 -jsonl -silent -o "$RUN/nuclei.jsonl"
fi
touch "$RUN/nuclei.jsonl"
# ---------- stage 6: fingerprint and dedup against the ledger and suppression list ----------
# fingerprint = template id | host and path | matcher name | sorted extracted values
fp_key='[.["template-id"], (.["matched-at"] // "" | sub("^[a-z]+://"; "")), (.["matcher-name"] // ""),
((.["extracted-results"] // []) | sort | join(","))] | join("|")'
fp_of() { jq -r "$fp_key" | while IFS= read -r k; do printf '%s\n' "$k" | sha1sum | cut -c1-16; done; }
: >"$RUN/new-findings.jsonl"
while IFS= read -r line; do
fp=$(fp_of <<<"$line"); tid=$(jq -r '.["template-id"]' <<<"$line")
url=$(jq -r '.["matched-at"] // ""' <<<"$line")
[[ -n "$(printf '%s\n' "$url" | inscope)" ]] || { log "drop out-of-scope match $url"; continue; }
h=$(printf '%s\n' "$url" | sed -E 's#^[a-z]+://##; s#[:/?].*##')
grep -qxF "$fp" "$P/state/ledger.txt" && continue # seen before
grep -qxF -e "$fp" -e "tid:$tid" -e "host:$h" "$P/state/suppress.txt" && continue # suppressed
jq -c --arg fp "$fp" '. + {fp: $fp}' <<<"$line" >>"$RUN/new-findings.jsonl"
done <"$RUN/nuclei.jsonl"
log "dedup: $(wc -l <"$RUN/nuclei.jsonl") raw, $(wc -l <"$RUN/new-findings.jsonl") new"
# ---------- stage 7: verification re-run and evidence folders (Light active) ----------
: >"$RUN/triage.tsv"
while IFS= read -r line; do
fp=$(jq -r .fp <<<"$line"); tid=$(jq -r '.["template-id"]' <<<"$line")
url=$(jq -r '.["matched-at"]' <<<"$line"); sev=$(jq -r '.info.severity' <<<"$line")
ev="$P/evidence/$fp"; mkdir -p "$ev"
printf '%s\n' "$line" >"$ev/finding.json"
base=$(sed -E 's#^([a-z]+://[^/?]+).*#\1#' <<<"$url") # templates add their own path
: >"$ev/verify.jsonl"
stage verify 120 nuclei -u "$base" -id "$tid" -rl 2 -jsonl -silent -o "$ev/verify.jsonl"
status=unconfirmed; src="$ev/finding.json"
if fp_of <"$ev/verify.jsonl" | grep -qx "$fp"; then status=rematched; src="$ev/verify.jsonl"; fi
jq -r '.request // empty' "$src" | head -c 20000 >"$ev/request.txt"
jq -r '.response // empty' "$src" | head -c 50000 >"$ev/response.txt"
jq -r '(.["extracted-results"] // [])[]' "$ev/finding.json" >"$ev/matched.txt"
printf 'status=%s\nseverity=%s\ntemplate=%s\nurl=%s\nrun=%s\n' "$status" "$sev" "$tid" "$url" "$STAMP" >"$ev/meta.txt"
printf '%s\t%s\t%s\t%s\t%s\n' "$sev" "$tid" "$url" "$status" "$fp" >>"$RUN/triage.tsv"
done <"$RUN/new-findings.jsonl"
# ---------- stage 8: deliver. Critical and high now, the rest to the digest ----------
while IFS=$'\t' read -r sev tid url status fp; do
case $sev in
critical|high)
printf '[%s] %s | %s | %s\nverified: %s | evidence: evidence/%s | run: %s\n' \
"${sev^^}" "$PROGRAM" "$tid" "$url" "$status" "$fp" "$STAMP" \
| notify -id "$NOTIFY_ID" -bulk -silent || { log "WARN notify failed for $fp"; continue; } ;;
*) printf '%s\t%s\t%s\t%s\t%s\n' "$sev" "$tid" "$url" "$status" "$fp" >>"$P/digest/queue.tsv" ;;
esac
echo "$fp" >>"$P/state/ledger.txt" # recorded only once delivered or queued
done <"$RUN/triage.tsv"
sort -u -o "$P/state/ledger.txt" "$P/state/ledger.txt"
# ---------- finish: stable pointer to the newest run, and a heartbeat ----------
ln -sfn "$RUN" "$P/current"
printf '%s ok findings=%s\n' "$STAMP" "$(wc -l <"$RUN/triage.tsv")" >"$P/state/heartbeat"
log "done: $(wc -l <"$RUN/triage.tsv") new findings, queue at $RUN/queue.tsv"
critical exposed-env https://dev.example.com/.env rematched 2d7bbe2f093b189d

Stage 8 writes that row to triage.tsv: severity, template id, matched URL, verification status, fingerprint. rematched means stage 7 saw the same fingerprint again. The row does not say the leaked value is real, current, or sensitive. You decide that in manual.md, by hand.

Every block can fail. Here is what happens, and why the design chose that outcome.

Block What can go wrong What the script does Why
Paths PIPE_ROOT points somewhere unexpected Scope checks fail, exit 3 A wrong root has no scope files, so it fails closed instead of creating a fresh, empty program
Fail-closed checks Missing or empty scope, missing out-of-scope, missing policy, bad RATE, AUTOMATED_SCANNING not yes, missing score config Exit 3 before any tool is checked or run The test proves no stub is ever called in these cases
PROGRAM name Contains / or .. Exit 2 The name becomes a path; a strict pattern stops it from escaping programs/
source "$POLICY" The policy file contains commands They run, as you It is your own file. Keep it to assignments; this is the reason for that rule
Tool check A tool missing from PATH, common under cron Exit 4 with the tool’s name Better than discovering at stage 5 that Nuclei never ran
Lock A previous run still going Exit 5, nothing else happens Two runs would interleave writes to the ledger and double the traffic
Run folder Two runs start in the same second, or the clock jumps back Exit 6 An early draft stamped to the minute. Its own end-to-end test ran twice in one minute, reused the folder, and re-sent the first run’s alerts. Stamps now include seconds, and an existing folder is refused
stage helper A tool hangs timeout sends TERM, then KILL 30 s later; the run log gets a WARN with code 124 One hung tool must not eat the night
inscope Scope file has IPv6 ranges They are ignored, so IPv6 targets are dropped Dropping is the fail-closed direction
Stage 1 All data sources fail, or keys expired Exact hosts from in-scope.txt still run. If there are none, exit 6 An empty enumeration is far more often a broken source than a vanished company
Stage 2 Resolvers return junk Junk names are filtered by scope; counts drop Watch the “in-scope hosts” count in the log for sudden changes
Stage 3 A host redirects to another domain Not followed: no -fr Following redirects is how a probe leaves scope
Stage 4 A host has no title or tech jq defaults (//) fill - or empty One missing field must not break the row
Stage 4 Fewer than 20 hosts Unique-length signal switched off On small scopes every length is unique, which makes the signal meaningless
Stage 5 Templates follow redirects out of scope Matches are dropped at stage 6 and logged The traffic was already sent. Keep tags narrow, and read the “drop out-of-scope match” lines
Stage 6 Nuclei renames a JSON field Fingerprints change; findings alert once more At-least-once is the safe direction. Check field names after each Nuclei update
Stage 7 Passing the matched URL as the target Template adds its path twice and never rematches Fixed: the base URL is used. The end-to-end test with a stub that logs its -u value caught this
Stage 7 Response holds secrets Saved to evidence/, capped at 50 KB Evidence is local and private. Never commit or paste it
Stage 8 notify fails (webhook revoked, network) WARN logged, fingerprint not added to the ledger The next run tries again
Finish Script dies before this block No current update, no heartbeat The heartbeat check notices
  • Follow redirects, brute-force, port scan or fuzz. Those are heavy and need a decision per program. Add them as weekly stages with their own guards, not nightly.
  • Screenshot. Expensive in memory. It is the exercise below.
  • Report. Ever. See Part 6.

Add a screenshot stage that captures only new live hosts, so the evidence for a fresh host includes what it looked like on day one.

Requirements, in pipeline contract form:

Stage Input Output Failure mode Noise
3b. Screenshot new hosts live.txt lines whose host is in new-hosts.txt screens/ in the run folder Timeout after 20 min: keep partial screenshots, log WARN. No new hosts: skip Light active, one page load per new host

Steps:

  1. Between stage 3 and stage 4, build the input: URLs from live.txt whose host appears in new-hosts.txt. Pass the result through inscope again.

  2. Skip the stage with a log line when the input is empty. Never call a tool with an empty list.

  3. Call your screenshot tool through stage screens 1200 .... httpx has a screenshot option (-ss) and a store-response directory option; gowitness is a dedicated alternative. Check the README of whichever you use for current flags and where files are written, and keep concurrency low: headless browsers are memory-hungry.

  4. Pass the rate from policy.env to the tool.

  5. Add the new output to the artifact table, and add a line to the failure-mode table above.

  6. Run the fail-closed test again. It must still pass: your stage must sit after the checks.

Terminal window
# A starting point for step 1: new live URLs only, still scope-filtered
grep -Ff "$RUN/new-hosts.txt" "$RUN/live.txt" | inscope > "$RUN/screen-targets.txt"

grep -F matches substrings, so dev.example.com also matches old-dev.example.com. Decide whether that matters to you, and if it does, compare extracted hosts exactly with awk instead. Noticing that kind of edge is the real point of the exercise.

A design rule is only real if a test proves it. This test builds a complete fake program and stubs every tool that sends traffic: each stub only writes its own name to a log. Then it breaks one input at a time and checks two things: the exit code is 3, and no stub was called.

Save it as ~/pipeline/tests/test-fail-closed.sh.

test-fail-closed.sh
#!/usr/bin/env bash
# test-fail-closed.sh: prove auto-triage.sh sends nothing when scope or policy is missing.
# Usage: bash test-fail-closed.sh ~/pipeline/bin/auto-triage.sh
set -u
SCRIPT="${1:?usage: test-fail-closed.sh path/to/auto-triage.sh}"
T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
# 1. stub every tool that sends traffic: each stub only records that it ran
mkdir -p "$T/stubs"
for tool in subfinder dnsx httpx nuclei notify; do
printf '#!/bin/sh\necho %s >> "%s/calls.log"\n' "$tool" "$T" >"$T/stubs/$tool"
chmod +x "$T/stubs/$tool"
done
# 2. build a complete, valid fake program, so each case breaks exactly one thing
P="$T/pipeline/programs/example"
mkdir -p "$P/scope" "$T/pipeline/etc"
printf '*.example.com\n' >"$P/scope/in-scope.txt"
: >"$P/scope/out-of-scope.txt"
printf 'RATE=5\nAUTOMATED_SCANNING=yes\n' >"$P/scope/policy.env"
: >"$T/pipeline/etc/score.conf"
# 3. run the pipeline and check: expected exit code, and no stub was called
fail=0
check() {
rm -f "$T/calls.log"
out=$(PATH="$T/stubs:$PATH" PIPE_ROOT="$T/pipeline" PROGRAM=example bash "$SCRIPT" 2>&1); rc=$?
if [[ $rc -eq $2 && ! -e "$T/calls.log" ]]; then
echo "PASS $1 (exit $rc, no tool called)"
else
echo "FAIL $1 (exit $rc, expected $2)"; fail=1
[[ -e "$T/calls.log" ]] && echo " tools called: $(tr '\n' ' ' <"$T/calls.log")"
fi
echo " ${out%%$'\n'*}"
}
rm "$P/scope/in-scope.txt"
check "missing in-scope.txt" 3
printf '# copied from policy, nothing yet\n\n' >"$P/scope/in-scope.txt"
check "comment-only in-scope.txt" 3
printf '*.example.com\n' >"$P/scope/in-scope.txt"; rm "$P/scope/out-of-scope.txt"
check "missing out-of-scope.txt" 3
: >"$P/scope/out-of-scope.txt"; rm "$P/scope/policy.env"
check "missing policy.env" 3
printf 'RATE=0\nAUTOMATED_SCANNING=yes\n' >"$P/scope/policy.env"
check "zero rate in policy.env" 3
printf 'RATE=5\n' >"$P/scope/policy.env"
check "automated scanning not allowed" 3
exit $fail
Terminal window
# Run the test against the installed pipeline
bash ~/pipeline/tests/test-fail-closed.sh ~/pipeline/bin/auto-triage.sh; echo "test exit: $?"

Expected output. The temporary path and timestamps will differ; every line must say PASS and the final exit must be 0.

# Expected output of the fail-closed test
PASS missing in-scope.txt (exit 3, no tool called)
[2026-11-13T17:16:30Z] FATAL scope: /tmp/tmp.kfnNFu3op1/pipeline/programs/example/scope/in-scope.txt missing or empty; refusing to run
PASS comment-only in-scope.txt (exit 3, no tool called)
[2026-11-13T17:16:30Z] FATAL scope: /tmp/tmp.kfnNFu3op1/pipeline/programs/example/scope/in-scope.txt missing or empty; refusing to run
PASS missing out-of-scope.txt (exit 3, no tool called)
[2026-11-13T17:16:30Z] FATAL scope: /tmp/tmp.kfnNFu3op1/pipeline/programs/example/scope/out-of-scope.txt missing; create it, even empty, on purpose
PASS missing policy.env (exit 3, no tool called)
[2026-11-13T17:16:31Z] FATAL policy: /tmp/tmp.kfnNFu3op1/pipeline/programs/example/scope/policy.env missing; refusing to guess rate limits
PASS zero rate in policy.env (exit 3, no tool called)
[2026-11-13T17:16:31Z] FATAL policy: RATE must be a positive integer
PASS automated scanning not allowed (exit 3, no tool called)
[2026-11-13T17:16:31Z] FATAL policy: AUTOMATED_SCANNING is not yes; refusing active stages
test exit: 0

The plainest version of the same proof, on your real program, without the test harness:

Terminal window
# Move the scope file away, run, and confirm exit 3 and that no run folder was created
P=~/pipeline/programs/example; mv "$P/scope/in-scope.txt" /tmp/in-scope.bak; ls "$P/runs" | wc -l; PROGRAM=example ~/pipeline/bin/auto-triage.sh; echo "exit: $?"; ls "$P/runs" | wc -l; mv /tmp/in-scope.bak "$P/scope/in-scope.txt"
# Expected: the run-folder count is unchanged, and the exit code is 3
12
[2026-11-13T17:20:02Z] FATAL scope: /home/hunter/pipeline/programs/example/scope/in-scope.txt missing or empty; refusing to run
exit: 3
12

Run the test after every change to the script, and add a case each time you add a new required file. If you add the exercise stage before the checks by mistake, the test tells you at once, because a stub gets called.

Next, keep the pipeline checklists open for your first night.

Connections10 backlinks · 11 outgoingFull graph →
Open local graph around this page
Open full graph →
Click a node to open · Drag to reposition · Scroll to zoom

Recon AtlasFor authorized testing only. Your scope is the map edge.