@openai/codex-security 0.1.21 → 0.1.24
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 +549 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +1 -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/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/references/scan-contract.md +10 -0
- package/_bundled_plugin/scripts/config_preflight.py +2 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +115 -76
- package/_bundled_plugin/scripts/finding_preview.py +22 -4
- package/_bundled_plugin/scripts/generate_in_scope_files.py +29 -9
- package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
- package/_bundled_plugin/scripts/rank_preview.py +1 -0
- package/_bundled_plugin/scripts/report_projection.py +8 -14
- package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
- package/_bundled_plugin/scripts/windows_scan_local_files.py +90 -6
- package/_bundled_plugin/scripts/workbench_cli.py +27 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +138 -0
- package/_bundled_plugin/scripts/workbench_db.py +110 -539
- package/_bundled_plugin/scripts/workbench_finding_index.py +42 -24
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +208 -0
- package/_bundled_plugin/scripts/workbench_findings.py +221 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
- package/_bundled_plugin/scripts/workbench_publication.py +520 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +322 -89
- package/_bundled_plugin/scripts/workbench_scan_history.py +1 -2
- package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
- package/_bundled_plugin/scripts/workbench_schema.py +276 -58
- package/_bundled_plugin/scripts/workbench_target.py +30 -6
- package/_bundled_plugin/scripts/workbench_validation.py +1 -5
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +2 -0
- package/dist/api.d.ts +5 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +135 -27
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +158 -62
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +5 -1
- package/dist/cloud-publish.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/deep-progress.d.ts +21 -0
- package/dist/deep-progress.d.ts.map +1 -0
- package/dist/deep-progress.js +108 -0
- package/dist/deep-progress.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/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/publication.js +28 -40
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +119 -13
- 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-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +12 -2
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +3 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +1 -1
- 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 +6 -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/serve.d.ts +2 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +28 -0
- package/dist/server/serve.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/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 +17 -5
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
6
|
import argparse
|
|
7
|
-
import csv
|
|
8
7
|
import errno
|
|
9
8
|
import hashlib
|
|
10
|
-
import io
|
|
11
9
|
import json
|
|
12
10
|
import os
|
|
13
11
|
import re
|
|
@@ -21,7 +19,6 @@ from contextlib import closing, contextmanager
|
|
|
21
19
|
from datetime import datetime, timedelta, timezone
|
|
22
20
|
from pathlib import Path, PurePosixPath
|
|
23
21
|
from typing import Any
|
|
24
|
-
from urllib.parse import quote
|
|
25
22
|
|
|
26
23
|
try:
|
|
27
24
|
import fcntl as posix_file_lock
|
|
@@ -37,11 +34,14 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
37
34
|
import deep_scan_workbench as deep_scan
|
|
38
35
|
import workbench_native_indexes as native_indexes
|
|
39
36
|
import workbench_progress as progress
|
|
37
|
+
import workbench_publication as publication
|
|
40
38
|
import workbench_remediation as remediation
|
|
41
39
|
import workbench_saved_results as saved_results
|
|
42
40
|
import workbench_scan_history as scan_history
|
|
43
41
|
import workbench_scan_usage as scan_usage
|
|
44
|
-
from filesystem_identity import
|
|
42
|
+
from filesystem_identity import (
|
|
43
|
+
serialize_filesystem_identity as serialize_filesystem_identity,
|
|
44
|
+
)
|
|
45
45
|
from filesystem_identity import (
|
|
46
46
|
stored_filesystem_identity_matches as stored_filesystem_identity_matches,
|
|
47
47
|
)
|
|
@@ -51,11 +51,9 @@ from finalize_scan_contract import (
|
|
|
51
51
|
RecoverableContractError,
|
|
52
52
|
_prepare_scan_finalization,
|
|
53
53
|
_write_prepared_scan_finalization,
|
|
54
|
-
csv_cell,
|
|
55
54
|
finalize_scan,
|
|
56
55
|
finding_candidate_id,
|
|
57
56
|
open_scan_local_file_descriptor,
|
|
58
|
-
write_sarif_projection,
|
|
59
57
|
write_scan_local_bytes,
|
|
60
58
|
)
|
|
61
59
|
from finding_preview import bounded_finding_details
|
|
@@ -80,8 +78,17 @@ from workbench_constants import (
|
|
|
80
78
|
PATCH_PREVIEW_BYTES,
|
|
81
79
|
SQLITE_RETRY_ATTEMPTS,
|
|
82
80
|
)
|
|
81
|
+
from workbench_dashboard import dashboard
|
|
83
82
|
from workbench_feedback import get_scan_feedback
|
|
84
83
|
from workbench_finding_index import index_findings
|
|
84
|
+
from workbench_finding_workflows import finding_workflow, register_workflow_scan
|
|
85
|
+
from workbench_findings import (
|
|
86
|
+
find_potential_duplicates,
|
|
87
|
+
list_dedupe_groups,
|
|
88
|
+
list_stored_findings,
|
|
89
|
+
store_dedupe_groups,
|
|
90
|
+
store_findings,
|
|
91
|
+
)
|
|
85
92
|
from workbench_remediation import remediation_claim_is_active
|
|
86
93
|
from workbench_scan_start import (
|
|
87
94
|
archive_scan,
|
|
@@ -1014,7 +1021,10 @@ def _start_prompt_driven_scan(
|
|
|
1014
1021
|
).fetchone()
|
|
1015
1022
|
if existing is not None:
|
|
1016
1023
|
connection.commit()
|
|
1017
|
-
return {
|
|
1024
|
+
return {
|
|
1025
|
+
**scan_context(connection, existing["id"]),
|
|
1026
|
+
"startDisposition": "joined",
|
|
1027
|
+
}
|
|
1018
1028
|
target_root.mkdir(parents=True, exist_ok=True)
|
|
1019
1029
|
workspace_id = str(uuid.uuid4())
|
|
1020
1030
|
scan_id = str(uuid.uuid4())
|
|
@@ -1125,7 +1135,10 @@ def pin_legacy_manifest_digest(
|
|
|
1125
1135
|
|
|
1126
1136
|
|
|
1127
1137
|
def complete_scan(
|
|
1128
|
-
connection: sqlite3.Connection,
|
|
1138
|
+
connection: sqlite3.Connection,
|
|
1139
|
+
args: argparse.Namespace,
|
|
1140
|
+
*,
|
|
1141
|
+
prepare_only: bool = False,
|
|
1129
1142
|
) -> dict[str, Any]:
|
|
1130
1143
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1131
1144
|
cost_json = None if prepare_only else parse_scan_cost(args.cost_json)
|
|
@@ -1338,8 +1351,7 @@ def budget_exhausted_draft(
|
|
|
1338
1351
|
existing_deferred = {
|
|
1339
1352
|
item.get("candidateId", item.get("id"))
|
|
1340
1353
|
for item in coverage["deferred"]
|
|
1341
|
-
if isinstance(item, dict)
|
|
1342
|
-
and isinstance(item.get("candidateId", item.get("id")), str)
|
|
1354
|
+
if isinstance(item, dict) and isinstance(item.get("candidateId", item.get("id")), str)
|
|
1343
1355
|
}
|
|
1344
1356
|
existing_surfaces = {
|
|
1345
1357
|
item.get("id")
|
|
@@ -1542,9 +1554,7 @@ def complete_scan_locked(
|
|
|
1542
1554
|
wrote = True
|
|
1543
1555
|
manifest, findings, _ = _write_prepared_scan_finalization(prepared)
|
|
1544
1556
|
except ContractError as exc:
|
|
1545
|
-
if wrote or (
|
|
1546
|
-
scan["mode"] == "deep" and not isinstance(exc, RecoverableContractError)
|
|
1547
|
-
):
|
|
1557
|
+
if wrote or (scan["mode"] == "deep" and not isinstance(exc, RecoverableContractError)):
|
|
1548
1558
|
args = argparse.Namespace(claim_token=claim_token, cost_json=cost_json)
|
|
1549
1559
|
args.message, args.scan_id = str(exc), scan_id
|
|
1550
1560
|
fail_scan_locked(connection, args)
|
|
@@ -1651,10 +1661,12 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1651
1661
|
raise SystemExit("The scan artifact directory must be empty before the scan starts.")
|
|
1652
1662
|
|
|
1653
1663
|
user_context = None
|
|
1664
|
+
workflow_id = None
|
|
1654
1665
|
if args.registration_json_stdin:
|
|
1655
1666
|
registration = json.load(sys.stdin)
|
|
1656
1667
|
recipe_json = json.dumps(registration["recipe"], ensure_ascii=False, separators=(",", ":"))
|
|
1657
1668
|
user_context = registration.get("userContext")
|
|
1669
|
+
workflow_id = registration.get("workflowId")
|
|
1658
1670
|
else:
|
|
1659
1671
|
recipe_json = sys.stdin.read() if args.recipe_json_stdin else args.recipe_json
|
|
1660
1672
|
recipe = parse_scan_recipe(recipe_json, repository)
|
|
@@ -1750,6 +1762,8 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1750
1762
|
scan_id,
|
|
1751
1763
|
),
|
|
1752
1764
|
)
|
|
1765
|
+
if workflow_id is not None:
|
|
1766
|
+
register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
|
|
1753
1767
|
connection.commit()
|
|
1754
1768
|
except BaseException:
|
|
1755
1769
|
connection.rollback()
|
|
@@ -1848,20 +1862,10 @@ def preserve_scan_results_locked(connection: sqlite3.Connection, scan_id: str) -
|
|
|
1848
1862
|
return saved_results.preserve_scan_results_locked(_WORKBENCH_DB_CONTEXT, connection, scan_id)
|
|
1849
1863
|
|
|
1850
1864
|
|
|
1851
|
-
def
|
|
1852
|
-
connection: sqlite3.Connection,
|
|
1853
|
-
) ->
|
|
1854
|
-
saved_results.
|
|
1855
|
-
_WORKBENCH_DB_CONTEXT, connection, scan_id, strict=strict
|
|
1856
|
-
)
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
def refresh_all_stopped_scan_results(connection: sqlite3.Connection) -> None:
|
|
1860
|
-
scan_ids = [
|
|
1861
|
-
row["id"] for row in connection.execute("SELECT id FROM scans WHERE status = 'failed'")
|
|
1862
|
-
]
|
|
1863
|
-
for scan_id in scan_ids:
|
|
1864
|
-
refresh_stopped_scan_results(connection, scan_id)
|
|
1865
|
+
def recover_scan_results(
|
|
1866
|
+
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1867
|
+
) -> dict[str, Any]:
|
|
1868
|
+
return saved_results.recover_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1865
1869
|
|
|
1866
1870
|
|
|
1867
1871
|
def preserve_scan_results(
|
|
@@ -1956,7 +1960,14 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1956
1960
|
id, occurrence_id, status, close_reason, note, created_at
|
|
1957
1961
|
) VALUES (?, ?, ?, ?, ?, ?)
|
|
1958
1962
|
""",
|
|
1959
|
-
(
|
|
1963
|
+
(
|
|
1964
|
+
str(uuid.uuid4()),
|
|
1965
|
+
occurrence["id"],
|
|
1966
|
+
args.status,
|
|
1967
|
+
close_reason,
|
|
1968
|
+
note,
|
|
1969
|
+
timestamp,
|
|
1970
|
+
),
|
|
1960
1971
|
)
|
|
1961
1972
|
connection.execute(
|
|
1962
1973
|
"""
|
|
@@ -2317,8 +2328,8 @@ def set_finding_remediation(
|
|
|
2317
2328
|
)
|
|
2318
2329
|
if current["pending_action_claim_token"] != action_token:
|
|
2319
2330
|
raise SystemExit("This remediation host request is owned by a different action token.")
|
|
2320
|
-
|
|
2321
|
-
|
|
2331
|
+
remediation.require_transition(current["state"], args.state)
|
|
2332
|
+
remediation.require_pending_action(current, args.state)
|
|
2322
2333
|
patch_path = current["patch_path"]
|
|
2323
2334
|
if args.patch_path is not None:
|
|
2324
2335
|
requested_patch_path = require_scan_relative_file(scan, args.patch_path)
|
|
@@ -2419,494 +2430,15 @@ def set_finding_remediation(
|
|
|
2419
2430
|
return scan_context(connection, occurrence["scan_id"])
|
|
2420
2431
|
|
|
2421
2432
|
|
|
2422
|
-
|
|
2423
|
-
args: argparse.Namespace, *, recording: bool
|
|
2424
|
-
) -> tuple[dict[str, Any], dict[str, str], list[dict[str, str]]]:
|
|
2425
|
-
payload = read_json_object(Path(args.input_file))
|
|
2426
|
-
required = {"scanId", "scanDirectory", "destination", "findings"}
|
|
2427
|
-
if recording:
|
|
2428
|
-
required.add("publications")
|
|
2429
|
-
if set(payload) != required:
|
|
2430
|
-
raise SystemExit("Linear publication input contains unexpected or missing fields.")
|
|
2431
|
-
|
|
2432
|
-
scan_id = payload["scanId"]
|
|
2433
|
-
scan_directory = payload["scanDirectory"]
|
|
2434
|
-
destination = payload["destination"]
|
|
2435
|
-
findings = payload["findings"]
|
|
2436
|
-
if not isinstance(scan_id, str) or not isinstance(scan_directory, str):
|
|
2437
|
-
raise SystemExit("Linear publication input must identify the exact completed scan.")
|
|
2438
|
-
if (
|
|
2439
|
-
not isinstance(destination, dict)
|
|
2440
|
-
or not {"type", "teamId"}.issubset(destination)
|
|
2441
|
-
or not set(destination).issubset({"type", "teamId", "projectId"})
|
|
2442
|
-
or destination.get("type") != "linear"
|
|
2443
|
-
or not isinstance(destination.get("teamId"), str)
|
|
2444
|
-
or not destination["teamId"].strip()
|
|
2445
|
-
or (
|
|
2446
|
-
"projectId" in destination
|
|
2447
|
-
and (
|
|
2448
|
-
not isinstance(destination["projectId"], str)
|
|
2449
|
-
or not destination["projectId"].strip()
|
|
2450
|
-
)
|
|
2451
|
-
)
|
|
2452
|
-
):
|
|
2453
|
-
raise SystemExit("Linear publication input must identify the exact team and optional project.")
|
|
2454
|
-
if not isinstance(findings, list):
|
|
2455
|
-
raise SystemExit("Linear publication input must include the planned scan findings.")
|
|
2456
|
-
|
|
2457
|
-
seen_finding_ids: set[str] = set()
|
|
2458
|
-
seen_occurrence_ids: set[str] = set()
|
|
2459
|
-
for finding in findings:
|
|
2460
|
-
if (
|
|
2461
|
-
not isinstance(finding, dict)
|
|
2462
|
-
or set(finding) != {"findingId", "occurrenceId"}
|
|
2463
|
-
or not isinstance(finding.get("findingId"), str)
|
|
2464
|
-
or not finding["findingId"].strip()
|
|
2465
|
-
or not isinstance(finding.get("occurrenceId"), str)
|
|
2466
|
-
or not finding["occurrenceId"].strip()
|
|
2467
|
-
):
|
|
2468
|
-
raise SystemExit("Linear publication input contains an invalid finding identity.")
|
|
2469
|
-
if (
|
|
2470
|
-
finding["findingId"] in seen_finding_ids
|
|
2471
|
-
or finding["occurrenceId"] in seen_occurrence_ids
|
|
2472
|
-
):
|
|
2473
|
-
raise SystemExit("Linear publication input repeats a finding or occurrence.")
|
|
2474
|
-
seen_finding_ids.add(finding["findingId"])
|
|
2475
|
-
seen_occurrence_ids.add(finding["occurrenceId"])
|
|
2476
|
-
|
|
2477
|
-
return payload, destination, findings
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
def verify_linear_publication_scan(
|
|
2481
|
-
connection: sqlite3.Connection,
|
|
2482
|
-
payload: dict[str, Any],
|
|
2483
|
-
findings: list[dict[str, str]],
|
|
2484
|
-
) -> sqlite3.Row:
|
|
2485
|
-
try:
|
|
2486
|
-
scan = require_scan(connection, payload["scanId"])
|
|
2487
|
-
except SystemExit as exc:
|
|
2488
|
-
raise SystemExit(
|
|
2489
|
-
"The completed scan is not present in the local Codex Security scan-history database. "
|
|
2490
|
-
"Use the state directory where the scan was completed."
|
|
2491
|
-
) from exc
|
|
2492
|
-
if scan["id"] != payload["scanId"]:
|
|
2493
|
-
raise SystemExit("Linear publication must use the exact completed scan identifier.")
|
|
2494
|
-
if scan["status"] != "complete":
|
|
2495
|
-
raise SystemExit("Only completed scans can publish findings to Linear.")
|
|
2496
|
-
|
|
2497
|
-
requested_directory = require_canonical_scan_directory(Path(payload["scanDirectory"]))
|
|
2498
|
-
recorded_directory = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
2499
|
-
if os.path.normcase(requested_directory) != os.path.normcase(recorded_directory):
|
|
2500
|
-
raise SystemExit(
|
|
2501
|
-
"The selected scan directory does not match its local Codex Security scan history."
|
|
2502
|
-
)
|
|
2503
|
-
if "seal_manifest_digest" in scan.keys():
|
|
2504
|
-
require_recorded_manifest_digest(scan, recorded_directory)
|
|
2505
|
-
|
|
2506
|
-
stored_findings = {
|
|
2507
|
-
row["id"]: row["finding_id"]
|
|
2508
|
-
for row in connection.execute(
|
|
2509
|
-
"SELECT id, finding_id FROM finding_occurrences WHERE scan_id = ?",
|
|
2510
|
-
(scan["id"],),
|
|
2511
|
-
)
|
|
2512
|
-
}
|
|
2513
|
-
for finding in findings:
|
|
2514
|
-
if stored_findings.get(finding["occurrenceId"]) != finding["findingId"]:
|
|
2515
|
-
raise SystemExit(
|
|
2516
|
-
"A selected finding or occurrence does not belong to the completed scan "
|
|
2517
|
-
"in local Codex Security scan history."
|
|
2518
|
-
)
|
|
2519
|
-
if len(stored_findings) != len(findings):
|
|
2520
|
-
raise SystemExit(
|
|
2521
|
-
"The completed scan findings do not exactly match local Codex Security scan history."
|
|
2522
|
-
)
|
|
2523
|
-
return scan
|
|
2433
|
+
_WORKBENCH_PUBLICATION_CONTEXT: publication.WorkbenchPublicationContext
|
|
2524
2434
|
|
|
2525
2435
|
|
|
2526
2436
|
def inspect_linear_publication(args: argparse.Namespace) -> dict[str, Any]:
|
|
2527
|
-
|
|
2528
|
-
database_uri = f"file:{quote(str(database_path()), safe='')}?mode=ro"
|
|
2529
|
-
with closing(sqlite3.connect(database_uri, uri=True, timeout=5)) as connection:
|
|
2530
|
-
connection.row_factory = sqlite3.Row
|
|
2531
|
-
connection.execute("BEGIN")
|
|
2532
|
-
scan = verify_linear_publication_scan(connection, payload, findings)
|
|
2533
|
-
recorded: dict[str, dict[str, str]] = {}
|
|
2534
|
-
if connection.execute(
|
|
2535
|
-
"SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'finding_publications'"
|
|
2536
|
-
).fetchone():
|
|
2537
|
-
for row in connection.execute(
|
|
2538
|
-
"""
|
|
2539
|
-
SELECT finding_id, occurrence_id, external_id, external_url
|
|
2540
|
-
FROM finding_publications
|
|
2541
|
-
WHERE scan_id = ? AND destination_type = ? AND team_id = ? AND project_id IS ?
|
|
2542
|
-
ORDER BY created_at, external_id
|
|
2543
|
-
""",
|
|
2544
|
-
(
|
|
2545
|
-
scan["id"],
|
|
2546
|
-
destination["type"],
|
|
2547
|
-
destination["teamId"],
|
|
2548
|
-
destination.get("projectId"),
|
|
2549
|
-
),
|
|
2550
|
-
):
|
|
2551
|
-
recorded.setdefault(
|
|
2552
|
-
row["occurrence_id"],
|
|
2553
|
-
{
|
|
2554
|
-
"findingId": row["finding_id"],
|
|
2555
|
-
"occurrenceId": row["occurrence_id"],
|
|
2556
|
-
"issueIdentifier": row["external_id"],
|
|
2557
|
-
**({"url": row["external_url"]} if row["external_url"] is not None else {}),
|
|
2558
|
-
},
|
|
2559
|
-
)
|
|
2560
|
-
return {
|
|
2561
|
-
"scanId": scan["id"],
|
|
2562
|
-
"destination": destination,
|
|
2563
|
-
"findingCount": len(findings),
|
|
2564
|
-
"recorded": [
|
|
2565
|
-
recorded[finding["occurrenceId"]]
|
|
2566
|
-
for finding in findings
|
|
2567
|
-
if finding["occurrenceId"] in recorded
|
|
2568
|
-
],
|
|
2569
|
-
}
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
def prepare_linear_publication(
|
|
2573
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
2574
|
-
) -> dict[str, Any]:
|
|
2575
|
-
payload, destination, findings = linear_publication_input(args, recording=False)
|
|
2576
|
-
connection.execute("BEGIN IMMEDIATE")
|
|
2577
|
-
try:
|
|
2578
|
-
scan = verify_linear_publication_scan(connection, payload, findings)
|
|
2579
|
-
result = {
|
|
2580
|
-
"scanId": scan["id"],
|
|
2581
|
-
"destination": destination,
|
|
2582
|
-
"findingCount": len(findings),
|
|
2583
|
-
}
|
|
2584
|
-
connection.commit()
|
|
2585
|
-
except BaseException:
|
|
2586
|
-
connection.rollback()
|
|
2587
|
-
raise
|
|
2588
|
-
return result
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
def record_linear_publications(
|
|
2592
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
2593
|
-
) -> dict[str, Any]:
|
|
2594
|
-
payload, destination, findings = linear_publication_input(args, recording=True)
|
|
2595
|
-
publications = payload["publications"]
|
|
2596
|
-
if not isinstance(publications, list):
|
|
2597
|
-
raise SystemExit("Linear publication results must be an array.")
|
|
2598
|
-
planned = {finding["findingId"]: finding["occurrenceId"] for finding in findings}
|
|
2599
|
-
current: dict[str, dict[str, str]] = {}
|
|
2600
|
-
external_ids: set[str] = set()
|
|
2601
|
-
for publication in publications:
|
|
2602
|
-
if (
|
|
2603
|
-
not isinstance(publication, dict)
|
|
2604
|
-
or not {"findingId", "occurrenceId", "issueIdentifier"}.issubset(publication)
|
|
2605
|
-
or not set(publication).issubset(
|
|
2606
|
-
{"findingId", "occurrenceId", "issueIdentifier", "url"}
|
|
2607
|
-
)
|
|
2608
|
-
or not isinstance(publication.get("findingId"), str)
|
|
2609
|
-
or not isinstance(publication.get("occurrenceId"), str)
|
|
2610
|
-
or not isinstance(publication.get("issueIdentifier"), str)
|
|
2611
|
-
or not publication["issueIdentifier"].strip()
|
|
2612
|
-
or (
|
|
2613
|
-
"url" in publication
|
|
2614
|
-
and (
|
|
2615
|
-
not isinstance(publication["url"], str)
|
|
2616
|
-
or not publication["url"].strip()
|
|
2617
|
-
)
|
|
2618
|
-
)
|
|
2619
|
-
):
|
|
2620
|
-
raise SystemExit("Linear publication results contain an invalid issue association.")
|
|
2621
|
-
finding_id = publication["findingId"]
|
|
2622
|
-
issue_identifier = publication["issueIdentifier"]
|
|
2623
|
-
if planned.get(finding_id) != publication["occurrenceId"]:
|
|
2624
|
-
raise SystemExit(
|
|
2625
|
-
"A created Linear issue does not match its planned finding and occurrence."
|
|
2626
|
-
)
|
|
2627
|
-
if finding_id in current or issue_identifier in external_ids:
|
|
2628
|
-
raise SystemExit("Linear publication results repeat a finding or issue identifier.")
|
|
2629
|
-
current[finding_id] = publication
|
|
2630
|
-
external_ids.add(issue_identifier)
|
|
2631
|
-
|
|
2632
|
-
connection.execute("BEGIN IMMEDIATE")
|
|
2633
|
-
try:
|
|
2634
|
-
scan = verify_linear_publication_scan(connection, payload, findings)
|
|
2635
|
-
timestamp = now()
|
|
2636
|
-
for publication in publications:
|
|
2637
|
-
conflicting = connection.execute(
|
|
2638
|
-
"""
|
|
2639
|
-
SELECT occurrence_id, external_url
|
|
2640
|
-
FROM finding_publications
|
|
2641
|
-
WHERE destination_type = ? AND team_id = ? AND project_id IS ?
|
|
2642
|
-
AND external_id = ?
|
|
2643
|
-
""",
|
|
2644
|
-
(
|
|
2645
|
-
destination["type"],
|
|
2646
|
-
destination["teamId"],
|
|
2647
|
-
destination.get("projectId"),
|
|
2648
|
-
publication["issueIdentifier"],
|
|
2649
|
-
),
|
|
2650
|
-
).fetchone()
|
|
2651
|
-
if conflicting is not None and conflicting["occurrence_id"] != publication[
|
|
2652
|
-
"occurrenceId"
|
|
2653
|
-
]:
|
|
2654
|
-
raise SystemExit("This Linear issue is already associated with a different finding.")
|
|
2655
|
-
if (
|
|
2656
|
-
conflicting is not None
|
|
2657
|
-
and "url" in publication
|
|
2658
|
-
and conflicting["external_url"] != publication["url"]
|
|
2659
|
-
):
|
|
2660
|
-
raise SystemExit("This Linear issue is already associated with a different URL.")
|
|
2661
|
-
|
|
2662
|
-
connection.execute(
|
|
2663
|
-
"""
|
|
2664
|
-
INSERT INTO finding_publications (
|
|
2665
|
-
scan_id, finding_id, occurrence_id, destination_type,
|
|
2666
|
-
team_id, project_id, external_id, external_url, created_at
|
|
2667
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
2668
|
-
ON CONFLICT DO NOTHING
|
|
2669
|
-
""",
|
|
2670
|
-
(
|
|
2671
|
-
scan["id"],
|
|
2672
|
-
publication["findingId"],
|
|
2673
|
-
publication["occurrenceId"],
|
|
2674
|
-
destination["type"],
|
|
2675
|
-
destination["teamId"],
|
|
2676
|
-
destination.get("projectId"),
|
|
2677
|
-
publication["issueIdentifier"],
|
|
2678
|
-
publication.get("url"),
|
|
2679
|
-
timestamp,
|
|
2680
|
-
),
|
|
2681
|
-
)
|
|
2682
|
-
|
|
2683
|
-
created = []
|
|
2684
|
-
for finding in findings:
|
|
2685
|
-
publication = current.get(finding["findingId"])
|
|
2686
|
-
if publication is None:
|
|
2687
|
-
continue
|
|
2688
|
-
row = connection.execute(
|
|
2689
|
-
"""
|
|
2690
|
-
SELECT finding_id, occurrence_id, external_id, external_url
|
|
2691
|
-
FROM finding_publications
|
|
2692
|
-
WHERE scan_id = ? AND occurrence_id = ? AND destination_type = ?
|
|
2693
|
-
AND team_id = ? AND project_id IS ? AND external_id = ?
|
|
2694
|
-
""",
|
|
2695
|
-
(
|
|
2696
|
-
scan["id"],
|
|
2697
|
-
publication["occurrenceId"],
|
|
2698
|
-
destination["type"],
|
|
2699
|
-
destination["teamId"],
|
|
2700
|
-
destination.get("projectId"),
|
|
2701
|
-
publication["issueIdentifier"],
|
|
2702
|
-
),
|
|
2703
|
-
).fetchone()
|
|
2704
|
-
if row is None:
|
|
2705
|
-
raise SystemExit("A created Linear issue could not be read from scan history.")
|
|
2706
|
-
created.append(
|
|
2707
|
-
{
|
|
2708
|
-
"findingId": row["finding_id"],
|
|
2709
|
-
"occurrenceId": row["occurrence_id"],
|
|
2710
|
-
"issueIdentifier": row["external_id"],
|
|
2711
|
-
**({"url": row["external_url"]} if row["external_url"] is not None else {}),
|
|
2712
|
-
}
|
|
2713
|
-
)
|
|
2714
|
-
result = {"scanId": scan["id"], "destination": destination, "created": created}
|
|
2715
|
-
connection.commit()
|
|
2716
|
-
except BaseException:
|
|
2717
|
-
connection.rollback()
|
|
2718
|
-
raise
|
|
2719
|
-
return result
|
|
2437
|
+
return publication.inspect_linear_publication(_WORKBENCH_PUBLICATION_CONTEXT, args)
|
|
2720
2438
|
|
|
2721
2439
|
|
|
2722
2440
|
def export_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
2723
|
-
|
|
2724
|
-
scan = require_scan(connection, args.scan_id)
|
|
2725
|
-
if scan["status"] != "complete" and not (
|
|
2726
|
-
scan["status"] == "failed" and scan["seal_manifest_digest"]
|
|
2727
|
-
):
|
|
2728
|
-
raise SystemExit(
|
|
2729
|
-
"Findings can be exported after the scan completes or preserves stopped results."
|
|
2730
|
-
)
|
|
2731
|
-
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
2732
|
-
require_recorded_manifest_digest(scan, scan_dir)
|
|
2733
|
-
verify_manifest_binding(scan, read_json_object(scan_dir / ARTIFACTS["manifest"]))
|
|
2734
|
-
try:
|
|
2735
|
-
manifest, _, _ = finalize_scan(
|
|
2736
|
-
scan_dir,
|
|
2737
|
-
expected_coverage_mode=expected_coverage_mode(scan),
|
|
2738
|
-
)
|
|
2739
|
-
except ContractError as exc:
|
|
2740
|
-
raise SystemExit(str(exc)) from exc
|
|
2741
|
-
verify_manifest_binding(scan, manifest)
|
|
2742
|
-
manifest_digest = published_manifest_digest(scan_dir, manifest)
|
|
2743
|
-
pin_legacy_manifest_digest(connection, scan["id"], manifest_digest)
|
|
2744
|
-
if args.format == "json":
|
|
2745
|
-
path = artifact_path(scan_dir, ARTIFACTS["findings"], required=True)
|
|
2746
|
-
elif args.format == "sarif":
|
|
2747
|
-
try:
|
|
2748
|
-
write_sarif_projection(scan_dir)
|
|
2749
|
-
except ContractError as exc:
|
|
2750
|
-
raise SystemExit(str(exc)) from exc
|
|
2751
|
-
path = artifact_path(scan_dir, "exports/results.sarif", required=True)
|
|
2752
|
-
else:
|
|
2753
|
-
path = write_csv_export(connection, scan)
|
|
2754
|
-
if path is None:
|
|
2755
|
-
raise SystemExit(f"Could not export Codex Security findings as {args.format.upper()}.")
|
|
2756
|
-
return {
|
|
2757
|
-
"export": {"format": args.format, "path": str(path)},
|
|
2758
|
-
"scan": scan_result(connection, scan),
|
|
2759
|
-
"workspace": workspace_state(connection, scan["workspace_id"]),
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
def write_csv_export(connection: sqlite3.Connection, scan: sqlite3.Row) -> Path:
|
|
2764
|
-
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
2765
|
-
output = io.StringIO(newline="")
|
|
2766
|
-
writer = csv.writer(output)
|
|
2767
|
-
deep_scan = scan["mode"] == "deep"
|
|
2768
|
-
candidate_ids_by_occurrence: dict[str, str] = {}
|
|
2769
|
-
if deep_scan:
|
|
2770
|
-
findings_document = read_json_object(scan_dir / ARTIFACTS["findings"])
|
|
2771
|
-
findings = findings_document.get("findings")
|
|
2772
|
-
if not isinstance(findings, list):
|
|
2773
|
-
raise SystemExit("findings.json must contain a findings array.")
|
|
2774
|
-
for finding in findings:
|
|
2775
|
-
if not isinstance(finding, dict):
|
|
2776
|
-
raise SystemExit("findings.json entries must be objects.")
|
|
2777
|
-
occurrence_id = finding.get("occurrenceId")
|
|
2778
|
-
candidate_id = finding_candidate_id(finding)
|
|
2779
|
-
if isinstance(occurrence_id, str) and isinstance(candidate_id, str):
|
|
2780
|
-
candidate_ids_by_occurrence[occurrence_id] = candidate_id
|
|
2781
|
-
columns = (
|
|
2782
|
-
"occurrence_id",
|
|
2783
|
-
"finding_id",
|
|
2784
|
-
*(("candidate_id",) if deep_scan else ()),
|
|
2785
|
-
"title",
|
|
2786
|
-
"summary",
|
|
2787
|
-
"severity",
|
|
2788
|
-
"confidence",
|
|
2789
|
-
"status",
|
|
2790
|
-
"close_reason",
|
|
2791
|
-
"note",
|
|
2792
|
-
"remediation",
|
|
2793
|
-
"path",
|
|
2794
|
-
"start_line",
|
|
2795
|
-
"end_line",
|
|
2796
|
-
)
|
|
2797
|
-
writer.writerow(columns)
|
|
2798
|
-
for row in finding_export_rows(connection, scan["id"]):
|
|
2799
|
-
writer.writerow(
|
|
2800
|
-
(
|
|
2801
|
-
csv_cell(row["occurrence_id"]),
|
|
2802
|
-
csv_cell(row["finding_id"]),
|
|
2803
|
-
*(
|
|
2804
|
-
(csv_cell(candidate_ids_by_occurrence.get(row["occurrence_id"])),)
|
|
2805
|
-
if deep_scan
|
|
2806
|
-
else ()
|
|
2807
|
-
),
|
|
2808
|
-
csv_cell(row["title"]),
|
|
2809
|
-
csv_cell(row["summary"]),
|
|
2810
|
-
csv_cell(row["severity"]),
|
|
2811
|
-
csv_cell(row["confidence"]),
|
|
2812
|
-
csv_cell(row["status"]),
|
|
2813
|
-
csv_cell(row["close_reason"]),
|
|
2814
|
-
csv_cell(row["note"]),
|
|
2815
|
-
csv_cell(row["remediation"]),
|
|
2816
|
-
csv_cell(row["relative_path"]),
|
|
2817
|
-
row["start_line"],
|
|
2818
|
-
row["end_line"],
|
|
2819
|
-
)
|
|
2820
|
-
)
|
|
2821
|
-
try:
|
|
2822
|
-
write_scan_local_bytes(
|
|
2823
|
-
scan_dir,
|
|
2824
|
-
"exports/findings.csv",
|
|
2825
|
-
output.getvalue().encode("utf-8"),
|
|
2826
|
-
)
|
|
2827
|
-
except ContractError as exc:
|
|
2828
|
-
raise SystemExit(
|
|
2829
|
-
"exports: expected a regular directory inside the scan directory."
|
|
2830
|
-
) from exc
|
|
2831
|
-
destination = scan_dir / "exports" / "findings.csv"
|
|
2832
|
-
path = available_artifact_path(scan_dir, destination)
|
|
2833
|
-
if path is None:
|
|
2834
|
-
raise SystemExit("findings.csv: expected a regular file inside the scan directory.")
|
|
2835
|
-
return path
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
def finding_export_rows(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Cursor:
|
|
2839
|
-
return connection.execute(
|
|
2840
|
-
"""
|
|
2841
|
-
SELECT
|
|
2842
|
-
occurrences.id AS occurrence_id,
|
|
2843
|
-
occurrences.finding_id,
|
|
2844
|
-
occurrences.title,
|
|
2845
|
-
occurrences.summary,
|
|
2846
|
-
occurrences.severity,
|
|
2847
|
-
occurrences.confidence,
|
|
2848
|
-
occurrences.remediation,
|
|
2849
|
-
COALESCE(triage.status, 'open') AS status,
|
|
2850
|
-
triage.close_reason,
|
|
2851
|
-
triage.note,
|
|
2852
|
-
locations.relative_path,
|
|
2853
|
-
locations.start_line,
|
|
2854
|
-
locations.end_line
|
|
2855
|
-
FROM finding_occurrences AS occurrences
|
|
2856
|
-
LEFT JOIN finding_triage AS triage ON triage.occurrence_id = occurrences.id
|
|
2857
|
-
LEFT JOIN finding_locations AS locations
|
|
2858
|
-
ON locations.occurrence_id = occurrences.id
|
|
2859
|
-
AND locations.sort_order = (
|
|
2860
|
-
SELECT primary_location.sort_order
|
|
2861
|
-
FROM finding_locations AS primary_location
|
|
2862
|
-
WHERE primary_location.occurrence_id = occurrences.id
|
|
2863
|
-
ORDER BY
|
|
2864
|
-
CASE WHEN primary_location.role = 'root_control' THEN 0 ELSE 1 END,
|
|
2865
|
-
primary_location.sort_order
|
|
2866
|
-
LIMIT 1
|
|
2867
|
-
)
|
|
2868
|
-
WHERE occurrences.scan_id = ?
|
|
2869
|
-
ORDER BY occurrences.created_at, occurrences.id
|
|
2870
|
-
""",
|
|
2871
|
-
(scan_id,),
|
|
2872
|
-
)
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
def require_remediation_transition(current: str, requested: str) -> None:
|
|
2876
|
-
allowed = {
|
|
2877
|
-
"requested": {"requested", "generated", "failed"},
|
|
2878
|
-
"generated": {"generated", "applied", "failed"},
|
|
2879
|
-
"applied": {"applied", "verifying", "failed"},
|
|
2880
|
-
"verifying": {"verifying", "verified", "failed"},
|
|
2881
|
-
"verified": {"verifying", "verified"},
|
|
2882
|
-
"failed": {"generated", "applied", "verifying", "verified", "failed"},
|
|
2883
|
-
}
|
|
2884
|
-
if requested not in allowed.get(current, set()):
|
|
2885
|
-
raise SystemExit(f"Finding remediation cannot move from {current} to {requested}.")
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
def require_pending_remediation_action(current: sqlite3.Row, requested: str) -> None:
|
|
2889
|
-
pending_action = current["pending_action"]
|
|
2890
|
-
if pending_action is not None:
|
|
2891
|
-
allowed = {
|
|
2892
|
-
"generate": {"generated", "failed"},
|
|
2893
|
-
"apply": {"applied", "failed"},
|
|
2894
|
-
"verify": {"verifying", "verified", "failed"},
|
|
2895
|
-
}
|
|
2896
|
-
if requested not in allowed[pending_action]:
|
|
2897
|
-
raise SystemExit(
|
|
2898
|
-
f"Pending remediation action {pending_action} cannot record state {requested}."
|
|
2899
|
-
)
|
|
2900
|
-
return
|
|
2901
|
-
required_action = {
|
|
2902
|
-
("requested", "generated"): "generate",
|
|
2903
|
-
("generated", "applied"): "apply",
|
|
2904
|
-
("applied", "verifying"): "verify",
|
|
2905
|
-
}.get((current["state"], requested))
|
|
2906
|
-
if required_action is not None:
|
|
2907
|
-
raise SystemExit(
|
|
2908
|
-
f"Request {required_action} before recording remediation state {requested}."
|
|
2909
|
-
)
|
|
2441
|
+
return publication.export_findings(_WORKBENCH_PUBLICATION_CONTEXT, connection, args)
|
|
2910
2442
|
|
|
2911
2443
|
|
|
2912
2444
|
def require_reviewed_patch_applied(
|
|
@@ -3077,8 +2609,8 @@ def workspace_state(
|
|
|
3077
2609
|
workspace_id: str,
|
|
3078
2610
|
*,
|
|
3079
2611
|
result_scan_id: str | None = None,
|
|
2612
|
+
result_scan: dict[str, Any] | None = None,
|
|
3080
2613
|
thread_id: str | None = None,
|
|
3081
|
-
refresh_stopped: bool = False,
|
|
3082
2614
|
) -> dict[str, Any]:
|
|
3083
2615
|
workspace = require_workspace(connection, workspace_id)
|
|
3084
2616
|
if thread_id is not None and workspace["thread_id"] != optional_text(thread_id, maximum=512):
|
|
@@ -3099,11 +2631,11 @@ def workspace_state(
|
|
|
3099
2631
|
}
|
|
3100
2632
|
selected_scan_id = result_scan_id or workspace["active_scan_id"]
|
|
3101
2633
|
if selected_scan_id:
|
|
3102
|
-
if refresh_stopped:
|
|
3103
|
-
refresh_stopped_scan_results(connection, selected_scan_id)
|
|
3104
2634
|
selected_scan = require_scan(connection, selected_scan_id)
|
|
3105
2635
|
result["userContext"] = selected_scan["user_context"]
|
|
3106
|
-
result["results"] =
|
|
2636
|
+
result["results"] = (
|
|
2637
|
+
result_scan if result_scan is not None else scan_result(connection, selected_scan)
|
|
2638
|
+
)
|
|
3107
2639
|
return result
|
|
3108
2640
|
|
|
3109
2641
|
target_metadata = None
|
|
@@ -3145,14 +2677,17 @@ def scan_context(
|
|
|
3145
2677
|
occurrence_id: str | None = None,
|
|
3146
2678
|
) -> dict[str, Any]:
|
|
3147
2679
|
scan = require_scan(connection, scan_id)
|
|
3148
|
-
|
|
2680
|
+
result = scan_result(connection, scan, occurrence_id=occurrence_id)
|
|
2681
|
+
workspace_result = result if occurrence_id is None else scan_result(connection, scan)
|
|
2682
|
+
workspace = workspace_state(
|
|
2683
|
+
connection,
|
|
2684
|
+
scan["workspace_id"],
|
|
2685
|
+
result_scan_id=scan["id"],
|
|
2686
|
+
result_scan=workspace_result,
|
|
2687
|
+
)
|
|
3149
2688
|
context = {
|
|
3150
2689
|
"otherRunningDeepScans": deep_scan.other_running_deep_scans(connection, scan["id"]),
|
|
3151
|
-
"scan":
|
|
3152
|
-
workspace["results"]
|
|
3153
|
-
if occurrence_id is None
|
|
3154
|
-
else scan_result(connection, scan, occurrence_id=occurrence_id)
|
|
3155
|
-
),
|
|
2690
|
+
"scan": result,
|
|
3156
2691
|
"workspace": workspace,
|
|
3157
2692
|
}
|
|
3158
2693
|
if scan["recipe_json"] is not None:
|
|
@@ -3162,7 +2697,6 @@ def scan_context(
|
|
|
3162
2697
|
|
|
3163
2698
|
|
|
3164
2699
|
def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
3165
|
-
refresh_stopped_scan_results(connection, args.scan_id)
|
|
3166
2700
|
scan = require_scan(connection, args.scan_id)
|
|
3167
2701
|
backfill_legacy_finding_details(connection, scan)
|
|
3168
2702
|
limit = min(args.limit, FINDINGS_PAGE_MAX)
|
|
@@ -3280,6 +2814,7 @@ def scan_result(
|
|
|
3280
2814
|
progress_result["independentReviews"] = {
|
|
3281
2815
|
"active": independent_reviews["active"],
|
|
3282
2816
|
"completed": independent_reviews["completed"],
|
|
2817
|
+
"maximum": independent_reviews["maximum"],
|
|
3283
2818
|
"consolidating": independent_reviews["consolidating"],
|
|
3284
2819
|
}
|
|
3285
2820
|
return {
|
|
@@ -3304,6 +2839,9 @@ def scan_result(
|
|
|
3304
2839
|
"remediationAvailable": remediation_available,
|
|
3305
2840
|
"remediationUnavailableReason": remediation_unavailable_reason,
|
|
3306
2841
|
"reportAvailable": "markdownReport" in artifacts,
|
|
2842
|
+
"resultsRecoveryNeeded": saved_results.scan_results_recovery_needed(
|
|
2843
|
+
_WORKBENCH_DB_CONTEXT, connection, scan
|
|
2844
|
+
),
|
|
3307
2845
|
"scanDir": scan["scan_dir"],
|
|
3308
2846
|
"scanId": scan["id"],
|
|
3309
2847
|
"scope": scan["scope"],
|
|
@@ -3752,13 +3290,10 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
|
3752
3290
|
scan_dir
|
|
3753
3291
|
):
|
|
3754
3292
|
raise SystemExit("Scan directory must be an existing canonical non-symlink directory.")
|
|
3755
|
-
# Re-check privacy
|
|
3756
|
-
# shared parent cannot substitute another user's forged artifact tree.
|
|
3293
|
+
# Re-check privacy so a shared parent cannot be used to substitute forged artifacts.
|
|
3757
3294
|
if os.name != "nt":
|
|
3758
3295
|
if stat.S_IMODE(metadata.st_mode) & 0o077:
|
|
3759
|
-
raise SystemExit(
|
|
3760
|
-
"Scan directory must not be accessible to other users (chmod 700)."
|
|
3761
|
-
)
|
|
3296
|
+
raise SystemExit("Scan directory must not be accessible to other users (chmod 700).")
|
|
3762
3297
|
geteuid = getattr(os, "geteuid", None)
|
|
3763
3298
|
effective_uid = geteuid() if geteuid is not None else None
|
|
3764
3299
|
if effective_uid is not None and metadata.st_uid != effective_uid:
|
|
@@ -3768,9 +3303,7 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
|
3768
3303
|
parent_metadata = parent.lstat()
|
|
3769
3304
|
except OSError as exc:
|
|
3770
3305
|
raise SystemExit("Scan output parent could not be inspected.") from exc
|
|
3771
|
-
if not stat.S_ISDIR(parent_metadata.st_mode) or stat.S_ISLNK(
|
|
3772
|
-
parent_metadata.st_mode
|
|
3773
|
-
):
|
|
3306
|
+
if not stat.S_ISDIR(parent_metadata.st_mode) or stat.S_ISLNK(parent_metadata.st_mode):
|
|
3774
3307
|
raise SystemExit("Scan output parent must be a non-symlink directory.")
|
|
3775
3308
|
if effective_uid is not None and parent_metadata.st_uid not in {
|
|
3776
3309
|
0,
|
|
@@ -3804,6 +3337,25 @@ def reject_non_finite_json(value: str) -> None:
|
|
|
3804
3337
|
raise ValueError(f"non-finite JSON number {value!r} is not supported")
|
|
3805
3338
|
|
|
3806
3339
|
|
|
3340
|
+
_WORKBENCH_PUBLICATION_CONTEXT = publication.WorkbenchPublicationContext(
|
|
3341
|
+
ARTIFACTS=ARTIFACTS,
|
|
3342
|
+
artifact_path=artifact_path,
|
|
3343
|
+
available_artifact_path=available_artifact_path,
|
|
3344
|
+
database_path=database_path,
|
|
3345
|
+
expected_coverage_mode=expected_coverage_mode,
|
|
3346
|
+
now=now,
|
|
3347
|
+
pin_legacy_manifest_digest=pin_legacy_manifest_digest,
|
|
3348
|
+
published_manifest_digest=published_manifest_digest,
|
|
3349
|
+
read_json_object=read_json_object,
|
|
3350
|
+
require_canonical_scan_directory=require_canonical_scan_directory,
|
|
3351
|
+
require_recorded_manifest_digest=require_recorded_manifest_digest,
|
|
3352
|
+
require_scan=require_scan,
|
|
3353
|
+
scan_result=scan_result,
|
|
3354
|
+
verify_manifest_binding=verify_manifest_binding,
|
|
3355
|
+
workspace_state=workspace_state,
|
|
3356
|
+
)
|
|
3357
|
+
|
|
3358
|
+
|
|
3807
3359
|
_WORKBENCH_DB_CONTEXT = saved_results.WorkbenchDbContext(
|
|
3808
3360
|
ARTIFACTS=ARTIFACTS,
|
|
3809
3361
|
artifact_path=artifact_path,
|
|
@@ -3872,7 +3424,6 @@ def main() -> None:
|
|
|
3872
3424
|
connection,
|
|
3873
3425
|
args.workspace_id,
|
|
3874
3426
|
thread_id=args.thread_id,
|
|
3875
|
-
refresh_stopped=True,
|
|
3876
3427
|
)
|
|
3877
3428
|
elif args.command == "save-workspace":
|
|
3878
3429
|
result = save_workspace(connection, args)
|
|
@@ -3901,12 +3452,10 @@ def main() -> None:
|
|
|
3901
3452
|
elif args.command == "record-deep-scan-publication-failure":
|
|
3902
3453
|
result = deep_scan.record_deep_scan_publication_failure(connection, args)
|
|
3903
3454
|
elif args.command == "get-scan":
|
|
3904
|
-
refresh_stopped_scan_results(connection, args.scan_id)
|
|
3905
3455
|
result = scan_context(connection, args.scan_id, args.occurrence_id)
|
|
3906
3456
|
elif args.command == "get-scan-feedback":
|
|
3907
3457
|
result = get_scan_feedback(connection, require_scan(connection, args.scan_id))
|
|
3908
3458
|
elif args.command == "list-scans":
|
|
3909
|
-
refresh_all_stopped_scan_results(connection)
|
|
3910
3459
|
result = scan_history.list_scans(connection, args)
|
|
3911
3460
|
elif args.command == "list-unmatched-scan-pairs":
|
|
3912
3461
|
result = scan_history.list_unmatched_scan_pairs(
|
|
@@ -3940,10 +3489,8 @@ def main() -> None:
|
|
|
3940
3489
|
read_coverage=coverage_for_comparison,
|
|
3941
3490
|
)
|
|
3942
3491
|
elif args.command == "list-global-findings":
|
|
3943
|
-
refresh_all_stopped_scan_results(connection)
|
|
3944
3492
|
result = native_indexes.list_global_findings(connection, args)
|
|
3945
3493
|
elif args.command == "list-repositories":
|
|
3946
|
-
refresh_all_stopped_scan_results(connection)
|
|
3947
3494
|
result = native_indexes.list_repositories(connection, args)
|
|
3948
3495
|
elif args.command == "list-findings":
|
|
3949
3496
|
result = list_findings(connection, args)
|
|
@@ -3963,6 +3510,8 @@ def main() -> None:
|
|
|
3963
3510
|
result = fail_scan(connection, args)
|
|
3964
3511
|
elif args.command == "preserve-scan-results":
|
|
3965
3512
|
result = preserve_scan_results(connection, args)
|
|
3513
|
+
elif args.command == "recover-scan-results":
|
|
3514
|
+
result = recover_scan_results(connection, args)
|
|
3966
3515
|
elif args.command == "write-scan-draft":
|
|
3967
3516
|
result = write_scan_draft(connection, args)
|
|
3968
3517
|
elif args.command == "mark-handoff-delivered":
|
|
@@ -4013,18 +3562,40 @@ def main() -> None:
|
|
|
4013
3562
|
result = release_finding_remediation_claim(connection, args)
|
|
4014
3563
|
elif args.command == "cancel-finding-remediation-request":
|
|
4015
3564
|
result = scan_context(
|
|
4016
|
-
connection,
|
|
3565
|
+
connection,
|
|
3566
|
+
remediation.cancel_finding_remediation_request(connection, args),
|
|
4017
3567
|
)
|
|
4018
3568
|
elif args.command == "set-finding-remediation":
|
|
4019
3569
|
result = set_finding_remediation(connection, args)
|
|
4020
3570
|
elif args.command == "prepare-linear-publication":
|
|
4021
|
-
result = prepare_linear_publication(
|
|
3571
|
+
result = publication.prepare_linear_publication(
|
|
3572
|
+
_WORKBENCH_PUBLICATION_CONTEXT, connection, args
|
|
3573
|
+
)
|
|
4022
3574
|
elif args.command == "record-linear-publications":
|
|
4023
|
-
result = record_linear_publications(
|
|
3575
|
+
result = publication.record_linear_publications(
|
|
3576
|
+
_WORKBENCH_PUBLICATION_CONTEXT, connection, args
|
|
3577
|
+
)
|
|
4024
3578
|
elif args.command == "export-findings":
|
|
4025
3579
|
result = export_findings(connection, args)
|
|
4026
3580
|
elif args.command == "database-info":
|
|
4027
3581
|
result = {"databasePath": str(database_path())}
|
|
3582
|
+
elif args.command == "finding-workflow":
|
|
3583
|
+
result = finding_workflow(connection, json.load(sys.stdin), now())
|
|
3584
|
+
elif args.command == "dashboard":
|
|
3585
|
+
result = dashboard(connection, json.load(sys.stdin))
|
|
3586
|
+
elif args.command == "store-findings":
|
|
3587
|
+
payload = json.load(sys.stdin)
|
|
3588
|
+
result = store_findings(
|
|
3589
|
+
connection, payload["entries"], now(), payload.get("repositoryId")
|
|
3590
|
+
)
|
|
3591
|
+
elif args.command == "find-potential-duplicates":
|
|
3592
|
+
result = find_potential_duplicates(connection, args.finding_id, args.repository_id)
|
|
3593
|
+
elif args.command == "store-dedupe-groups":
|
|
3594
|
+
result = store_dedupe_groups(connection, json.load(sys.stdin)["groups"], now())
|
|
3595
|
+
elif args.command == "list-dedupe-groups":
|
|
3596
|
+
result = list_dedupe_groups(connection, args.finding_id)
|
|
3597
|
+
elif args.command == "list-stored-findings":
|
|
3598
|
+
result = list_stored_findings(connection, limit=args.limit, offset=args.offset)
|
|
4028
3599
|
else:
|
|
4029
3600
|
raise SystemExit(f"Unknown command: {args.command}")
|
|
4030
3601
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|