java-topology/tools/scans/networkx.sh
russell@unturf.com db29a08762 undefect. CWE-407 — 92 sites, 42 ecosystems
B&W print-friendly diagrams + tinkerpop-0001 + wave-3 proof sections.
Squash of 94 local commits onto remote master.
2026-03-26 19:48:18 -04:00

22 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
# CWE-407 scan — NetworkX (Python graph library)
# Network mode: semitrusted
set -euo pipefail
echo "# scan=networkx host=$(hostname) date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
cd /tmp && git clone --depth 1 https://github.com/networkx/networkx networkx 2>&1 | tail -1
GRAPH_KW="tarjan|strongly.connected|dfs\b|scc\b|topolog|cycle|reachab|postorder|dominator|digraph|shortest.path"
PY_MEM="[^a-z]in (path|stack|visited|seen|queue|ancestors)\b|not in (path|stack|visited)\b|path\.index\b|stack\.index\b"
echo "# roots: /tmp/networkx/networkx/algorithms"
find /tmp/networkx/networkx/algorithms -name "*.py" | sort | while IFS= read -r f; do
gl=$(grep -inE "$GRAPH_KW" "$f" 2>/dev/null | cut -d: -f1 | head -5 || true)
[ -z "$gl" ] && continue
while IFS= read -r ln; do
s=$(( ln > 20 ? ln - 20 : 1 )); e=$(( ln + 20 ))
hit=$(sed -n "${s},${e}p" "$f" 2>/dev/null | grep -iE "$PY_MEM" | head -1 | sed 's/^\s*//' || true)
[ -n "$hit" ] && echo "CANDIDATE ${f}:${ln} ${hit}"
done <<< "$gl"
done
echo "# scan complete"