mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-04 18:58:18 +00:00
feat(model): a region that spans the flow, not just a function
contributor-scan 2.4, closing the no-go task 2.2 recorded. VAmPI's SQL injection is a request parameter reaching `get_by_username` in api_views/users.py, passed to `User.get_user` in models/user_model.py, interpolated into a query string and executed there. Source and sink are in different functions and different modules. Regions were per-function, so neither region saw both ends and the engine was silent on the most ordinary shape a real injection bug has. `reachableByFlows` was never the limitation -- it follows calls already. The limitation was the QUESTION. Sinks were filtered to the labeled function's own body, so a crossing flow had no sink to end at. Three changes, each with a reason it is sound rather than convenient: **An entry point is the trust boundary.** parameter_sources was off for repository scans because a repository's parameters are not all attacker input. An entry point's are, by definition -- that is what makes it an entry point. The driver turns it on only for regions the mapper found and named, and leaves it off for walker fallbacks and for named functions that are not entry points. **Sinks may sit below the handler.** taint.sc admits sinks in methods reachable from the labeled method through the call graph, bounded at ENTRY_POINT_CALL_DEPTH = 3: handler -> service -> data access, which is where these bugs live. Unbounded would make the question about most of the repository rather than about this entry point, and make it unaffordable. **The finding names the sink, not the asker.** A crossing flow ends in another file and another function, so Verdict carries the evidence's own `path:line:function` and the site uses it. Reporting `models/user_model.py:73:get_by_username` would name a place that does not exist: line 73 is inside get_user. Also: labeled methods are now resolved by name AND file. `get_user` exists in more than one module of a real repository, which a corpus of one-file excerpts could never surface. Measured on the same checkout and budget as 2.2: VAmPI-SQLI missed -> model_entailed at models/user_model.py:73:get_user known found 0 of 2 before 2.2's fixes, 1 of 2 in 2.2, 2 of 2 now entailed 7 -> 8 query time 40.9s -> 37.4s peak RSS 869MB -> 827MB cost $0.0067, unchanged Asking the bigger question cost nothing measurable here: file scoping and call-graph following pull in opposite directions and roughly cancel at this size. That is one 520-line repository, and VAmPI is now the repository this change was developed against -- the exact overfitting shape Req 8 exists to catch. The depth bound and the entry-point rule mean nothing general until a checkout nobody tuned against says so. 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
177c7f3719
commit
ca7b5ba370
@@ -66,7 +66,13 @@ class ModelFinding:
|
||||
|
||||
|
||||
def _arbitrate(
|
||||
cpg: CpgResult, spec: TaintSpec | DominanceSpec | ConfigSpec, *, path: str, function: str, parameter_sources: bool
|
||||
cpg: CpgResult,
|
||||
spec: TaintSpec | DominanceSpec | ConfigSpec,
|
||||
*,
|
||||
path: str,
|
||||
function: str,
|
||||
parameter_sources: bool,
|
||||
call_depth: int,
|
||||
) -> Verdict | None:
|
||||
"""Route a family to the arbiter that can actually decide it.
|
||||
|
||||
@@ -79,7 +85,7 @@ def _arbitrate(
|
||||
return dominance_verdict(cpg, spec, function=function)
|
||||
if isinstance(spec, ConfigSpec):
|
||||
return config_verdict(cpg, spec, function=function, file=path)
|
||||
return taint_verdict(cpg, spec, function=function, file=path, parameter_sources=parameter_sources)
|
||||
return taint_verdict(cpg, spec, function=function, file=path, parameter_sources=parameter_sources, call_depth=call_depth)
|
||||
|
||||
|
||||
def scan_region(
|
||||
@@ -92,13 +98,14 @@ def scan_region(
|
||||
model: str = "",
|
||||
candidates: Sequence[Mapping[str, object]] = (),
|
||||
parameter_sources: bool = False,
|
||||
call_depth: int = 0,
|
||||
) -> list[ModelFinding]:
|
||||
"""Findings for one region and family, ordered strongest first."""
|
||||
answer = _arbitrate(cpg, spec, path=path, function=function, parameter_sources=parameter_sources)
|
||||
answer = _arbitrate(cpg, spec, path=path, function=function, parameter_sources=parameter_sources, call_depth=call_depth)
|
||||
|
||||
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(path, function, answer.witness), family=spec.family, rung=Rung.ENTAILED, witness=answer.witness)]
|
||||
return [ModelFinding(site=_site(path, function, answer), 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
|
||||
@@ -107,9 +114,7 @@ def scan_region(
|
||||
return []
|
||||
said = _ask(client, model, residual_question(spec, answer.witness, function))
|
||||
if said:
|
||||
return [
|
||||
ModelFinding(site=_site(path, function, answer.witness), family=spec.family, rung=Rung.CORROBORATED, witness=answer.witness)
|
||||
]
|
||||
return [ModelFinding(site=_site(path, function, answer), 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
|
||||
@@ -203,13 +208,21 @@ def _ask(client: Any, model: str, question: str) -> bool | None:
|
||||
_LINE_IN_WITNESS = re.compile(r"\(line (\d+)")
|
||||
|
||||
|
||||
def _site(path: str, function: str, witness: str) -> str:
|
||||
def _site(path: str, function: str, verdict: Verdict) -> 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.
|
||||
|
||||
The arbiter's own ``location`` wins when it has one. Once a flow may cross into another module, the
|
||||
region that asked is no longer where the answer lives, and naming the asker would send a contributor to
|
||||
the wrong file.
|
||||
"""
|
||||
if verdict.location:
|
||||
# Already `path:line:function`, and every part of it is the sink's. See `taint._location`.
|
||||
return verdict.location
|
||||
witness = verdict.witness
|
||||
# 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':?`.
|
||||
|
||||
Reference in New Issue
Block a user