@openai/codex-security 0.1.20 → 0.1.23
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.
- package/README.md +1101 -865
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/config-preflight.md +2 -30
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/finding-detail-fields.md +5 -10
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +243 -0
- package/_bundled_plugin/scripts/config_preflight.py +2 -8
- package/_bundled_plugin/scripts/finalize_scan_contract.py +206 -35
- package/_bundled_plugin/scripts/finding_preview.py +22 -4
- package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -1
- package/_bundled_plugin/scripts/launch_codex_security_mcp +0 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +101 -7
- package/_bundled_plugin/scripts/workbench_cli.py +21 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +115 -0
- package/_bundled_plugin/scripts/workbench_db.py +29 -2
- package/_bundled_plugin/scripts/workbench_finding_index.py +42 -24
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +190 -0
- package/_bundled_plugin/scripts/workbench_findings.py +216 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +30 -5
- package/_bundled_plugin/scripts/workbench_schema.py +263 -58
- package/_bundled_plugin/scripts/workbench_target.py +22 -3
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +88 -0
- package/_bundled_plugin/skills/assess-patch-risk/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/assess-patch-risk/references/risk-rubric.md +76 -0
- package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +163 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +16 -48
- package/_bundled_plugin/skills/track-findings/SKILL.md +2 -0
- package/dist/api.d.ts +3 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +129 -45
- package/dist/api.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +6 -24
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +28 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +525 -96
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts +5 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +312 -10
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +5 -1
- package/dist/component-plan.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -0
- package/dist/contract.js.map +1 -1
- package/dist/custom-publish.d.ts +22 -0
- package/dist/custom-publish.d.ts.map +1 -0
- package/dist/custom-publish.js +47 -0
- package/dist/custom-publish.js.map +1 -0
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +16 -0
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -0
- package/dist/deduplication/checkpointed-review.js +76 -0
- package/dist/deduplication/checkpointed-review.js.map +1 -0
- package/dist/deduplication/codex-review.d.ts +21 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -0
- package/dist/deduplication/codex-review.js +252 -0
- package/dist/deduplication/codex-review.js.map +1 -0
- package/dist/deduplication/deduplication-prompts.d.ts +8 -0
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -0
- package/dist/deduplication/deduplication-prompts.js +35 -0
- package/dist/deduplication/deduplication-prompts.js.map +1 -0
- package/dist/deduplication/deduplication-reviewer.d.ts +46 -0
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -0
- package/dist/deduplication/deduplication-reviewer.js +105 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -0
- package/dist/deduplication/deduplication.d.ts +6 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -0
- package/dist/deduplication/deduplication.js +85 -0
- package/dist/deduplication/deduplication.js.map +1 -0
- package/dist/deduplication/scan.d.ts +16 -0
- package/dist/deduplication/scan.d.ts.map +1 -0
- package/dist/deduplication/scan.js +101 -0
- package/dist/deduplication/scan.js.map +1 -0
- package/dist/finding-dedupe-groups.d.ts +7 -0
- package/dist/finding-dedupe-groups.d.ts.map +1 -0
- package/dist/finding-dedupe-groups.js +2 -0
- package/dist/finding-dedupe-groups.js.map +1 -0
- package/dist/finding-retrieval.d.ts +13 -0
- package/dist/finding-retrieval.d.ts.map +1 -0
- package/dist/finding-retrieval.js +2 -0
- package/dist/finding-retrieval.js.map +1 -0
- package/dist/finding-workflow.d.ts +53 -0
- package/dist/finding-workflow.d.ts.map +1 -0
- package/dist/finding-workflow.js +117 -0
- package/dist/finding-workflow.js.map +1 -0
- package/dist/findings-client.d.ts +15 -0
- package/dist/findings-client.d.ts.map +1 -0
- package/dist/findings-client.js +60 -0
- package/dist/findings-client.js.map +1 -0
- package/dist/github.d.ts +161 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +158 -0
- package/dist/github.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/publication.js +28 -40
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +10 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +29 -5
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +5 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +371 -197
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts +15 -0
- package/dist/saved-scan.d.ts.map +1 -0
- package/dist/saved-scan.js +68 -0
- package/dist/saved-scan.js.map +1 -0
- package/dist/scan-comparison.d.ts +6 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +7 -2
- package/dist/scan-comparison.js.map +1 -1
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +276 -0
- package/dist/server/dashboard/app.css +2 -0
- package/dist/server/dashboard/app.js +66 -0
- package/dist/server/dashboard/index.html +18 -0
- package/dist/server/dashboard-types.d.ts +45 -0
- package/dist/server/dashboard-types.d.ts.map +1 -0
- package/dist/server/dashboard-types.js +2 -0
- package/dist/server/dashboard-types.js.map +1 -0
- package/dist/server/dashboard.d.ts +6 -0
- package/dist/server/dashboard.d.ts.map +1 -0
- package/dist/server/dashboard.js +45 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/server/embeddings.d.ts +16 -0
- package/dist/server/embeddings.d.ts.map +1 -0
- package/dist/server/embeddings.js +114 -0
- package/dist/server/embeddings.js.map +1 -0
- package/dist/server/errors.d.ts +5 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +8 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/findings-service.d.ts +20 -0
- package/dist/server/findings-service.d.ts.map +1 -0
- package/dist/server/findings-service.js +31 -0
- package/dist/server/findings-service.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +32 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes.d.ts +6 -0
- package/dist/server/routes.d.ts.map +1 -0
- package/dist/server/routes.js +86 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/server/server.d.ts +10 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/sqlite-store.d.ts +22 -0
- package/dist/server/sqlite-store.d.ts.map +1 -0
- package/dist/server/sqlite-store.js +82 -0
- package/dist/server/sqlite-store.js.map +1 -0
- package/dist/server/storage.d.ts +32 -0
- package/dist/server/storage.d.ts.map +1 -0
- package/dist/server/storage.js +2 -0
- package/dist/server/storage.js.map +1 -0
- package/dist/server/validation.d.ts +17 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +53 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +1 -0
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +8 -0
- package/dist/thread-source.d.ts.map +1 -0
- package/dist/thread-source.js +7 -0
- package/dist/thread-source.js.map +1 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +2 -1
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +23 -8
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"""Storage operations for complete findings imported without a scan."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
import sqlite3
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
15
|
+
from workbench_finding_index import upsert_finding
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def store_findings(
|
|
19
|
+
connection: sqlite3.Connection,
|
|
20
|
+
entries: list[dict[str, Any]],
|
|
21
|
+
timestamp: str,
|
|
22
|
+
repository_id: str | None = None,
|
|
23
|
+
) -> dict[str, Any]:
|
|
24
|
+
try:
|
|
25
|
+
with connection:
|
|
26
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
27
|
+
for entry in entries:
|
|
28
|
+
finding = entry["finding"]
|
|
29
|
+
embedding = entry["embedding"]
|
|
30
|
+
identity = (
|
|
31
|
+
finding["fingerprints"]["primary"],
|
|
32
|
+
finding["ruleId"],
|
|
33
|
+
finding["identity"]["anchor"],
|
|
34
|
+
finding["identity"].get("instance"),
|
|
35
|
+
)
|
|
36
|
+
current = connection.execute(
|
|
37
|
+
"SELECT fingerprint, rule_id, identity_anchor, identity_instance "
|
|
38
|
+
"FROM findings WHERE id = ?",
|
|
39
|
+
(finding["findingId"],),
|
|
40
|
+
).fetchone()
|
|
41
|
+
if current is not None and tuple(current) != identity:
|
|
42
|
+
raise sqlite3.IntegrityError("The stored finding identity cannot be replaced.")
|
|
43
|
+
upsert_finding(connection, finding, timestamp, repository_id)
|
|
44
|
+
connection.execute(
|
|
45
|
+
"""
|
|
46
|
+
INSERT INTO finding_embeddings (finding_id, model, vector_json)
|
|
47
|
+
VALUES (?, ?, ?)
|
|
48
|
+
ON CONFLICT(finding_id) DO UPDATE SET
|
|
49
|
+
model = excluded.model, vector_json = excluded.vector_json
|
|
50
|
+
""",
|
|
51
|
+
(
|
|
52
|
+
finding["findingId"],
|
|
53
|
+
embedding["model"],
|
|
54
|
+
json.dumps(embedding["vector"], allow_nan=False),
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
except sqlite3.IntegrityError:
|
|
58
|
+
return {"error": "finding_conflict"}
|
|
59
|
+
return {"findingIds": [entry["finding"]["findingId"] for entry in entries]}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def list_stored_findings(
|
|
63
|
+
connection: sqlite3.Connection, *, limit: int, offset: int
|
|
64
|
+
) -> dict[str, Any]:
|
|
65
|
+
connection.execute("BEGIN")
|
|
66
|
+
with connection:
|
|
67
|
+
total = connection.execute(
|
|
68
|
+
"SELECT COUNT(*) FROM findings WHERE details_json IS NOT NULL"
|
|
69
|
+
).fetchone()[0]
|
|
70
|
+
rows = connection.execute(
|
|
71
|
+
"""
|
|
72
|
+
SELECT details_json FROM findings WHERE details_json IS NOT NULL
|
|
73
|
+
ORDER BY created_at, id LIMIT ? OFFSET ?
|
|
74
|
+
""",
|
|
75
|
+
(limit, offset),
|
|
76
|
+
).fetchall()
|
|
77
|
+
next_offset = offset + len(rows)
|
|
78
|
+
return {
|
|
79
|
+
"findings": [json.loads(row["details_json"]) for row in rows],
|
|
80
|
+
"limit": limit,
|
|
81
|
+
"offset": offset,
|
|
82
|
+
"total": total,
|
|
83
|
+
"nextOffset": next_offset if next_offset < total else None,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def find_potential_duplicates(
|
|
88
|
+
connection: sqlite3.Connection, finding_id: str, repository_id: str | None
|
|
89
|
+
) -> dict[str, Any]:
|
|
90
|
+
"""Rank IDs and vectors in the requested scope before loading finding documents."""
|
|
91
|
+
connection.execute("BEGIN")
|
|
92
|
+
with connection:
|
|
93
|
+
if repository_id is None:
|
|
94
|
+
source = "finding_embeddings AS embeddings"
|
|
95
|
+
predicate = ""
|
|
96
|
+
scope_parameters: tuple[str, ...] = ()
|
|
97
|
+
else:
|
|
98
|
+
source = (
|
|
99
|
+
"finding_repositories AS repositories JOIN finding_embeddings AS embeddings "
|
|
100
|
+
"ON embeddings.finding_id = repositories.finding_id"
|
|
101
|
+
)
|
|
102
|
+
predicate = "repositories.repository_id = ? AND "
|
|
103
|
+
scope_parameters = (repository_id,)
|
|
104
|
+
anchor = connection.execute(
|
|
105
|
+
f"SELECT embeddings.model, embeddings.vector_json FROM {source} "
|
|
106
|
+
f"WHERE {predicate}embeddings.finding_id = ?",
|
|
107
|
+
(*scope_parameters, finding_id),
|
|
108
|
+
).fetchone()
|
|
109
|
+
if anchor is None:
|
|
110
|
+
return {"error": "finding_not_indexed"}
|
|
111
|
+
rows = connection.execute(
|
|
112
|
+
f"SELECT embeddings.finding_id, embeddings.vector_json FROM {source} "
|
|
113
|
+
"JOIN findings ON findings.id = embeddings.finding_id "
|
|
114
|
+
f"WHERE {predicate}embeddings.model = ? AND embeddings.finding_id != ? "
|
|
115
|
+
"ORDER BY findings.created_at, findings.id",
|
|
116
|
+
(*scope_parameters, anchor["model"], finding_id),
|
|
117
|
+
)
|
|
118
|
+
ranked: list[tuple[str, float]] = []
|
|
119
|
+
try:
|
|
120
|
+
vector = normalized_vector(json.loads(anchor["vector_json"]))
|
|
121
|
+
for row in rows:
|
|
122
|
+
candidate = json.loads(row["vector_json"])
|
|
123
|
+
if len(candidate) != len(vector):
|
|
124
|
+
continue
|
|
125
|
+
other = normalized_vector(candidate)
|
|
126
|
+
similarity = sum(left * right for left, right in zip(vector, other))
|
|
127
|
+
if similarity >= 0.55:
|
|
128
|
+
ranked.append((row["finding_id"], similarity))
|
|
129
|
+
except ValueError:
|
|
130
|
+
return {"error": "embedding_failed"}
|
|
131
|
+
# Stable sorting retains insertion-time / finding-ID order for ties.
|
|
132
|
+
ranked.sort(key=lambda candidate: candidate[1], reverse=True)
|
|
133
|
+
selected_ids = [finding_id, *(candidate[0] for candidate in ranked[:50])]
|
|
134
|
+
documents = {
|
|
135
|
+
row["id"]: json.loads(row["details_json"])
|
|
136
|
+
for row in connection.execute(
|
|
137
|
+
"SELECT id, details_json FROM findings WHERE id IN ("
|
|
138
|
+
+ ",".join("?" for _ in selected_ids)
|
|
139
|
+
+ ")",
|
|
140
|
+
selected_ids,
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
"finding": documents[finding_id],
|
|
145
|
+
"potentialDuplicates": [documents[id] for id in selected_ids[1:]],
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def store_dedupe_groups(
|
|
150
|
+
connection: sqlite3.Connection, groups: list[list[str]], timestamp: str
|
|
151
|
+
) -> dict[str, Any]:
|
|
152
|
+
"""Persist reviewed sets independently, including overlapping groups, in one transaction."""
|
|
153
|
+
stored: dict[str, dict[str, Any]] = {}
|
|
154
|
+
try:
|
|
155
|
+
with connection:
|
|
156
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
157
|
+
for group in groups:
|
|
158
|
+
members = sorted(set(group))
|
|
159
|
+
# Membership, not input order, identifies a group on retries.
|
|
160
|
+
group_id = "fdg_" + hashlib.sha256(
|
|
161
|
+
json.dumps(members, ensure_ascii=True, separators=(",", ":")).encode("utf-8")
|
|
162
|
+
).hexdigest()
|
|
163
|
+
connection.execute(
|
|
164
|
+
"INSERT INTO finding_dedupe_groups (id, created_at) VALUES (?, ?) "
|
|
165
|
+
"ON CONFLICT(id) DO NOTHING",
|
|
166
|
+
(group_id, timestamp),
|
|
167
|
+
)
|
|
168
|
+
connection.executemany(
|
|
169
|
+
"INSERT INTO finding_dedupe_group_members (group_id, finding_id) VALUES (?, ?) "
|
|
170
|
+
"ON CONFLICT(group_id, finding_id) DO NOTHING",
|
|
171
|
+
((group_id, finding_id) for finding_id in members),
|
|
172
|
+
)
|
|
173
|
+
created_at = connection.execute(
|
|
174
|
+
"SELECT created_at FROM finding_dedupe_groups WHERE id = ?", (group_id,)
|
|
175
|
+
).fetchone()[0]
|
|
176
|
+
stored[group_id] = {
|
|
177
|
+
"groupId": group_id,
|
|
178
|
+
"findingIds": members,
|
|
179
|
+
"createdAt": created_at,
|
|
180
|
+
}
|
|
181
|
+
except sqlite3.IntegrityError:
|
|
182
|
+
return {"error": "finding_conflict"}
|
|
183
|
+
return {"groups": list(stored.values())}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def list_dedupe_groups(connection: sqlite3.Connection, finding_id: str) -> dict[str, Any]:
|
|
187
|
+
groups: dict[str, dict[str, Any]] = {}
|
|
188
|
+
rows = connection.execute(
|
|
189
|
+
"""
|
|
190
|
+
SELECT groups.id, groups.created_at, members.finding_id
|
|
191
|
+
FROM finding_dedupe_group_members AS matched
|
|
192
|
+
JOIN finding_dedupe_groups AS groups ON groups.id = matched.group_id
|
|
193
|
+
JOIN finding_dedupe_group_members AS members ON members.group_id = groups.id
|
|
194
|
+
WHERE matched.finding_id = ?
|
|
195
|
+
ORDER BY groups.created_at, groups.id, members.finding_id
|
|
196
|
+
""",
|
|
197
|
+
(finding_id,),
|
|
198
|
+
)
|
|
199
|
+
for row in rows:
|
|
200
|
+
group = groups.setdefault(
|
|
201
|
+
row["id"],
|
|
202
|
+
{"groupId": row["id"], "findingIds": [], "createdAt": row["created_at"]},
|
|
203
|
+
)
|
|
204
|
+
group["findingIds"].append(row["finding_id"])
|
|
205
|
+
return {"groups": list(groups.values())}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def normalized_vector(vector: list[float]) -> list[float]:
|
|
209
|
+
norm = math.hypot(*vector)
|
|
210
|
+
if norm == 0 or not math.isfinite(norm):
|
|
211
|
+
raise ValueError("A stored embedding cannot be compared.")
|
|
212
|
+
return [value / norm for value in vector]
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
if __name__ == "__main__":
|
|
216
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
@@ -150,6 +150,10 @@ def _worker_candidate_key(
|
|
|
150
150
|
if isinstance(provenance, dict)
|
|
151
151
|
else finding.get("identity")
|
|
152
152
|
)
|
|
153
|
+
if not isinstance(identity, dict):
|
|
154
|
+
normalized = dict(finding)
|
|
155
|
+
_ensure_finding_identity(normalized)
|
|
156
|
+
identity = normalized.get("identity")
|
|
153
157
|
anchor = identity.get("anchor") if isinstance(identity, dict) else None
|
|
154
158
|
instance = identity.get("instance") if isinstance(identity, dict) else None
|
|
155
159
|
return worker_id, candidate_id, finding.get("ruleId"), anchor, instance
|
|
@@ -215,12 +219,13 @@ def merge_saved_results(
|
|
|
215
219
|
stopped: bool,
|
|
216
220
|
reason: str,
|
|
217
221
|
frozen_source_digests: dict[str, str] | None = None,
|
|
222
|
+
allow_frozen_legacy_parent: bool = False,
|
|
218
223
|
) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]] | None:
|
|
219
224
|
"""Read only bound parent/worker files; return an unsealed loss-preserving union."""
|
|
220
225
|
initial_warnings = set(warnings)
|
|
221
226
|
parent: dict[str, Any] | None = None
|
|
222
227
|
parent_manifest: dict[str, Any] | None = None
|
|
223
|
-
if frozen_source_digests is None:
|
|
228
|
+
if frozen_source_digests is None or allow_frozen_legacy_parent:
|
|
224
229
|
try:
|
|
225
230
|
parent_manifest = _read_scan_local_json(
|
|
226
231
|
scan_dir, "scan-manifest.json", "Saved parent manifest"
|
|
@@ -587,7 +592,9 @@ def merge_saved_results(
|
|
|
587
592
|
and coverage.get("completeness") in {"complete", "unknown"}
|
|
588
593
|
):
|
|
589
594
|
coverage["completeness"] = "partial"
|
|
590
|
-
if superseded and not stopped
|
|
595
|
+
if superseded and not stopped and all(
|
|
596
|
+
valid_finding(finding) for finding in (parent["findings"] if parent else [])
|
|
597
|
+
):
|
|
591
598
|
continue
|
|
592
599
|
if "threatModel" not in manifest["scan"] and isinstance(draft.get("threatModel"), dict):
|
|
593
600
|
manifest["scan"]["threatModel"] = copy.deepcopy(draft["threatModel"])
|
|
@@ -668,9 +675,7 @@ def merge_saved_results(
|
|
|
668
675
|
mapped_key = represented[key]
|
|
669
676
|
historical_contents = represented_history.get(key, set())
|
|
670
677
|
elif worker_id and candidate_id:
|
|
671
|
-
candidate_key = _worker_candidate_key(
|
|
672
|
-
worker_id, candidate_id, finding
|
|
673
|
-
)
|
|
678
|
+
candidate_key = _worker_candidate_key(worker_id, candidate_id, finding)
|
|
674
679
|
if candidate_key not in represented_candidates:
|
|
675
680
|
represented_candidates[candidate_key] = key
|
|
676
681
|
mapped_key = represented_candidates[candidate_key]
|
|
@@ -1002,6 +1007,12 @@ def preserve_scan_results_locked(db: Any, connection: Any, scan_id: str) -> bool
|
|
|
1002
1007
|
f"{scan['failure_message'] or ''}"
|
|
1003
1008
|
).strip(),
|
|
1004
1009
|
frozen_source_digests=frozen_source_digests,
|
|
1010
|
+
allow_frozen_legacy_parent=(
|
|
1011
|
+
frozen_source_digests == {}
|
|
1012
|
+
and isinstance(existing_scan, dict)
|
|
1013
|
+
and existing_scan.get("sealedAt") is not None
|
|
1014
|
+
and "preservedSources" not in existing_scan
|
|
1015
|
+
),
|
|
1005
1016
|
)
|
|
1006
1017
|
if documents is None:
|
|
1007
1018
|
unpublished_warnings = list(dict.fromkeys([*warnings, *publication_follow_up_warnings]))
|
|
@@ -1013,6 +1024,20 @@ def preserve_scan_results_locked(db: Any, connection: Any, scan_id: str) -> bool
|
|
|
1013
1024
|
(json.dumps(unpublished_warnings), db.now(), scan_id),
|
|
1014
1025
|
)
|
|
1015
1026
|
return False
|
|
1027
|
+
if frozen_source_digests is None:
|
|
1028
|
+
retained_sources = documents[0].get("scan", {}).get("preservedSources")
|
|
1029
|
+
if not isinstance(retained_sources, dict) or not all(
|
|
1030
|
+
isinstance(relative, str) and isinstance(digest, str)
|
|
1031
|
+
for relative, digest in retained_sources.items()
|
|
1032
|
+
):
|
|
1033
|
+
raise ContractError("Stopped scan source digests could not be frozen.")
|
|
1034
|
+
frozen_source_digests = retained_sources
|
|
1035
|
+
with connection:
|
|
1036
|
+
connection.execute(
|
|
1037
|
+
"UPDATE scans SET retained_source_digests_json = ? "
|
|
1038
|
+
"WHERE id = ? AND retained_source_digests_json IS NULL",
|
|
1039
|
+
(json.dumps(retained_sources, sort_keys=True), scan_id),
|
|
1040
|
+
)
|
|
1016
1041
|
prepared = _prepare_scan_finalization(
|
|
1017
1042
|
scan_dir,
|
|
1018
1043
|
expected_coverage_mode=db.expected_coverage_mode(scan),
|