mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-17 20:19:29 +00:00
fix(output-encoding): ask about the server half, and say what the family cannot decide
The census recorded this family completing 44 questions on a Node application and finding
nothing, which is what a client-only vocabulary must do there: all six declared sinks were DOM
sinks. NodeGoat's cross-site scripting is server-side.
Decision: the family asks about a value reaching a rendering call, and states in its own
declaration that it cannot decide template-mediated escaping. Whether res.render is safe depends
on the engine's autoescape setting and on the template's markup, neither of which is at the
call, so res.render is not a sink and the family's limits field says so. A new CWE-79 sink
covers res.write, res.end, res.send and the response.* spellings; res.json stays out because an
application/json body is not a document.
Template auto-escaping is claimed where its evidence is, as a configuration defect:
swig.setDefaults, nunjucks.configure and marked.setOptions are security settings now.
It establishes a finding: app/routes/research.js:25, model_entailed,
`req.query.url + req.query.symbol -> res.write(body)`. The handler fetches a URL the caller
chooses and writes the response body into a text/html response, so the document served from
this origin is the attacker's. The record states how coarse the step is: the path from url to
body runs through the client's callback parameter, which the graph treats as reachable from the
call's arguments, so the conclusion rests on the call's semantics rather than on what the graph
established. Five of seven families now establish findings.
Four defects were found on the way, three of them false positives this change would otherwise
have shipped.
- The permissive-value set was shared across every setting, while a boolean's polarity belongs
to the setting: true leaves the door open in cors({origin: true}) and closes it in
swig.setDefaults({autoescape: true}). Adding the template engines would have reported the fix
as the defect on the line that offers it. ConfigSpec now carries per-setting values, and
Jinja2's Environment moved out of Python's shared list for the same latent reason.
- config.sc matched a dotted setting on its trailing segment alone, so marked.setOptions would
have claimed an editor's setOptions. dominance.sc already required the qualifier.
- taint.sc asked its flow query of every argument including the receiver at index 0. On a
response sink the receiver is the response object, so res.end() -- which takes no data -- was
reported exactly like the res.write(body) two lines above it. Flows now use the real
arguments, as arity already did.
- The arbiter sorted a file's settings by line number as TEXT, so line 126 preceded line 78 and
which setting a file reported depended on the spelling of its line numbers.
Template escaping disabled at server.js:135 is detected, measured model_entailed against the
real query and the real arbiter, and still not reported: the arbiter returns one verdict per
question and that file has an earlier permissive setting. Task 14.6 carries it rather than
hiding it.
1,415 tests pass, thirteen skipped; nine Joern-gated query tests pass in the image.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
This commit is contained in:
co-authored by
Claude Opus 5
parent
57f5a3f0dc
commit
f31ef862a7
@@ -40,12 +40,14 @@ def verdict(cpg: CpgResult, spec: ConfigSpec, *, function: str = "", file: str =
|
||||
# Both abstractions read the same literal: a permissive flag ("*", True) and a weak algorithm ("md5").
|
||||
permissive = {value.strip().strip("'\"").lower() for value in spec.permissive}
|
||||
permissive |= {value.strip().strip("'\"").lower() for value in spec.weak_algorithms}
|
||||
scoped = {setting: {value.strip().strip("'\"").lower() for value in values} for setting, values in spec.permissive_by_setting}
|
||||
for row in settings:
|
||||
literals = row["literals"]
|
||||
if not isinstance(literals, list):
|
||||
continue
|
||||
allowed = _permissive_for(str(row["setting"]), scoped) or permissive
|
||||
for literal in literals:
|
||||
if str(literal).strip().strip("'\"").lower() in permissive:
|
||||
if str(literal).strip().strip("'\"").lower() in allowed:
|
||||
return Verdict(
|
||||
rung=Rung.ENTAILED,
|
||||
family=spec.family,
|
||||
@@ -64,6 +66,21 @@ def verdict(cpg: CpgResult, spec: ConfigSpec, *, function: str = "", file: str =
|
||||
return None
|
||||
|
||||
|
||||
def _permissive_for(setting: str, scoped: Mapping[str, set[str]]) -> set[str]:
|
||||
"""The values permissive for the setting THIS row calls, empty when the facts declare none for it.
|
||||
|
||||
A boolean's meaning is a property of the setting, not of the language: `autoescape: false` disables
|
||||
escaping and `secure: false` disables a cookie flag, while `autoescape: true` is the fix and `origin: true`
|
||||
is the defect. Asking per setting is what lets the template engines join the table without reporting every
|
||||
repository that escapes its output.
|
||||
|
||||
The longest declared name that appears in the call wins, so a specific `swig.setDefaults` is not decided by
|
||||
a shorter name that happens to be a substring of the same call.
|
||||
"""
|
||||
matched = sorted((name for name in scoped if name in setting), key=len, reverse=True)
|
||||
return set(scoped[matched[0]]) if matched else set()
|
||||
|
||||
|
||||
def _settings(rows: object, spec: ConfigSpec, *, function: str) -> list[dict[str, object]]:
|
||||
"""Rows for calls this spec actually names. A non-list (an engine failure) yields nothing."""
|
||||
if not isinstance(rows, Sequence) or isinstance(rows, (str, bytes)):
|
||||
@@ -86,8 +103,16 @@ def _settings(rows: object, spec: ConfigSpec, *, function: str) -> list[dict[str
|
||||
"literals": [str(v) for v in literals] if isinstance(literals, Sequence) and not isinstance(literals, str) else [],
|
||||
}
|
||||
)
|
||||
# Deterministic order: the first row decides, so it must not depend on engine ordering.
|
||||
return sorted(kept, key=lambda row: (str(row["method"]), str(row["line"]), str(row["setting"])))
|
||||
|
||||
# Deterministic order: the first row decides, so it must not depend on engine ordering. The line sorts
|
||||
# NUMERICALLY, which is what "the first row" was always meant to mean: as text, line 126 precedes line 78,
|
||||
# and which of a file's settings gets reported was decided by the spelling of its line number. Caught when
|
||||
# a second permissive setting was added to a file that already had one.
|
||||
def _line(row: dict[str, object]) -> tuple[int, str]:
|
||||
text = str(row["line"])
|
||||
return (int(text) if text.lstrip("-").isdigit() else 1 << 30, text)
|
||||
|
||||
return sorted(kept, key=lambda row: (str(row["method"]), _line(row), str(row["setting"])))
|
||||
|
||||
|
||||
__all__ = ["request_params", "verdict"]
|
||||
|
||||
@@ -173,6 +173,13 @@ class ConfigSpec:
|
||||
# algorithm NAMED, not a setting left open. The data has been on the sink facts (`weak_literals`) since
|
||||
# before this feature and nothing read it.
|
||||
weak_algorithms: tuple[str, ...] = ()
|
||||
# Which values are permissive FOR WHICH setting, as (setting, values) pairs. A flat set cannot hold the
|
||||
# answer, because the polarity of a boolean is per setting: `true` leaves the door open in
|
||||
# `cors({origin: true})` and closes it in `swig.setDefaults({autoescape: true})`. With one shared set,
|
||||
# adding a template engine would have reported the fix as the defect on exactly the line whose comment
|
||||
# offers it. A setting a discharger names uses that discharger's values; a setting no discharger names
|
||||
# falls back to `permissive`, which is the committed behaviour for `app.listen` and `createClient`.
|
||||
permissive_by_setting: tuple[tuple[str, tuple[str, ...]], ...] = ()
|
||||
|
||||
|
||||
def config_specs(
|
||||
@@ -194,6 +201,12 @@ def config_specs(
|
||||
weak_calls = tuple(sorted({call for sink in flow.sinks if sink.weak_literals for call in sink.calls}))
|
||||
if not settings or not permissive:
|
||||
return {}
|
||||
scoped_values: dict[str, set[str]] = {}
|
||||
for fact in scoped.dischargers:
|
||||
if fact.kind != "non_permissive_value" or not fact.permissive_values:
|
||||
continue
|
||||
for call in fact.calls:
|
||||
scoped_values.setdefault(call, set()).update(fact.permissive_values)
|
||||
return {
|
||||
"config_secrets": ConfigSpec(
|
||||
family="config_secrets",
|
||||
@@ -201,6 +214,7 @@ def config_specs(
|
||||
settings=tuple(sorted(set(settings) | set(weak_calls))),
|
||||
permissive=permissive,
|
||||
weak_algorithms=weak,
|
||||
permissive_by_setting=tuple((call, tuple(sorted(values))) for call, values in sorted(scoped_values.items())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user