Skip to content

Commit d2b4e9f

Browse files
authored
Merge pull request #102 from CoreTrace/feat/taint-kinds-nosql-log-pii
feat: add the NOSQL, LOG and PII taint kinds
2 parents a72b281 + 1d51ec8 commit d2b4e9f

4 files changed

Lines changed: 51 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
- A plugin's entrypoint may be a package, `<module>/__init__.py`, so a plugin can split its tables across files and import them relatively (#93).
99
- The cache key covers every file of a plugin directory, not only `.py` and `.toml`, so rules or advisories shipped as data invalidate cached results when they change (#94).
1010

11+
### Analysis
12+
13+
- New taint kinds: `NOSQL` in `TaintKind.ALL`; `LOG` and `PII` outside it, carried only by the values a model marks, so a NoSQL-injection, log-injection or personal-data detector no longer has to share a kind with another rule (#96).
14+
1115
## 0.2.0 (2026-09-06)
1216

1317
### Adoption in an existing repository

‎docs/plugins.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ class CommandInjectionPlugin(TaintDetector):
106106
```
107107

108108
`confidence` defaults to high; a hotspot, a flow behind a guard that mentions the value
109-
or an authorization decorator, is reported at medium. The taint kinds are `SQL`,
110-
`COMMAND`, `HTML`, `PATH`, `SSRF`, `CODE`, `DESERIALIZATION`, `REDIRECT`, `ADVISORY`
111-
(APIs affected by advisories) and `CREDENTIAL`, which only credential-named parameters
112-
carry so that ordinary input reaching a database write is not a plaintext credential.
109+
or an authorization decorator, is reported at medium. The taint kinds every source
110+
carries by default (`TaintKind.ALL`) are `SQL`, `NOSQL`, `COMMAND`, `HTML`, `PATH`,
111+
`SSRF`, `CODE`, `DESERIALIZATION`, `REDIRECT` and `ADVISORY` (APIs affected by
112+
advisories). Three kinds are outside `ALL`, so only a value a model marks with them
113+
reaches their sinks: `CREDENTIAL`, which credential-named parameters carry so that
114+
ordinary input reaching a database write is not a plaintext credential; `LOG`, for
115+
values that must not be written to a log as they are; and `PII`, for personal data
116+
that must not leave the application through a log, a third party or plain storage.
113117

114118
### Security models: `ModelPlugin`
115119

‎src/coretrace_python/taint/models.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ class TaintKind(Flag):
3030
ADVISORY = auto()
3131
DESERIALIZATION = auto()
3232
REDIRECT = auto()
33-
ALL = SQL | COMMAND | HTML | PATH | SSRF | CODE | ADVISORY | DESERIALIZATION | REDIRECT
34-
# Outside ALL on purpose: only credential-named parameters carry it, so a database
35-
# write reached by ordinary input is not a plaintext credential.
33+
NOSQL = auto()
34+
ALL = SQL | COMMAND | HTML | PATH | SSRF | CODE | ADVISORY | DESERIALIZATION | REDIRECT | NOSQL
35+
# Outside ALL on purpose: only the values a model marks carry them, so a database
36+
# write reached by ordinary input is not a plaintext credential, and ordinary input
37+
# reaching a logger is neither log forging nor a personal-data leak.
3638
CREDENTIAL = auto()
39+
LOG = auto()
40+
PII = auto()
3741

3842

3943
class ModelError(Exception):

‎tests/test_taint.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,38 @@ def test_taint_kinds_form_a_bitset() -> None:
101101
assert {TaintKind.SQL, TaintKind.COMMAND, TaintKind.HTML, TaintKind.PATH, TaintKind.SSRF} <= set(TaintKind)
102102

103103

104+
def test_nosql_is_ordinary_input_while_log_and_pii_are_opt_in() -> None:
105+
assert TaintKind.NOSQL in TaintKind.ALL
106+
assert TaintKind.LOG not in TaintKind.ALL
107+
assert TaintKind.PII not in TaintKind.ALL
108+
assert TaintKind.CREDENTIAL not in TaintKind.ALL
109+
110+
111+
def test_ordinary_input_reaches_a_nosql_sink_but_not_a_log_sink() -> None:
112+
registry = SecurityModelRegistry()
113+
registry.register(
114+
Source(sym("python.flask.request.args"), HTTP),
115+
Source(sym("python.app.record"), "record", TaintKind.LOG),
116+
Sink(sym("python.db.find"), TaintKind.NOSQL),
117+
Sink(sym("python.logging.info"), TaintKind.LOG),
118+
)
119+
_, facts = analyze(
120+
"from flask import request\n"
121+
"import db, logging\n"
122+
"from app import record\n\n"
123+
"def run():\n"
124+
" db.find(request.args['q'])\n"
125+
" logging.info(request.args['q'])\n"
126+
" logging.info(record())\n",
127+
registry.freeze(),
128+
)
129+
130+
assert [(f.sink.symbol, f.kinds) for f in facts.flows] == [
131+
(sym("python.db.find"), TaintKind.NOSQL),
132+
(sym("python.logging.info"), TaintKind.LOG),
133+
]
134+
135+
104136
def test_taint_joins_with_or() -> None:
105137
a = Taint(TaintKind.SQL, frozenset({Source(sym("python.a"), "a")}))
106138
b = Taint(TaintKind.HTML, frozenset({Source(sym("python.b"), "b")}))

0 commit comments

Comments
 (0)