mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-21 22:19:29 +00:00
feat(model): first repository measurement, and the four things it found
contributor-scan 2.2. VAmPI at a pinned commit, scanned whole rather than as excerpts, with benchmarks/repos/measure.py recording build time, query time, arbitration time, peak memory, cost, unjudged regions, and whether each known vulnerability was found and at which rung. The corpus could not have found any of this. Every defect below needs a repository to become visible, and three of them were invisible behind a passing test suite. **The batch path was unreachable.** query_batch was implemented, tested and committed while CpgResult exposed only `run`, so the driver's capability check found nothing and fell back to one JVM per region-family: the first attempt at this measurement ran eighteen minutes on 520 lines, issuing `--param function=` one at a time. Every test called query_batch directly, so none of them noticed. CpgResult now carries run_batch and a test asserts the capability is reachable through the object the driver is handed. The earlier 275s->106s improvement attributed to batching came from region deduplication alone. **The budget stopped free work.** It bounds model calls, but was enforced by breaking the region loop -- spending a paid limit to stop unpaid CPG arbitration. 6 of 22 regions were examined and VAmPI's BOLA, which the graph entails for nothing, was never reached. It now withholds the judge only. 22 of 22 regions arbitrated, 17 counted as regions_unasked (silent because unaffordable is not silent because decided), and the BOLA is entailed by the model layer. **A region with no function asked about the whole repository.** Sending function="" matched every hit in the tree and the driver attributed that answer to whoever asked: one `host='0.0.0.0'` in app.py became eight identical entailed findings in eight files that do not contain it. Queries now carry the region's file. Entailed findings 14 -> 7, query time 70.9s -> 40.9s. The single-request form stays unscoped so the committed pair measurements remain reproducible. **The JVM had no heap bound.** Joern claimed a quarter of physical RAM and runs were killed under memory pressure at different points, so the numbers described the host rather than the engine. -J-Xmx2048m by default, OPENULTRASAST_CPG_HEAP_MB to raise it. Also: arbitrated findings carried `function:line` where the report layer read `path:line`, so every entailed finding reached a contributor with a function name where its file belonged; and the witness line was parsed by splitting on a comma, which produced sites like `config.py:17): permissive literal '0.0.0.0':?`. Reading: GO on one CPG per repository -- 6.2s to build, 177s end to end, 869MB, $0.0067, nothing infeasible. NO-GO on region-scoped taint as the only shape: VAmPI's SQL injection runs from a handler parameter into a function in another module, and a per-function region sees neither end. That is the ordinary shape of a real injection bug, so it is recorded as task 2.4 along with three smaller defects this run exposed. Gates byte-identical. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
co-authored by
Claude Opus 5
parent
8c387306be
commit
177c7f3719
@@ -22,6 +22,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
@@ -64,7 +65,9 @@ class ModelFinding:
|
||||
contradiction: str = ""
|
||||
|
||||
|
||||
def _arbitrate(cpg: CpgResult, spec: TaintSpec | DominanceSpec | ConfigSpec, *, function: str, parameter_sources: bool) -> Verdict | None:
|
||||
def _arbitrate(
|
||||
cpg: CpgResult, spec: TaintSpec | DominanceSpec | ConfigSpec, *, path: str, function: str, parameter_sources: bool
|
||||
) -> Verdict | None:
|
||||
"""Route a family to the arbiter that can actually decide it.
|
||||
|
||||
Dispatching on the spec type rather than on a family name keeps this honest: a family without an arbiter
|
||||
@@ -75,14 +78,15 @@ def _arbitrate(cpg: CpgResult, spec: TaintSpec | DominanceSpec | ConfigSpec, *,
|
||||
if isinstance(spec, DominanceSpec):
|
||||
return dominance_verdict(cpg, spec, function=function)
|
||||
if isinstance(spec, ConfigSpec):
|
||||
return config_verdict(cpg, spec, function=function)
|
||||
return taint_verdict(cpg, spec, function=function, parameter_sources=parameter_sources)
|
||||
return config_verdict(cpg, spec, function=function, file=path)
|
||||
return taint_verdict(cpg, spec, function=function, file=path, parameter_sources=parameter_sources)
|
||||
|
||||
|
||||
def scan_region(
|
||||
cpg: CpgResult,
|
||||
spec: TaintSpec | DominanceSpec | ConfigSpec,
|
||||
*,
|
||||
path: str = "",
|
||||
function: str = "",
|
||||
client: Any | None = None,
|
||||
model: str = "",
|
||||
@@ -90,11 +94,11 @@ def scan_region(
|
||||
parameter_sources: bool = False,
|
||||
) -> list[ModelFinding]:
|
||||
"""Findings for one region and family, ordered strongest first."""
|
||||
answer = _arbitrate(cpg, spec, function=function, parameter_sources=parameter_sources)
|
||||
answer = _arbitrate(cpg, spec, path=path, function=function, parameter_sources=parameter_sources)
|
||||
|
||||
if answer is not None and answer.rung is Rung.ENTAILED:
|
||||
# The graph decided. No model call, and no candidate needs asking about: this region has its finding.
|
||||
return [ModelFinding(site=_site(function, answer.witness), family=spec.family, rung=Rung.ENTAILED, witness=answer.witness)]
|
||||
return [ModelFinding(site=_site(path, function, answer.witness), family=spec.family, rung=Rung.ENTAILED, witness=answer.witness)]
|
||||
|
||||
if answer is not None:
|
||||
# A real flow through a sanitizer. Whether it suffices is the residual, and the model HAS coverage
|
||||
@@ -103,7 +107,9 @@ def scan_region(
|
||||
return []
|
||||
said = _ask(client, model, residual_question(spec, answer.witness, function))
|
||||
if said:
|
||||
return [ModelFinding(site=_site(function, answer.witness), family=spec.family, rung=Rung.CORROBORATED, witness=answer.witness)]
|
||||
return [
|
||||
ModelFinding(site=_site(path, function, answer.witness), family=spec.family, rung=Rung.CORROBORATED, witness=answer.witness)
|
||||
]
|
||||
return []
|
||||
|
||||
# The model resolved nothing. It is SILENT, not negative — so the enumerator's candidates are put to the
|
||||
@@ -194,9 +200,22 @@ def _ask(client: Any, model: str, question: str) -> bool | None:
|
||||
return bool(payload["vulnerable"]) if isinstance(payload, Mapping) and isinstance(payload.get("vulnerable"), bool) else None
|
||||
|
||||
|
||||
def _site(function: str, witness: str) -> str:
|
||||
line = witness.partition("(line ")[2].split(",")[0].strip(") ") if "(line " in witness else "?"
|
||||
return f"{function or '?'}:{line}"
|
||||
_LINE_IN_WITNESS = re.compile(r"\(line (\d+)")
|
||||
|
||||
|
||||
def _site(path: str, function: str, witness: str) -> str:
|
||||
"""``path:line:function`` -- the same shape a candidate id carries, because one consumer parses both.
|
||||
|
||||
An arbitrated finding used to be ``function:line``, which the report layer then read as ``path:line``:
|
||||
every entailed finding arrived with a function name where its file belonged and no line at all. A
|
||||
contributor cannot open that, and nothing downstream can match it against a known location.
|
||||
"""
|
||||
# A regex, because the witness is prose and the delimiter after the number varies: "(line 17,"
|
||||
# in one family and "(line 17):" in another. Splitting on a comma produced sites like
|
||||
# `config.py:17): permissive literal '0.0.0.0':?`.
|
||||
found = _LINE_IN_WITNESS.search(witness)
|
||||
line = found.group(1) if found else "?"
|
||||
return f"{path or '?'}:{line}:{function or '?'}"
|
||||
|
||||
|
||||
__all__ = ["CANDIDATE_QUESTION", "MAX_JUDGED_CANDIDATES", "ModelFinding", "residual_question", "scan_region"]
|
||||
|
||||
Reference in New Issue
Block a user