@openai/codex-security 0.1.30 → 0.2.0
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 +386 -37
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- 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/artifact-storage.md +4 -4
- package/_bundled_plugin/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -2
- package/_bundled_plugin/references/final-report.md +4 -2
- package/_bundled_plugin/references/scan-artifacts.md +2 -2
- package/_bundled_plugin/references/scan-contract.md +2 -2
- package/_bundled_plugin/references/threat-model.md +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +22 -0
- package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +19 -4
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
- package/_bundled_plugin/scripts/config_preflight.py +4 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
- package/_bundled_plugin/scripts/finding_preview.py +42 -82
- package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
- package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
- package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
- package/_bundled_plugin/scripts/rank_preview.py +86 -68
- package/_bundled_plugin/scripts/report_projection.py +37 -58
- package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
- package/_bundled_plugin/scripts/workbench/storage.py +11 -0
- package/_bundled_plugin/scripts/workbench_cli.py +11 -17
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +116 -228
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
- package/_bundled_plugin/scripts/workbench_progress.py +12 -34
- package/_bundled_plugin/scripts/workbench_publication.py +47 -62
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
- package/_bundled_plugin/scripts/workbench_schema.py +86 -271
- package/_bundled_plugin/scripts/workbench_severity.py +3 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
- package/_bundled_plugin/scripts/workbench_target.py +98 -10
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +6 -20
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/dist/api.d.ts +3 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +201 -207
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +277 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +9 -4
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +2 -8
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -5
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +281 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +21 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +673 -701
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +1 -8
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +2 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +30 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +2 -6
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +1 -0
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +31 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -33
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +63 -122
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +65 -34
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -31
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +4 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +17 -16
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +10 -11
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +2 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +3 -3
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +2 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js +40 -62
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +1 -4
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +2 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +24 -6
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.js.map +1 -1
- package/dist/deduplication/scan.js +3 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +3 -19
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +0 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +22 -40
- package/dist/deep-progress.js.map +1 -1
- package/dist/errors.d.ts +3 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -7
- package/dist/errors.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +22 -22
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +4 -7
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +7 -17
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +2 -3
- package/dist/github.js.map +1 -1
- package/dist/import-scan.js +2 -2
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +7 -3
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -3
- package/dist/linear.js.map +1 -1
- package/dist/models.d.ts +24 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +36 -31
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +29 -0
- package/dist/owner-evidence.d.ts.map +1 -0
- package/dist/owner-evidence.js +192 -0
- package/dist/owner-evidence.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +2 -4
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -0
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +15 -29
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -13
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +11 -14
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +31 -41
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- package/dist/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +10 -13
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +230 -145
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +10 -20
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +8 -22
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +4 -4
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +38 -73
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +0 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +10 -19
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +1 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +2 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +1 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +8 -6
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +8 -4
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +98 -84
- package/dist/security-policy.js.map +1 -1
- package/dist/server/dashboard/app.js +5 -5
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +1 -0
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/routes.d.ts +3 -2
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +19 -7
- package/dist/server/routes.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +2 -3
- package/dist/server/server.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +4 -14
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-store.js +8 -15
- package/dist/severity-store.js.map +1 -1
- package/dist/suggest-owners.d.ts +37 -0
- package/dist/suggest-owners.d.ts.map +1 -0
- package/dist/suggest-owners.js +111 -0
- package/dist/suggest-owners.js.map +1 -0
- package/dist/targets.d.ts +7 -2
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +29 -25
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +1 -0
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/thread-source.js +1 -0
- package/dist/thread-source.js.map +1 -1
- package/dist/trusted-executable.d.ts +5 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +22 -5
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +20 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.js.map +1 -1
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +13 -34
- package/dist/worker-progress.js.map +1 -1
- package/docs/dedupe-records.md +24 -0
- package/package.json +15 -13
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- package/dist/server/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.js.map +0 -1
|
@@ -52,15 +52,10 @@ def index_findings(
|
|
|
52
52
|
document: dict[str, Any],
|
|
53
53
|
timestamp: str,
|
|
54
54
|
) -> None:
|
|
55
|
-
findings = document.get("findings")
|
|
56
|
-
if not isinstance(findings, list):
|
|
57
|
-
raise SystemExit("findings.json must contain a findings array.")
|
|
58
55
|
repository_id = connection.execute(
|
|
59
56
|
"SELECT target_id FROM scans WHERE id = ?", (scan_id,)
|
|
60
57
|
).fetchone()["target_id"]
|
|
61
|
-
for finding in findings:
|
|
62
|
-
if not isinstance(finding, dict):
|
|
63
|
-
raise SystemExit("findings.json entries must be objects.")
|
|
58
|
+
for finding in document["findings"]:
|
|
64
59
|
severity = finding["severity"]
|
|
65
60
|
confidence = finding["confidence"]
|
|
66
61
|
upsert_finding(connection, finding, timestamp, repository_id)
|
|
@@ -192,10 +192,7 @@ def list_repositories(
|
|
|
192
192
|
) -> dict[str, Any]:
|
|
193
193
|
scans = scan_history.list_scans(connection)["scans"]
|
|
194
194
|
scans_by_id = {scan["scanId"]: scan for scan in scans}
|
|
195
|
-
scan_count_by_target
|
|
196
|
-
for scan in scans:
|
|
197
|
-
target_id = scan["targetId"]
|
|
198
|
-
scan_count_by_target[target_id] = scan_count_by_target.get(target_id, 0) + 1
|
|
195
|
+
scan_count_by_target = dict(Counter(scan["targetId"] for scan in scans))
|
|
199
196
|
|
|
200
197
|
latest_scan_by_target: dict[str, dict[str, Any]] = {}
|
|
201
198
|
for row in connection.execute(
|
|
@@ -16,15 +16,12 @@ from workbench_validation import optional_text, require_uuid, user_context_argum
|
|
|
16
16
|
MAX_PREFLIGHT_ISSUES = 32
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
def _javascript_string_length(value: str) -> int:
|
|
20
|
-
return len(value.encode("utf-16-le", errors="surrogatepass")) // 2
|
|
21
|
-
|
|
22
|
-
|
|
23
19
|
def _preflight_issue_text(value: Any, maximum: int, label: str) -> str:
|
|
24
20
|
if not isinstance(value, str):
|
|
25
21
|
raise SystemExit(f"Preflight issue {label} must be text.")
|
|
26
22
|
normalized = value.strip()
|
|
27
|
-
|
|
23
|
+
# Match JavaScript's UTF-16 code-unit length.
|
|
24
|
+
if not normalized or len(normalized.encode("utf-16-le", errors="surrogatepass")) // 2 > maximum:
|
|
28
25
|
raise SystemExit(f"Preflight issue {label} must contain 1 to {maximum} characters.")
|
|
29
26
|
return normalized
|
|
30
27
|
|
|
@@ -85,7 +82,7 @@ def update_context(
|
|
|
85
82
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
86
83
|
context = user_context_argument(args)
|
|
87
84
|
connection.execute("BEGIN IMMEDIATE")
|
|
88
|
-
|
|
85
|
+
with connection:
|
|
89
86
|
scan = require_scan(connection, scan_id)
|
|
90
87
|
if scan["status"] != "running" or scan["canceled_at"] is not None:
|
|
91
88
|
raise SystemExit("Only a running scan can update context.")
|
|
@@ -120,10 +117,6 @@ def update_context(
|
|
|
120
117
|
"UPDATE workspaces SET updated_at = ? WHERE id = ?",
|
|
121
118
|
(timestamp, workspace["id"]),
|
|
122
119
|
)
|
|
123
|
-
connection.commit()
|
|
124
|
-
except BaseException:
|
|
125
|
-
connection.rollback()
|
|
126
|
-
raise
|
|
127
120
|
return scan_context(connection, scan_id)
|
|
128
121
|
|
|
129
122
|
|
|
@@ -169,7 +162,7 @@ def update_progress(
|
|
|
169
162
|
)
|
|
170
163
|
serialized_preflight_issues = preflight_issues_json(preflight_issues)
|
|
171
164
|
connection.execute("BEGIN IMMEDIATE")
|
|
172
|
-
|
|
165
|
+
with connection:
|
|
173
166
|
timestamp = now()
|
|
174
167
|
scan = require_scan(connection, scan_id)
|
|
175
168
|
if scan["status"] != "running":
|
|
@@ -233,8 +226,12 @@ def update_progress(
|
|
|
233
226
|
and args.phase_progress_unit != progress["phase_progress_unit"]
|
|
234
227
|
):
|
|
235
228
|
raise SystemExit("Phase progress unit cannot change within a phase.")
|
|
236
|
-
updates: list[str] = [
|
|
237
|
-
|
|
229
|
+
updates: list[str] = [
|
|
230
|
+
"phase_items_total = ?",
|
|
231
|
+
"phase_items_completed = ?",
|
|
232
|
+
"phase_progress_unit = ?",
|
|
233
|
+
]
|
|
234
|
+
values: list[Any] = [phase_total, phase_completed, phase_unit]
|
|
238
235
|
if next_phase == "preflight" and scan["mode"] != "deep":
|
|
239
236
|
updates.extend(["preflight_checks_total = ?", "preflight_checks_completed = ?"])
|
|
240
237
|
values.extend([phase_total, phase_completed])
|
|
@@ -288,29 +285,10 @@ def update_progress(
|
|
|
288
285
|
)
|
|
289
286
|
if updated.rowcount != 1:
|
|
290
287
|
raise SystemExit("Only a running scan can update progress.")
|
|
291
|
-
if updates:
|
|
292
|
-
connection.execute(
|
|
293
|
-
f"UPDATE scan_progress SET {', '.join(updates)}, updated_at = ? WHERE scan_id = ?",
|
|
294
|
-
(*values, timestamp, scan["id"]),
|
|
295
|
-
)
|
|
296
|
-
else:
|
|
297
|
-
connection.execute(
|
|
298
|
-
"UPDATE scan_progress SET updated_at = ? WHERE scan_id = ?",
|
|
299
|
-
(timestamp, scan["id"]),
|
|
300
|
-
)
|
|
301
288
|
connection.execute(
|
|
302
|
-
""
|
|
303
|
-
|
|
304
|
-
SET phase_items_total = ?, phase_items_completed = ?,
|
|
305
|
-
phase_progress_unit = ?, updated_at = ?
|
|
306
|
-
WHERE scan_id = ?
|
|
307
|
-
""",
|
|
308
|
-
(phase_total, phase_completed, phase_unit, timestamp, scan["id"]),
|
|
289
|
+
f"UPDATE scan_progress SET {', '.join(updates)}, updated_at = ? WHERE scan_id = ?",
|
|
290
|
+
(*values, timestamp, scan["id"]),
|
|
309
291
|
)
|
|
310
|
-
connection.commit()
|
|
311
|
-
except BaseException:
|
|
312
|
-
connection.rollback()
|
|
313
|
-
raise
|
|
314
292
|
return scan_context(connection, scan["id"])
|
|
315
293
|
|
|
316
294
|
|
|
@@ -7,44 +7,29 @@ import csv
|
|
|
7
7
|
import io
|
|
8
8
|
import os
|
|
9
9
|
import sqlite3
|
|
10
|
-
|
|
10
|
+
import sys
|
|
11
11
|
from contextlib import closing
|
|
12
|
-
from dataclasses import dataclass
|
|
13
12
|
from pathlib import Path
|
|
14
13
|
from typing import Any
|
|
15
14
|
from urllib.parse import quote
|
|
16
15
|
|
|
16
|
+
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
17
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
18
|
from finalize_scan_contract import (
|
|
18
19
|
ContractError,
|
|
20
|
+
build_threat_model_export,
|
|
19
21
|
csv_cell,
|
|
20
22
|
finalize_scan,
|
|
21
23
|
finding_candidate_id,
|
|
24
|
+
finding_csv_columns,
|
|
25
|
+
write_export_output,
|
|
22
26
|
write_sarif_projection,
|
|
23
27
|
write_scan_local_bytes,
|
|
24
28
|
)
|
|
25
29
|
|
|
26
30
|
|
|
27
|
-
@dataclass(frozen=True)
|
|
28
|
-
class WorkbenchPublicationContext:
|
|
29
|
-
ARTIFACTS: dict[str, str]
|
|
30
|
-
artifact_path: Callable[..., Path | None]
|
|
31
|
-
available_artifact_path: Callable[[Path, Path], Path | None]
|
|
32
|
-
database_path: Callable[[], Path]
|
|
33
|
-
expected_coverage_mode: Callable[[sqlite3.Row], str]
|
|
34
|
-
now: Callable[[], str]
|
|
35
|
-
pin_legacy_manifest_digest: Callable[[sqlite3.Connection, str, str], None]
|
|
36
|
-
published_manifest_digest: Callable[[Path, dict[str, Any]], str]
|
|
37
|
-
read_json_object: Callable[[Path], dict[str, Any]]
|
|
38
|
-
require_canonical_scan_directory: Callable[[Path], Path]
|
|
39
|
-
require_recorded_manifest_digest: Callable[[sqlite3.Row, Path], str]
|
|
40
|
-
require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row]
|
|
41
|
-
scan_result: Callable[[sqlite3.Connection, sqlite3.Row], dict[str, Any]]
|
|
42
|
-
verify_manifest_binding: Callable[[sqlite3.Row, dict[str, Any]], None]
|
|
43
|
-
workspace_state: Callable[[sqlite3.Connection, str], dict[str, Any]]
|
|
44
|
-
|
|
45
|
-
|
|
46
31
|
def linear_publication_input(
|
|
47
|
-
db:
|
|
32
|
+
db: Any,
|
|
48
33
|
args: argparse.Namespace,
|
|
49
34
|
*,
|
|
50
35
|
recording: bool,
|
|
@@ -107,7 +92,7 @@ def linear_publication_input(
|
|
|
107
92
|
|
|
108
93
|
|
|
109
94
|
def verify_linear_publication_scan(
|
|
110
|
-
db:
|
|
95
|
+
db: Any,
|
|
111
96
|
connection: sqlite3.Connection,
|
|
112
97
|
payload: dict[str, Any],
|
|
113
98
|
findings: list[dict[str, str]],
|
|
@@ -154,7 +139,7 @@ def verify_linear_publication_scan(
|
|
|
154
139
|
|
|
155
140
|
|
|
156
141
|
def inspect_linear_publication(
|
|
157
|
-
db:
|
|
142
|
+
db: Any,
|
|
158
143
|
args: argparse.Namespace,
|
|
159
144
|
) -> dict[str, Any]:
|
|
160
145
|
payload, destination, findings = linear_publication_input(db, args, recording=False)
|
|
@@ -203,28 +188,24 @@ def inspect_linear_publication(
|
|
|
203
188
|
|
|
204
189
|
|
|
205
190
|
def prepare_linear_publication(
|
|
206
|
-
db:
|
|
191
|
+
db: Any,
|
|
207
192
|
connection: sqlite3.Connection,
|
|
208
193
|
args: argparse.Namespace,
|
|
209
194
|
) -> dict[str, Any]:
|
|
210
195
|
payload, destination, findings = linear_publication_input(db, args, recording=False)
|
|
211
196
|
connection.execute("BEGIN IMMEDIATE")
|
|
212
|
-
|
|
197
|
+
with connection:
|
|
213
198
|
scan = verify_linear_publication_scan(db, connection, payload, findings)
|
|
214
199
|
result = {
|
|
215
200
|
"scanId": scan["id"],
|
|
216
201
|
"destination": destination,
|
|
217
202
|
"findingCount": len(findings),
|
|
218
203
|
}
|
|
219
|
-
connection.commit()
|
|
220
|
-
except BaseException:
|
|
221
|
-
connection.rollback()
|
|
222
|
-
raise
|
|
223
204
|
return result
|
|
224
205
|
|
|
225
206
|
|
|
226
207
|
def record_linear_publications(
|
|
227
|
-
db:
|
|
208
|
+
db: Any,
|
|
228
209
|
connection: sqlite3.Connection,
|
|
229
210
|
args: argparse.Namespace,
|
|
230
211
|
) -> dict[str, Any]:
|
|
@@ -264,7 +245,7 @@ def record_linear_publications(
|
|
|
264
245
|
external_ids.add(issue_identifier)
|
|
265
246
|
|
|
266
247
|
connection.execute("BEGIN IMMEDIATE")
|
|
267
|
-
|
|
248
|
+
with connection:
|
|
268
249
|
scan = verify_linear_publication_scan(db, connection, payload, findings)
|
|
269
250
|
timestamp = db.now()
|
|
270
251
|
for publication in publications:
|
|
@@ -349,28 +330,48 @@ def record_linear_publications(
|
|
|
349
330
|
}
|
|
350
331
|
)
|
|
351
332
|
result = {"scanId": scan["id"], "destination": destination, "created": created}
|
|
352
|
-
connection.commit()
|
|
353
|
-
except BaseException:
|
|
354
|
-
connection.rollback()
|
|
355
|
-
raise
|
|
356
333
|
return result
|
|
357
334
|
|
|
358
335
|
|
|
359
336
|
def export_findings(
|
|
360
|
-
db:
|
|
337
|
+
db: Any,
|
|
361
338
|
connection: sqlite3.Connection,
|
|
362
339
|
args: argparse.Namespace,
|
|
363
340
|
) -> dict[str, Any]:
|
|
364
341
|
scan = db.require_scan(connection, args.scan_id)
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
"
|
|
370
|
-
|
|
342
|
+
artifact = getattr(args, "artifact", "findings")
|
|
343
|
+
args.format = args.format or ("md" if artifact == "threat-model" else "csv")
|
|
344
|
+
if artifact == "threat-model":
|
|
345
|
+
if args.format != "md":
|
|
346
|
+
raise SystemExit("Threat models can only be exported as Markdown (md).")
|
|
347
|
+
else:
|
|
348
|
+
if args.format == "md":
|
|
349
|
+
raise SystemExit("Markdown export requires --artifact threat-model.")
|
|
350
|
+
if scan["status"] != "complete" and not (
|
|
351
|
+
scan["status"] == "failed" and scan["seal_manifest_digest"]
|
|
352
|
+
):
|
|
353
|
+
raise SystemExit(
|
|
354
|
+
"Findings can be exported after the scan completes or preserves stopped results."
|
|
355
|
+
)
|
|
371
356
|
scan_dir = db.require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
372
357
|
db.require_recorded_manifest_digest(scan, scan_dir)
|
|
373
|
-
|
|
358
|
+
manifest_path = scan_dir / db.ARTIFACTS["manifest"]
|
|
359
|
+
db.verify_manifest_binding(scan, db.read_json_object(manifest_path))
|
|
360
|
+
if getattr(args, "validate_only", False):
|
|
361
|
+
# SDK/CLI exports use their requested destination without modifying saved artifacts.
|
|
362
|
+
return {"scan": {"scanId": scan["id"], "scanDir": str(scan_dir)}}
|
|
363
|
+
if artifact == "threat-model":
|
|
364
|
+
path = scan_dir / "exports" / "threatmodel.md"
|
|
365
|
+
try:
|
|
366
|
+
contents = build_threat_model_export(scan_dir)
|
|
367
|
+
write_export_output(scan_dir, path, "md", contents)
|
|
368
|
+
except ContractError as exc:
|
|
369
|
+
raise SystemExit(str(exc)) from exc
|
|
370
|
+
return {
|
|
371
|
+
"export": {"artifact": artifact, "format": "md", "path": str(path)},
|
|
372
|
+
"scan": db.scan_result(connection, scan),
|
|
373
|
+
"workspace": db.workspace_state(connection, scan["workspace_id"]),
|
|
374
|
+
}
|
|
374
375
|
try:
|
|
375
376
|
manifest, _, _ = finalize_scan(
|
|
376
377
|
scan_dir,
|
|
@@ -401,7 +402,7 @@ def export_findings(
|
|
|
401
402
|
|
|
402
403
|
|
|
403
404
|
def write_csv_export(
|
|
404
|
-
db:
|
|
405
|
+
db: Any,
|
|
405
406
|
connection: sqlite3.Connection,
|
|
406
407
|
scan: sqlite3.Row,
|
|
407
408
|
) -> Path:
|
|
@@ -422,23 +423,7 @@ def write_csv_export(
|
|
|
422
423
|
candidate_id = finding_candidate_id(finding)
|
|
423
424
|
if isinstance(occurrence_id, str) and isinstance(candidate_id, str):
|
|
424
425
|
candidate_ids_by_occurrence[occurrence_id] = candidate_id
|
|
425
|
-
|
|
426
|
-
"occurrence_id",
|
|
427
|
-
"finding_id",
|
|
428
|
-
*(("candidate_id",) if deep_scan else ()),
|
|
429
|
-
"title",
|
|
430
|
-
"summary",
|
|
431
|
-
"severity",
|
|
432
|
-
"confidence",
|
|
433
|
-
"status",
|
|
434
|
-
"close_reason",
|
|
435
|
-
"note",
|
|
436
|
-
"remediation",
|
|
437
|
-
"path",
|
|
438
|
-
"start_line",
|
|
439
|
-
"end_line",
|
|
440
|
-
)
|
|
441
|
-
writer.writerow(columns)
|
|
426
|
+
writer.writerow(finding_csv_columns(deep_scan))
|
|
442
427
|
for row in finding_export_rows(connection, scan["id"]):
|
|
443
428
|
writer.writerow(
|
|
444
429
|
(
|
|
@@ -90,35 +90,25 @@ def require_pending_action(current: sqlite3.Row, requested: str) -> None:
|
|
|
90
90
|
)
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
def register_cancel_finding_remediation_request(subparsers: Any) -> None:
|
|
94
|
-
parser = subparsers.add_parser("cancel-finding-remediation-request")
|
|
95
|
-
parser.add_argument("--occurrence-id", required=True)
|
|
96
|
-
parser.add_argument("--request-id", required=True)
|
|
97
|
-
parser.add_argument("--action-token", required=True)
|
|
98
|
-
|
|
99
|
-
|
|
100
93
|
def cancel_finding_remediation_request(
|
|
101
94
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
102
95
|
) -> str:
|
|
103
96
|
request_id = require_uuid(args.request_id, "request-id")
|
|
104
97
|
action_token = require_uuid(args.action_token, "action-token")
|
|
105
98
|
connection.execute("BEGIN IMMEDIATE")
|
|
106
|
-
|
|
99
|
+
with connection:
|
|
107
100
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
108
101
|
current = connection.execute(
|
|
109
102
|
"SELECT * FROM finding_remediation_attempts WHERE request_id = ?",
|
|
110
103
|
(request_id,),
|
|
111
104
|
).fetchone()
|
|
112
105
|
if current is None:
|
|
113
|
-
connection.commit()
|
|
114
106
|
return str(occurrence["scan_id"])
|
|
115
107
|
if current["occurrence_id"] != occurrence["id"]:
|
|
116
108
|
raise SystemExit("This remediation request belongs to a different finding.")
|
|
117
109
|
if current["pending_action"] is None:
|
|
118
|
-
connection.commit()
|
|
119
110
|
return str(occurrence["scan_id"])
|
|
120
111
|
if current["state"] == "failed" and current["pending_action_claim_token"] is None:
|
|
121
|
-
connection.commit()
|
|
122
112
|
return str(occurrence["scan_id"])
|
|
123
113
|
if current["pending_action_claim_token"] != action_token:
|
|
124
114
|
raise SystemExit("This remediation host request is owned by a different action token.")
|
|
@@ -152,10 +142,6 @@ def cancel_finding_remediation_request(
|
|
|
152
142
|
""",
|
|
153
143
|
(timestamp, request_id, action_token),
|
|
154
144
|
)
|
|
155
|
-
connection.commit()
|
|
156
|
-
except BaseException:
|
|
157
|
-
connection.rollback()
|
|
158
|
-
raise
|
|
159
145
|
return str(occurrence["scan_id"])
|
|
160
146
|
|
|
161
147
|
|
|
@@ -193,9 +179,5 @@ def _cancel_generation(
|
|
|
193
179
|
)
|
|
194
180
|
|
|
195
181
|
|
|
196
|
-
def main() -> None:
|
|
197
|
-
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
198
|
-
|
|
199
|
-
|
|
200
182
|
if __name__ == "__main__":
|
|
201
|
-
|
|
183
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|