Skip to content

Commit 55e013f

Browse files
committed
feat: decide advisory host conditions from the URL's constant text
A fixed host with redirects disabled rules the call out; with redirects followed the condition stays pending, naming the chain a redirect may open. The correlation reads the same URL proof as ssrf and open-redirect.
1 parent c0062a3 commit 55e013f

6 files changed

Lines changed: 74 additions & 14 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `open-redirect` judges a flow on the destination a browser resolves from the target's constant text, with its own criteria rather than SSRF's. A reference on the current site keeps the browser there, so the flow is refuted. Such a reference is `/` followed by a character that is not a slash, a backslash, a space or a control character, as in `"/profile/" + id`; or `?`, `#`, or a relative path whose first segment holds no `:`. A fixed absolute host makes the flow a hotspot, since the input chooses the path, where that host may redirect again. Everything else stays a vulnerability, including `"/" + next`: `//evil.com` is another host. The URL facts both rules read are one shared proof, `coretrace_python.taint.urls`, and `ssrf` now reads it too, with the same verdicts. The regression corpus is unchanged: its three `open-redirect` findings redirect to values built without constant text (#168).
88

9+
### Advisories
10+
11+
- An advisory entry point may declare a `host` condition: the attacker must choose the host of the URL passed as the named argument. It is decided from the URL's constant text, the proof `ssrf` and `open-redirect` read. A fixed host with redirects disabled in the call leaves the call reachable, not exploitable. A fixed host with redirects followed keeps it exploitable, because a redirect may lead to a host the attacker controls, and the condition pending review says so. Input in the query does not choose the host. Anything else stays pending review, and so do the environment conditions. A `host` condition must name its argument and carry nothing else (#170).
12+
913
## 0.14.0 (2026-09-26)
1014

1115
### Precision

‎docs/usage.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,23 @@ a call passing a variable, or unpacking `*args` or `**kwargs`, leaves the condit
386386
pending review. A `semantic` condition — the document's tags, the platform, the
387387
template's origin — cannot be decided and is always pending review, never dropped.
388388

389+
A `host` condition says the attacker must choose the host of the URL passed as
390+
`argument` (or at `position`), as credentials leaking to the host of a crafted URL
391+
need: `{"kind": "host", "text": "…", "argument": "url", "position": 0}`. It is
392+
decided from the URL's constant text, as `ssrf` and `open-redirect` read it, when the
393+
attacker's input is passed in that argument. The outcome has three cases:
394+
395+
- Constant text fixes the host (`"https://api.example.com/" + path`) and the call
396+
disables redirects (`allow_redirects=False`, `follow_redirects=False`): the call is
397+
reachable, not exploitable.
398+
- Constant text fixes the host but redirects may be followed: the call stays
399+
exploitable. The fixed initial host does not clear the chain, since a redirect may
400+
lead to a host the attacker controls, and the condition pending review says so.
401+
Input in the query does not choose the host.
402+
- Otherwise the condition stays pending review.
403+
404+
The other conditions, the environment included, stay pending as before.
405+
389406
Every dependency finding records the highest level of evidence established in its
390407
`level` metadata: `declared` (the requirement allows a vulnerable version), `imported`
391408
(a module of the package is imported somewhere), `reachable` (an entry point or affected

‎src/coretrace_python/dependency/advisories.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,16 @@ def _condition(entry: Mapping[str, Any]) -> Condition:
251251
default = entry.get("default", False)
252252
if not isinstance(default, bool):
253253
raise TypeError(f"condition default must be true or false, got {default!r}")
254-
return Condition(
254+
condition = Condition(
255255
str(entry["kind"]),
256256
str(entry["text"]),
257257
None if entry.get("argument") is None else str(entry["argument"]),
258258
tuple(str(v) for v in entry.get("values") or []),
259259
position,
260260
default,
261261
)
262+
if condition.kind == "host" and (
263+
(condition.argument is None and condition.position is None) or condition.values or condition.default
264+
):
265+
raise ValueError("a host condition names the URL argument, by keyword or position, and nothing else")
266+
return condition

‎src/coretrace_python/dependency/correlation.py‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from __future__ import annotations
1111

1212
from collections.abc import Iterable, Mapping
13-
from dataclasses import dataclass
13+
from dataclasses import dataclass, replace
1414

1515
from coretrace_python.dependency.graph import (
1616
DIRECT,
@@ -24,6 +24,7 @@
2424
from coretrace_python.interprocedural import Arguments, CallSite, ExternalSymbol
2525
from coretrace_python.semantic.symbols import SymbolId
2626
from coretrace_python.taint import Sink, TaintFlow, TaintKind
27+
from coretrace_python.taint.urls import UrlProof, redirects_disabled
2728

2829
Affected = Mapping[SymbolId, tuple[Advisory, ...]]
2930

@@ -61,14 +62,33 @@ class ConditionCheck:
6162
passed: str | None = None
6263

6364

64-
def check_conditions(entry: AdvisoryEntryPoint | None, arguments: Arguments | None) -> ConditionCheck:
65-
"""Decide ``entry``'s conditions against what the call's ``arguments`` denote."""
65+
def check_conditions(
66+
entry: AdvisoryEntryPoint | None,
67+
arguments: Arguments | None,
68+
url: UrlProof | None = None,
69+
passed_as: frozenset[tuple[int | None, str | None]] = frozenset(),
70+
) -> ConditionCheck:
71+
"""Decide ``entry``'s conditions against what the call's ``arguments`` denote and, for
72+
a ``host`` condition, what ``url`` proves of the value the attacker's input is passed
73+
in (``passed_as``). A host the URL's constant text fixes rules the call out when the
74+
call disables redirects; otherwise a redirect may still lead to a host the attacker
75+
controls, and the condition stays pending with that uncertainty."""
6676

6777
if entry is None:
6878
return ConditionCheck()
6979
met: list[Condition] = []
7080
pending: list[Condition] = []
7181
for condition in entry.conditions:
82+
if condition.kind == "host":
83+
origin = url.origin if url is not None and _passed_in(condition, passed_as) else None
84+
if origin is None:
85+
pending.append(condition)
86+
elif redirects_disabled(arguments):
87+
return ConditionCheck(tuple(met), tuple(pending), condition, repr(origin))
88+
else:
89+
text = f"the host is fixed by {origin!r}, but a redirect may lead to a host the attacker controls"
90+
pending.append(replace(condition, text=text))
91+
continue
7292
given = arguments.given(condition.argument, condition.position) if condition.checkable and arguments is not None else None
7393
if given is None:
7494
pending.append(condition)
@@ -84,6 +104,16 @@ def check_conditions(entry: AdvisoryEntryPoint | None, arguments: Arguments | No
84104
return ConditionCheck(tuple(met), tuple(pending))
85105

86106

107+
def _passed_in(condition: Condition, passed_as: frozenset[tuple[int | None, str | None]]) -> bool:
108+
"""Whether a value passed as ``passed_as`` is the argument ``condition`` names."""
109+
110+
return any(
111+
(keyword is not None and keyword == condition.argument)
112+
or (keyword is None and position is not None and position == condition.position)
113+
for position, keyword in passed_as
114+
)
115+
116+
87117
def ruled_out(module: str, site: CallSite, check: ConditionCheck) -> str:
88118
"""Which call a contradicted condition rules out, and why: ``app:12
89119
python.yaml.load(Loader=python.yaml.SafeLoader)``."""
@@ -120,9 +150,10 @@ def correlate(
120150
flows: Iterable[TaintFlow],
121151
verdicts: Verdicts | None,
122152
affected: Affected,
153+
urls: Mapping[TaintFlow, UrlProof] | None = None,
123154
) -> tuple[Finding, ...]:
124155
"""Exploitable-vulnerability findings for the non-refuted ADVISORY flows of a function,
125-
one per advisory the sink is affected by."""
156+
one per advisory the sink is affected by; ``urls`` holds what each flow's URL proves."""
126157

127158
findings: list[Finding] = []
128159
for flow in flows:
@@ -136,7 +167,7 @@ def correlate(
136167
entry = advisory.entry_point(flow.sink.symbol)
137168
if entry is not None and not any(entry.exploitable_through(p, k) for p, k in flow.passed_as):
138169
continue
139-
check = check_conditions(entry, flow.sink_arguments)
170+
check = check_conditions(entry, flow.sink_arguments, (urls or {}).get(flow), flow.passed_as)
140171
if check.contradicted is None:
141172
findings.append(_exploitable(function, flow, advisory, verdict, hotspot, check))
142173
return tuple(findings)

‎src/coretrace_python/dependency/graph.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ class Condition:
151151
``argument`` condition names the argument by keyword, and by ``position`` when it may
152152
be passed positionally, and lists the ``values`` that satisfy it — symbols
153153
(``python.yaml.FullLoader``) or constants as Python writes them (``True``);
154-
``default`` says an absent argument means a vulnerable value. A ``semantic``
155-
condition cannot be checked and is reported as pending review."""
154+
``default`` says an absent argument means a vulnerable value. A ``host`` condition
155+
says the attacker must choose the host of the URL passed as ``argument`` (or at
156+
``position``); the engine decides it from what the URL's constant text proves. A
157+
``semantic`` condition cannot be checked and is reported as pending review."""
156158

157159
kind: str
158160
text: str

‎src/coretrace_python/engine.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
escaped_templates,
127127
registered_routes,
128128
)
129+
from coretrace_python.taint.urls import flow_url
129130

130131
TOOL_NAME = "coretrace-python-analyzer"
131132

@@ -770,14 +771,14 @@ def _analyse_module(
770771
graph = manager.get(CallGraphAnalysis)
771772
correlated: list[Finding] = []
772773
if affected:
774+
strings = manager.get(ModuleStringsAnalysis)
773775
for function in supported:
776+
flows = manager.get(TaintAnalysis, function).flows
777+
ssa = manager.get(SSAAnalysis, function)
778+
defs = {i.result: i for block in ssa.blocks for i in block.instructions if i.result is not None}
779+
urls = {flow: flow_url(flow, defs, strings) for flow in flows if flow.kinds & TaintKind.ADVISORY}
774780
correlated.extend(
775-
correlate(
776-
graph.name_of(function),
777-
manager.get(TaintAnalysis, function).flows,
778-
manager.get(RefutationAnalysis, function),
779-
affected,
780-
)
781+
correlate(graph.name_of(function), flows, manager.get(RefutationAnalysis, function), affected, urls)
781782
)
782783
return CachedModule(
783784
manager.get(EntryPointAnalysis),

0 commit comments

Comments
 (0)