patchsight 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {patchsight-0.1.0 → patchsight-0.2.0}/PKG-INFO +5 -4
- {patchsight-0.1.0 → patchsight-0.2.0}/docs/pypi.md +4 -3
- {patchsight-0.1.0 → patchsight-0.2.0}/pyproject.toml +1 -1
- {patchsight-0.1.0 → patchsight-0.2.0}/pyproject.toml.orig +1 -1
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/cli.py +45 -6
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/db.py +126 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/__main__.py +260 -20
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/extraction.py +9 -3
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/replay.py +5 -3
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/build_db.py +65 -32
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/diffs/github.py +2 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/extract/extractor.py +40 -1
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/extract/prompt.py +37 -5
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/http.py +14 -1
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/ingest/snapshot.py +3 -0
- patchsight-0.2.0/src/patchsight/pipeline/kaggle_inputs.py +141 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/llm/config.py +11 -0
- patchsight-0.2.0/src/patchsight/pipeline/llm_records.py +133 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/pypi.py +2 -0
- patchsight-0.2.0/src/patchsight/pipeline/pypi_extract.py +308 -0
- patchsight-0.2.0/src/patchsight/scan/explain.py +115 -0
- patchsight-0.2.0/src/patchsight/scan/lockfiles/__init__.py +47 -0
- patchsight-0.2.0/src/patchsight/scan/lockfiles/poetry.py +26 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/lockfiles/requirements.py +2 -11
- patchsight-0.2.0/src/patchsight/scan/lockfiles/toml_lock.py +41 -0
- patchsight-0.2.0/src/patchsight/scan/lockfiles/uv.py +28 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/report.py +1 -1
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/run.py +3 -4
- patchsight-0.1.0/src/patchsight/scan/lockfiles/__init__.py +0 -1
- {patchsight-0.1.0 → patchsight-0.2.0}/LICENSE +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/eval/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/eval/confidence.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/eval/metrics.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/eval/parity.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/eval/safety.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/names.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/bundle.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/changedfuncs.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/dunlap.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/benchmarks/splits.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/diffs/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/diffs/commits.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/diffs/hunks.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/diffs/mapping.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/diffs/paths.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/extract/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/extract/schema.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/extract/validate.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/fix_sample.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/ingest/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/ingest/aliases.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/ingest/ghsa_repo.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/ingest/osv.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/ingest/references.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/llm/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/llm/client.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/llm/tokens.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/pipeline/week1.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/py.typed +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/__init__.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/ast_scanner.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/dbcache.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/osv_client.py +0 -0
- {patchsight-0.1.0 → patchsight-0.2.0}/src/patchsight/scan/verdicts.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patchsight
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Know which vulnerable Python dependencies your code actually calls: symbol-level triage, no LLM at scan time.
|
|
5
5
|
Keywords: security,vulnerability,dependencies,supply-chain,sca,static-analysis,reachability,osv,pypi,cli
|
|
6
6
|
Author: Niroj33
|
|
@@ -55,15 +55,16 @@ An LLM reads each PyPI security fix offline and records which functions carry th
|
|
|
55
55
|
pip install patchsight
|
|
56
56
|
|
|
57
57
|
patchsight db update # download the latest symbol database (SHA-256 verified)
|
|
58
|
-
patchsight scan . # scan
|
|
58
|
+
patchsight scan . # scan the lockfile and the code under .
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
| Option | What it does |
|
|
62
62
|
|:---|:---|
|
|
63
|
-
| `--
|
|
63
|
+
| `--lockfile PATH` | Scan a specific lockfile: `requirements.txt`, `uv.lock` or `poetry.lock` (default: the first found, in that order) |
|
|
64
64
|
| `--format json` | Machine-readable output |
|
|
65
65
|
| `--fail-on called` | Exit 1 if any alert is CALLED: a CI gate (`unknown` also fails on UNKNOWN) |
|
|
66
66
|
| `--db PATH` | Use a specific database file (or set `PATCHSIGHT_DB`) |
|
|
67
|
+
| `patchsight explain ID` | Why the database lists an advisory's symbols: confidence, models, rationale and the changed lines |
|
|
67
68
|
| `patchsight db info` | Show which database a scan uses, and its age |
|
|
68
69
|
|
|
69
70
|
## Verdicts
|
|
@@ -91,7 +92,7 @@ The F1 95% interval is 0.62 to 0.74. The reports and a one-command offline repro
|
|
|
91
92
|
|
|
92
93
|
## Status: early release
|
|
93
94
|
|
|
94
|
-
-
|
|
95
|
+
- Reads `requirements.txt` (exact `==` pins only), `uv.lock` and `poetry.lock`. Packages without a PyPI release version (unpinned requirements, git, URL or local sources) are listed, not guessed.
|
|
95
96
|
- The current symbol database ([`db-2026.11.14`](https://github.com/professor3333/PatchSight/releases/tag/db-2026.11.14)) covers 3,505 PyPI vulnerabilities with **fallback records**: every function the fix changed, at low confidence. Expect many UNKNOWN verdicts until LLM-extracted, high-confidence records are published.
|
|
96
97
|
- Transitive use and dynamic code (`getattr` with a computed name, `importlib`, star imports) aren't analysed. They give UNKNOWN or NOT IMPORTED, never a false "not called".
|
|
97
98
|
|
|
@@ -17,15 +17,16 @@ An LLM reads each PyPI security fix offline and records which functions carry th
|
|
|
17
17
|
pip install patchsight
|
|
18
18
|
|
|
19
19
|
patchsight db update # download the latest symbol database (SHA-256 verified)
|
|
20
|
-
patchsight scan . # scan
|
|
20
|
+
patchsight scan . # scan the lockfile and the code under .
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
| Option | What it does |
|
|
24
24
|
|:---|:---|
|
|
25
|
-
| `--
|
|
25
|
+
| `--lockfile PATH` | Scan a specific lockfile: `requirements.txt`, `uv.lock` or `poetry.lock` (default: the first found, in that order) |
|
|
26
26
|
| `--format json` | Machine-readable output |
|
|
27
27
|
| `--fail-on called` | Exit 1 if any alert is CALLED: a CI gate (`unknown` also fails on UNKNOWN) |
|
|
28
28
|
| `--db PATH` | Use a specific database file (or set `PATCHSIGHT_DB`) |
|
|
29
|
+
| `patchsight explain ID` | Why the database lists an advisory's symbols: confidence, models, rationale and the changed lines |
|
|
29
30
|
| `patchsight db info` | Show which database a scan uses, and its age |
|
|
30
31
|
|
|
31
32
|
## Verdicts
|
|
@@ -53,7 +54,7 @@ The F1 95% interval is 0.62 to 0.74. The reports and a one-command offline repro
|
|
|
53
54
|
|
|
54
55
|
## Status: early release
|
|
55
56
|
|
|
56
|
-
-
|
|
57
|
+
- Reads `requirements.txt` (exact `==` pins only), `uv.lock` and `poetry.lock`. Packages without a PyPI release version (unpinned requirements, git, URL or local sources) are listed, not guessed.
|
|
57
58
|
- The current symbol database ([`db-2026.11.14`](https://github.com/professor3333/PatchSight/releases/tag/db-2026.11.14)) covers 3,505 PyPI vulnerabilities with **fallback records**: every function the fix changed, at low confidence. Expect many UNKNOWN verdicts until LLM-extracted, high-confidence records are published.
|
|
58
59
|
- Transitive use and dynamic code (`getattr` with a computed name, `importlib`, star imports) aren't analysed. They give UNKNOWN or NOT IMPORTED, never a false "not called".
|
|
59
60
|
|
|
@@ -89,8 +89,14 @@ def db_info(
|
|
|
89
89
|
@app.command()
|
|
90
90
|
def scan(
|
|
91
91
|
path: Annotated[Path, typer.Argument(help="Project directory to scan.")] = Path(),
|
|
92
|
-
|
|
93
|
-
Path | None,
|
|
92
|
+
lockfile_option: Annotated[
|
|
93
|
+
Path | None,
|
|
94
|
+
typer.Option(
|
|
95
|
+
"--lockfile",
|
|
96
|
+
"--requirements",
|
|
97
|
+
help="requirements.txt, uv.lock or poetry.lock (default: the first found, in "
|
|
98
|
+
"that order).",
|
|
99
|
+
),
|
|
94
100
|
] = None,
|
|
95
101
|
database: Annotated[
|
|
96
102
|
Path | None,
|
|
@@ -104,20 +110,22 @@ def scan(
|
|
|
104
110
|
"""Label every dependency alert as called, imported but not called, not imported, or unknown."""
|
|
105
111
|
from patchsight.db import DatabaseError
|
|
106
112
|
from patchsight.scan.dbcache import default_db_path
|
|
113
|
+
from patchsight.scan.lockfiles import DISCOVERY_ORDER, find
|
|
107
114
|
from patchsight.scan.osv_client import OsvError
|
|
108
115
|
from patchsight.scan.report import render_json, render_text
|
|
109
116
|
from patchsight.scan.run import run_scan
|
|
110
117
|
|
|
111
|
-
lockfile =
|
|
112
|
-
if not lockfile.
|
|
113
|
-
|
|
118
|
+
lockfile = lockfile_option or find(path)
|
|
119
|
+
if lockfile is None or not lockfile.is_file():
|
|
120
|
+
looked = lockfile if lockfile is not None else f"{path} ({', '.join(DISCOVERY_ORDER)})"
|
|
121
|
+
typer.echo(f"error: no lockfile at {looked}; pass --lockfile", err=True)
|
|
114
122
|
raise typer.Exit(code=2)
|
|
115
123
|
try:
|
|
116
124
|
alerts, dependencies, meta = run_scan(path, lockfile, database or default_db_path())
|
|
117
125
|
except DatabaseError as error:
|
|
118
126
|
typer.echo(f"error: {error}; run 'patchsight db update' or pass --db", err=True)
|
|
119
127
|
raise typer.Exit(code=2) from None
|
|
120
|
-
except OsvError as error:
|
|
128
|
+
except (OsvError, ValueError) as error:
|
|
121
129
|
typer.echo(f"error: {error}", err=True)
|
|
122
130
|
raise typer.Exit(code=2) from None
|
|
123
131
|
shown = lockfile.as_posix()
|
|
@@ -128,3 +136,34 @@ def scan(
|
|
|
128
136
|
failing = {"called": {"CALLED"}, "unknown": {"CALLED", "UNKNOWN"}}.get(fail_on, set())
|
|
129
137
|
if any(a.verdict in failing for a in alerts):
|
|
130
138
|
raise typer.Exit(code=1)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@app.command()
|
|
142
|
+
def explain(
|
|
143
|
+
identifier: Annotated[str, typer.Argument(help="Advisory ID: GHSA, PYSEC or CVE.")],
|
|
144
|
+
database: Annotated[
|
|
145
|
+
Path | None,
|
|
146
|
+
typer.Option("--db", help="Symbol database (default: the one 'db update' downloaded)."),
|
|
147
|
+
] = None,
|
|
148
|
+
output: Annotated[str, typer.Option("--format", help="text or json.")] = "text",
|
|
149
|
+
) -> None:
|
|
150
|
+
"""Show why the database lists the symbols it does for an advisory, with evidence."""
|
|
151
|
+
from patchsight.db import DatabaseError, SymbolDatabase
|
|
152
|
+
from patchsight.scan import explain as explaining
|
|
153
|
+
from patchsight.scan.dbcache import default_db_path
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
opened = SymbolDatabase(database or default_db_path())
|
|
157
|
+
except DatabaseError as error:
|
|
158
|
+
typer.echo(f"error: {error}; run 'patchsight db update' or pass --db", err=True)
|
|
159
|
+
raise typer.Exit(code=2) from None
|
|
160
|
+
try:
|
|
161
|
+
vulnerability, identifiers, records = explaining.lookup(opened, identifier)
|
|
162
|
+
meta = opened.meta
|
|
163
|
+
finally:
|
|
164
|
+
opened.close()
|
|
165
|
+
canonical = explaining.normalise_identifier(identifier)
|
|
166
|
+
render = explaining.render_json if output == "json" else explaining.render_text
|
|
167
|
+
typer.echo(render(canonical, vulnerability, identifiers, records, meta))
|
|
168
|
+
if not records:
|
|
169
|
+
raise typer.Exit(code=1)
|
|
@@ -9,6 +9,12 @@ its vulnerability, so the scanner can look up whatever ID OSV returns.
|
|
|
9
9
|
Low-confidence symbols can make an alert ``CALLED`` but never ``IMPORTED_NOT_CALLED``.
|
|
10
10
|
|
|
11
11
|
Stdlib ``sqlite3`` only, so the scan path can read it without any pipeline dependency.
|
|
12
|
+
|
|
13
|
+
Compatibility: the ``extraction`` table (second-opinion model and the reason for the tier)
|
|
14
|
+
and the ``evidence`` table (each flagged symbol's rationale and cited hunk locations) were
|
|
15
|
+
added within schema version 1. Readers that predate them never query them, so they keep
|
|
16
|
+
working; this reader treats a database without them as having no such provenance. Evidence
|
|
17
|
+
holds commit SHAs, paths and line ranges only, never code (rule 13).
|
|
12
18
|
"""
|
|
13
19
|
|
|
14
20
|
import json
|
|
@@ -55,6 +61,21 @@ CREATE TABLE symbols (
|
|
|
55
61
|
FOREIGN KEY (vulnerability, package) REFERENCES records (vulnerability, package)
|
|
56
62
|
);
|
|
57
63
|
CREATE INDEX symbols_by_record ON symbols (vulnerability, package);
|
|
64
|
+
CREATE TABLE extraction (
|
|
65
|
+
vulnerability TEXT NOT NULL,
|
|
66
|
+
package TEXT NOT NULL,
|
|
67
|
+
second_opinion_model TEXT,
|
|
68
|
+
tier_reason TEXT,
|
|
69
|
+
PRIMARY KEY (vulnerability, package)
|
|
70
|
+
);
|
|
71
|
+
CREATE TABLE evidence (
|
|
72
|
+
vulnerability TEXT NOT NULL,
|
|
73
|
+
package TEXT NOT NULL,
|
|
74
|
+
qualified_name TEXT NOT NULL,
|
|
75
|
+
rationale TEXT NOT NULL,
|
|
76
|
+
hunks TEXT NOT NULL,
|
|
77
|
+
PRIMARY KEY (vulnerability, package, qualified_name)
|
|
78
|
+
);
|
|
58
79
|
"""
|
|
59
80
|
|
|
60
81
|
|
|
@@ -69,6 +90,29 @@ class FixCommitRef(BaseModel):
|
|
|
69
90
|
sha: str
|
|
70
91
|
|
|
71
92
|
|
|
93
|
+
class HunkLocation(BaseModel):
|
|
94
|
+
"""Where a cited diff hunk sits: the fix commit, the file and both line ranges."""
|
|
95
|
+
|
|
96
|
+
model_config = ConfigDict(frozen=True)
|
|
97
|
+
|
|
98
|
+
commit: str
|
|
99
|
+
path: str
|
|
100
|
+
old_start: int
|
|
101
|
+
old_count: int
|
|
102
|
+
new_start: int
|
|
103
|
+
new_count: int
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class SymbolEvidence(BaseModel):
|
|
107
|
+
"""Why the model flagged a symbol: a one-sentence rationale and the hunks it cited."""
|
|
108
|
+
|
|
109
|
+
model_config = ConfigDict(frozen=True)
|
|
110
|
+
|
|
111
|
+
qualified_name: str
|
|
112
|
+
rationale: str
|
|
113
|
+
hunks: tuple[HunkLocation, ...]
|
|
114
|
+
|
|
115
|
+
|
|
72
116
|
class Symbol(BaseModel):
|
|
73
117
|
"""A vulnerable definition. ``qualified_name`` is ``module.qualname`` when the module
|
|
74
118
|
is known, otherwise just the qualname."""
|
|
@@ -99,6 +143,12 @@ class Record(BaseModel):
|
|
|
99
143
|
advisory_modified: datetime
|
|
100
144
|
truncated: bool
|
|
101
145
|
extracted_at: datetime
|
|
146
|
+
# LLM records only: the second model's ID (ADR 0005) and why the tier was chosen.
|
|
147
|
+
second_opinion_model: str | None = None
|
|
148
|
+
tier_reason: str | None = None
|
|
149
|
+
# The symbols the model judged vulnerable (all of a high record's symbols; in a low
|
|
150
|
+
# record, the model's picks among every changed definition).
|
|
151
|
+
evidence: tuple[SymbolEvidence, ...] = ()
|
|
102
152
|
|
|
103
153
|
|
|
104
154
|
def write(
|
|
@@ -137,6 +187,29 @@ def write(
|
|
|
137
187
|
record.extracted_at.isoformat(),
|
|
138
188
|
),
|
|
139
189
|
)
|
|
190
|
+
if record.second_opinion_model is not None or record.tier_reason is not None:
|
|
191
|
+
connection.execute(
|
|
192
|
+
"INSERT INTO extraction VALUES (?, ?, ?, ?)",
|
|
193
|
+
(
|
|
194
|
+
record.vulnerability,
|
|
195
|
+
record.package,
|
|
196
|
+
record.second_opinion_model,
|
|
197
|
+
record.tier_reason,
|
|
198
|
+
),
|
|
199
|
+
)
|
|
200
|
+
connection.executemany(
|
|
201
|
+
"INSERT INTO evidence VALUES (?, ?, ?, ?, ?)",
|
|
202
|
+
[
|
|
203
|
+
(
|
|
204
|
+
record.vulnerability,
|
|
205
|
+
record.package,
|
|
206
|
+
e.qualified_name,
|
|
207
|
+
e.rationale,
|
|
208
|
+
json.dumps([h.model_dump() for h in e.hunks]),
|
|
209
|
+
)
|
|
210
|
+
for e in record.evidence
|
|
211
|
+
],
|
|
212
|
+
)
|
|
140
213
|
connection.executemany(
|
|
141
214
|
"INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?, ?)",
|
|
142
215
|
[
|
|
@@ -175,6 +248,14 @@ class SymbolDatabase:
|
|
|
175
248
|
f"{path} has schema version {version}; this version of PatchSight reads "
|
|
176
249
|
f"version {SCHEMA_VERSION}. Update PatchSight or download a matching database."
|
|
177
250
|
)
|
|
251
|
+
tables = {
|
|
252
|
+
name
|
|
253
|
+
for (name,) in self._connection.execute(
|
|
254
|
+
"SELECT name FROM sqlite_master WHERE type = 'table'"
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
self._has_extraction = "extraction" in tables
|
|
258
|
+
self._has_evidence = "evidence" in tables
|
|
178
259
|
|
|
179
260
|
def close(self) -> None:
|
|
180
261
|
self._connection.close()
|
|
@@ -188,6 +269,23 @@ class SymbolDatabase:
|
|
|
188
269
|
).fetchone()
|
|
189
270
|
return str(row[0]) if row else None
|
|
190
271
|
|
|
272
|
+
def identifiers_for(self, vulnerability: str) -> list[str]:
|
|
273
|
+
"""Every advisory ID and alias that points at this vulnerability."""
|
|
274
|
+
rows = self._connection.execute(
|
|
275
|
+
"SELECT identifier FROM aliases WHERE vulnerability = ? ORDER BY identifier",
|
|
276
|
+
(vulnerability,),
|
|
277
|
+
).fetchall()
|
|
278
|
+
return [str(r[0]) for r in rows]
|
|
279
|
+
|
|
280
|
+
def records_for(self, vulnerability: str) -> list[Record]:
|
|
281
|
+
"""The vulnerability's records, one per affected package."""
|
|
282
|
+
packages = self._connection.execute(
|
|
283
|
+
"SELECT package FROM records WHERE vulnerability = ? ORDER BY package",
|
|
284
|
+
(vulnerability,),
|
|
285
|
+
).fetchall()
|
|
286
|
+
found = (self.record(vulnerability, str(p[0])) for p in packages)
|
|
287
|
+
return [r for r in found if r is not None]
|
|
288
|
+
|
|
191
289
|
def record(self, vulnerability: str, package: str) -> Record | None:
|
|
192
290
|
row = self._connection.execute(
|
|
193
291
|
"SELECT * FROM records WHERE vulnerability = ? AND package = ?",
|
|
@@ -200,6 +298,24 @@ class SymbolDatabase:
|
|
|
200
298
|
"WHERE vulnerability = ? AND package = ? ORDER BY qualified_name",
|
|
201
299
|
(vulnerability, package),
|
|
202
300
|
).fetchall()
|
|
301
|
+
provenance = (
|
|
302
|
+
self._connection.execute(
|
|
303
|
+
"SELECT second_opinion_model, tier_reason FROM extraction "
|
|
304
|
+
"WHERE vulnerability = ? AND package = ?",
|
|
305
|
+
(vulnerability, package),
|
|
306
|
+
).fetchone()
|
|
307
|
+
if self._has_extraction
|
|
308
|
+
else None
|
|
309
|
+
)
|
|
310
|
+
evidence = (
|
|
311
|
+
self._connection.execute(
|
|
312
|
+
"SELECT qualified_name, rationale, hunks FROM evidence "
|
|
313
|
+
"WHERE vulnerability = ? AND package = ? ORDER BY qualified_name",
|
|
314
|
+
(vulnerability, package),
|
|
315
|
+
).fetchall()
|
|
316
|
+
if self._has_evidence
|
|
317
|
+
else []
|
|
318
|
+
)
|
|
203
319
|
return Record(
|
|
204
320
|
vulnerability=row[0],
|
|
205
321
|
package=row[1],
|
|
@@ -218,4 +334,14 @@ class SymbolDatabase:
|
|
|
218
334
|
Symbol(qualified_name=s[0], module=s[1], name=s[2], kind=s[3], path=s[4])
|
|
219
335
|
for s in symbols
|
|
220
336
|
),
|
|
337
|
+
second_opinion_model=provenance[0] if provenance else None,
|
|
338
|
+
tier_reason=provenance[1] if provenance else None,
|
|
339
|
+
evidence=tuple(
|
|
340
|
+
SymbolEvidence(
|
|
341
|
+
qualified_name=e[0],
|
|
342
|
+
rationale=e[1],
|
|
343
|
+
hunks=tuple(HunkLocation(**h) for h in json.loads(e[2])),
|
|
344
|
+
)
|
|
345
|
+
for e in evidence
|
|
346
|
+
),
|
|
221
347
|
)
|