@openai/codex-security 0.1.17 → 0.1.18
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 +44 -14
- 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/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +4 -2
- package/_bundled_plugin/references/scan-artifacts.md +1 -1
- package/_bundled_plugin/references/scan-contract.md +18 -7
- package/_bundled_plugin/schemas/scan-manifest.schema.json +2 -2
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +23 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +88 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +58 -18
- package/_bundled_plugin/scripts/report_projection.py +19 -8
- package/_bundled_plugin/scripts/workbench_cli.py +13 -0
- package/_bundled_plugin/scripts/workbench_db.py +149 -167
- package/_bundled_plugin/scripts/workbench_finding_index.py +101 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +19 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +1289 -0
- package/_bundled_plugin/scripts/workbench_schema.py +28 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +4 -4
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +1 -1
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +54 -7
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +13 -0
- package/dist/cli.js.map +1 -1
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/models.d.ts +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/package.json +2 -2
|
@@ -37,6 +37,7 @@ import deep_scan_workbench as deep_scan
|
|
|
37
37
|
import workbench_native_indexes as native_indexes
|
|
38
38
|
import workbench_progress as progress
|
|
39
39
|
import workbench_remediation as remediation
|
|
40
|
+
import workbench_saved_results as saved_results
|
|
40
41
|
import workbench_scan_history as scan_history
|
|
41
42
|
import workbench_scan_usage as scan_usage
|
|
42
43
|
from filesystem_identity import serialize_filesystem_identity as serialize_filesystem_identity
|
|
@@ -46,6 +47,7 @@ from filesystem_identity import (
|
|
|
46
47
|
from finalize_scan_contract import (
|
|
47
48
|
PRODUCER_NAME,
|
|
48
49
|
ContractError,
|
|
50
|
+
RecoverableContractError,
|
|
49
51
|
_prepare_scan_finalization,
|
|
50
52
|
_write_prepared_scan_finalization,
|
|
51
53
|
csv_cell,
|
|
@@ -78,6 +80,7 @@ from workbench_constants import (
|
|
|
78
80
|
SQLITE_RETRY_ATTEMPTS,
|
|
79
81
|
)
|
|
80
82
|
from workbench_feedback import get_scan_feedback
|
|
83
|
+
from workbench_finding_index import index_findings
|
|
81
84
|
from workbench_remediation import remediation_claim_is_active
|
|
82
85
|
from workbench_scan_start import (
|
|
83
86
|
archive_scan,
|
|
@@ -1467,6 +1470,24 @@ def complete_scan_locked(
|
|
|
1467
1470
|
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
1468
1471
|
completion_timestamp = now()
|
|
1469
1472
|
completion_binding = workbench_completion_binding(scan, completion_timestamp)
|
|
1473
|
+
current_manifest_path = artifact_path(scan_dir, ARTIFACTS["manifest"], required=False)
|
|
1474
|
+
if current_manifest_path is not None:
|
|
1475
|
+
current_manifest = read_json_object(current_manifest_path)
|
|
1476
|
+
if (
|
|
1477
|
+
isinstance(current_manifest.get("scan"), dict)
|
|
1478
|
+
and current_manifest["scan"].get("complete") is False
|
|
1479
|
+
):
|
|
1480
|
+
raise SystemExit(
|
|
1481
|
+
"The latest saved scan draft is incomplete; continue the scan before completing it."
|
|
1482
|
+
)
|
|
1483
|
+
already_sealed = (
|
|
1484
|
+
current_manifest_path is not None
|
|
1485
|
+
and isinstance(current_manifest.get("scan"), dict)
|
|
1486
|
+
and (
|
|
1487
|
+
current_manifest["scan"].get("sealedAt") is not None
|
|
1488
|
+
or current_manifest["scan"].get("artifacts") is not None
|
|
1489
|
+
)
|
|
1490
|
+
)
|
|
1470
1491
|
if scan["recipe_json"] is not None:
|
|
1471
1492
|
draft_artifacts: dict[str, Path] = {}
|
|
1472
1493
|
missing_drafts = []
|
|
@@ -1494,16 +1515,38 @@ def complete_scan_locked(
|
|
|
1494
1515
|
if isinstance(manifest_scan, dict) and manifest_scan.get("sealedAt") is not None:
|
|
1495
1516
|
completion_binding["startedAt"] = manifest_scan.get("startedAt")
|
|
1496
1517
|
completion_binding["completedAt"] = manifest_scan.get("completedAt")
|
|
1518
|
+
wrote = False
|
|
1497
1519
|
try:
|
|
1498
1520
|
prepared = _prepare_scan_finalization(
|
|
1499
1521
|
scan_dir,
|
|
1500
1522
|
expected_coverage_mode=expected_coverage_mode(scan),
|
|
1501
1523
|
completion_binding=completion_binding,
|
|
1502
1524
|
completion_warnings=warnings,
|
|
1525
|
+
draft_documents=saved_results.merge_saved_results(
|
|
1526
|
+
scan_dir,
|
|
1527
|
+
scan["id"],
|
|
1528
|
+
completion_binding,
|
|
1529
|
+
connection.execute(
|
|
1530
|
+
"SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",
|
|
1531
|
+
(scan["id"],),
|
|
1532
|
+
).fetchall(),
|
|
1533
|
+
warnings,
|
|
1534
|
+
stopped=False,
|
|
1535
|
+
reason="",
|
|
1536
|
+
)
|
|
1537
|
+
if current_manifest_path is not None and not already_sealed
|
|
1538
|
+
else None,
|
|
1503
1539
|
)
|
|
1504
1540
|
add_warning()
|
|
1541
|
+
wrote = True
|
|
1505
1542
|
manifest, findings, _ = _write_prepared_scan_finalization(prepared)
|
|
1506
1543
|
except ContractError as exc:
|
|
1544
|
+
if wrote or (
|
|
1545
|
+
scan["mode"] == "deep" and not isinstance(exc, RecoverableContractError)
|
|
1546
|
+
):
|
|
1547
|
+
args = argparse.Namespace(claim_token=claim_token, cost_json=cost_json)
|
|
1548
|
+
args.message, args.scan_id = str(exc), scan_id
|
|
1549
|
+
fail_scan_locked(connection, args)
|
|
1507
1550
|
raise SystemExit(str(exc)) from exc
|
|
1508
1551
|
artifacts = {
|
|
1509
1552
|
kind: artifact_path(scan_dir, filename, required=True)
|
|
@@ -1793,101 +1836,63 @@ def get_scan_recipe(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
1793
1836
|
}
|
|
1794
1837
|
|
|
1795
1838
|
|
|
1839
|
+
_WORKBENCH_DB_CONTEXT: saved_results.WorkbenchDbContext
|
|
1840
|
+
|
|
1841
|
+
|
|
1796
1842
|
def coverage_for_comparison(scan: sqlite3.Row) -> dict[str, Any]:
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1843
|
+
return saved_results.coverage_for_comparison(_WORKBENCH_DB_CONTEXT, scan)
|
|
1844
|
+
|
|
1845
|
+
|
|
1846
|
+
def preserve_scan_results_locked(connection: sqlite3.Connection, scan_id: str) -> bool:
|
|
1847
|
+
return saved_results.preserve_scan_results_locked(_WORKBENCH_DB_CONTEXT, connection, scan_id)
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
def refresh_stopped_scan_results(
|
|
1851
|
+
connection: sqlite3.Connection, scan_id: str, *, strict: bool = False
|
|
1852
|
+
) -> None:
|
|
1853
|
+
saved_results.refresh_stopped_scan_results(
|
|
1854
|
+
_WORKBENCH_DB_CONTEXT, connection, scan_id, strict=strict
|
|
1855
|
+
)
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
def refresh_all_stopped_scan_results(connection: sqlite3.Connection) -> None:
|
|
1859
|
+
scan_ids = [
|
|
1860
|
+
row["id"] for row in connection.execute("SELECT id FROM scans WHERE status = 'failed'")
|
|
1861
|
+
]
|
|
1862
|
+
for scan_id in scan_ids:
|
|
1863
|
+
refresh_stopped_scan_results(connection, scan_id)
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
def preserve_scan_results(
|
|
1867
|
+
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1868
|
+
) -> dict[str, Any]:
|
|
1869
|
+
return saved_results.preserve_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
def write_scan_draft(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1873
|
+
return saved_results.write_scan_draft(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1808
1874
|
|
|
1809
1875
|
|
|
1810
1876
|
def fail_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
scan = require_scan(connection, scan_id)
|
|
1817
|
-
if scan["status"] == "failed":
|
|
1818
|
-
connection.commit()
|
|
1819
|
-
return scan_context(connection, scan["id"])
|
|
1820
|
-
if scan["status"] == "complete":
|
|
1821
|
-
raise SystemExit("A completed scan cannot be marked failed.")
|
|
1822
|
-
handoff.require_current_continuation(
|
|
1823
|
-
scan,
|
|
1824
|
-
args.claim_token,
|
|
1825
|
-
error_message="Scan failure is owned by another continuation.",
|
|
1826
|
-
)
|
|
1827
|
-
message = optional_text(args.message, maximum=2400)
|
|
1828
|
-
updated = connection.execute(
|
|
1829
|
-
"""
|
|
1830
|
-
UPDATE scans
|
|
1831
|
-
SET status = 'failed', failure_message = ?, completed_at = ?, updated_at = ?,
|
|
1832
|
-
cost_json = ?
|
|
1833
|
-
WHERE id = ? AND status = 'running'
|
|
1834
|
-
""",
|
|
1835
|
-
(message, timestamp, timestamp, cost_json, scan["id"]),
|
|
1836
|
-
)
|
|
1837
|
-
if updated.rowcount != 1:
|
|
1838
|
-
raise SystemExit("Only a running scan can be marked failed.")
|
|
1839
|
-
deep_scan.fail_from_parent_scan(connection, scan["id"], message, timestamp)
|
|
1840
|
-
progress_updated = connection.execute(
|
|
1841
|
-
"UPDATE scan_progress SET updated_at = ? WHERE scan_id = ?",
|
|
1842
|
-
(timestamp, scan["id"]),
|
|
1843
|
-
)
|
|
1844
|
-
if progress_updated.rowcount != 1:
|
|
1845
|
-
raise SystemExit("Codex Security scan progress not found.")
|
|
1846
|
-
connection.commit()
|
|
1847
|
-
except BaseException:
|
|
1848
|
-
connection.rollback()
|
|
1849
|
-
raise
|
|
1850
|
-
return scan_context(connection, scan["id"])
|
|
1877
|
+
return saved_results.fail_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
def fail_scan_locked(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1881
|
+
return saved_results.fail_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1851
1882
|
|
|
1852
1883
|
|
|
1853
1884
|
def cancel_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
connection.commit()
|
|
1866
|
-
return workspace_state(connection, scan["workspace_id"])
|
|
1867
|
-
if scan["status"] != "running":
|
|
1868
|
-
raise SystemExit("Only a running scan can be canceled.")
|
|
1869
|
-
updated = connection.execute(
|
|
1870
|
-
"""
|
|
1871
|
-
UPDATE scans
|
|
1872
|
-
SET status = 'failed', canceled_at = ?, completed_at = ?, updated_at = ?
|
|
1873
|
-
WHERE id = ? AND status = 'running'
|
|
1874
|
-
""",
|
|
1875
|
-
(timestamp, timestamp, timestamp, scan["id"]),
|
|
1876
|
-
)
|
|
1877
|
-
if updated.rowcount != 1:
|
|
1878
|
-
raise SystemExit("Only a running scan can be canceled.")
|
|
1879
|
-
deep_scan.cancel_from_parent_scan(connection, scan["id"], timestamp)
|
|
1880
|
-
progress_updated = connection.execute(
|
|
1881
|
-
"UPDATE scan_progress SET updated_at = ? WHERE scan_id = ?",
|
|
1882
|
-
(timestamp, scan["id"]),
|
|
1883
|
-
)
|
|
1884
|
-
if progress_updated.rowcount != 1:
|
|
1885
|
-
raise SystemExit("Codex Security scan progress not found.")
|
|
1886
|
-
connection.commit()
|
|
1887
|
-
except BaseException:
|
|
1888
|
-
connection.rollback()
|
|
1889
|
-
raise
|
|
1890
|
-
return workspace_state(connection, scan["workspace_id"])
|
|
1885
|
+
return saved_results.cancel_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1886
|
+
|
|
1887
|
+
|
|
1888
|
+
def cancel_scan_locked(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1889
|
+
return saved_results.cancel_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
def preserve_stopped_results_after_transition(connection: sqlite3.Connection, scan_id: str) -> None:
|
|
1893
|
+
saved_results.preserve_stopped_results_after_transition(
|
|
1894
|
+
_WORKBENCH_DB_CONTEXT, connection, scan_id
|
|
1895
|
+
)
|
|
1891
1896
|
|
|
1892
1897
|
|
|
1893
1898
|
def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
@@ -2666,9 +2671,14 @@ def record_linear_publications(
|
|
|
2666
2671
|
|
|
2667
2672
|
|
|
2668
2673
|
def export_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
2674
|
+
refresh_stopped_scan_results(connection, args.scan_id, strict=True)
|
|
2669
2675
|
scan = require_scan(connection, args.scan_id)
|
|
2670
|
-
if scan["status"] != "complete"
|
|
2671
|
-
|
|
2676
|
+
if scan["status"] != "complete" and not (
|
|
2677
|
+
scan["status"] == "failed" and scan["seal_manifest_digest"]
|
|
2678
|
+
):
|
|
2679
|
+
raise SystemExit(
|
|
2680
|
+
"Findings can be exported after the scan completes or preserves stopped results."
|
|
2681
|
+
)
|
|
2672
2682
|
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
2673
2683
|
require_recorded_manifest_digest(scan, scan_dir)
|
|
2674
2684
|
verify_manifest_binding(scan, read_json_object(scan_dir / ARTIFACTS["manifest"]))
|
|
@@ -3004,82 +3014,6 @@ def open_scan_local_file(scan_dir: Path, relative_path: str) -> Any:
|
|
|
3004
3014
|
raise SystemExit("Patch path must identify a scan-local regular file.") from exc
|
|
3005
3015
|
|
|
3006
3016
|
|
|
3007
|
-
def index_findings(
|
|
3008
|
-
connection: sqlite3.Connection,
|
|
3009
|
-
scan_id: str,
|
|
3010
|
-
document: dict[str, Any],
|
|
3011
|
-
timestamp: str,
|
|
3012
|
-
) -> None:
|
|
3013
|
-
findings = document.get("findings")
|
|
3014
|
-
if not isinstance(findings, list):
|
|
3015
|
-
raise SystemExit("findings.json must contain a findings array.")
|
|
3016
|
-
for finding in findings:
|
|
3017
|
-
if not isinstance(finding, dict):
|
|
3018
|
-
raise SystemExit("findings.json entries must be objects.")
|
|
3019
|
-
identity = finding["identity"]
|
|
3020
|
-
fingerprints = finding["fingerprints"]
|
|
3021
|
-
severity = finding["severity"]
|
|
3022
|
-
confidence = finding["confidence"]
|
|
3023
|
-
connection.execute(
|
|
3024
|
-
"""
|
|
3025
|
-
INSERT INTO findings (
|
|
3026
|
-
id, fingerprint, rule_id, identity_anchor, identity_instance, created_at, updated_at
|
|
3027
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
3028
|
-
ON CONFLICT(id) DO UPDATE SET
|
|
3029
|
-
fingerprint = excluded.fingerprint,
|
|
3030
|
-
rule_id = excluded.rule_id,
|
|
3031
|
-
identity_anchor = excluded.identity_anchor,
|
|
3032
|
-
identity_instance = excluded.identity_instance,
|
|
3033
|
-
updated_at = excluded.updated_at
|
|
3034
|
-
""",
|
|
3035
|
-
(
|
|
3036
|
-
finding["findingId"],
|
|
3037
|
-
fingerprints["primary"],
|
|
3038
|
-
finding["ruleId"],
|
|
3039
|
-
identity["anchor"],
|
|
3040
|
-
identity.get("instance"),
|
|
3041
|
-
timestamp,
|
|
3042
|
-
timestamp,
|
|
3043
|
-
),
|
|
3044
|
-
)
|
|
3045
|
-
connection.execute(
|
|
3046
|
-
"""
|
|
3047
|
-
INSERT INTO finding_occurrences (
|
|
3048
|
-
id, finding_id, scan_id, title, summary, severity, confidence, remediation,
|
|
3049
|
-
details_json, created_at
|
|
3050
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
3051
|
-
""",
|
|
3052
|
-
(
|
|
3053
|
-
finding["occurrenceId"],
|
|
3054
|
-
finding["findingId"],
|
|
3055
|
-
scan_id,
|
|
3056
|
-
finding["title"],
|
|
3057
|
-
finding["summary"],
|
|
3058
|
-
severity["level"],
|
|
3059
|
-
confidence["level"],
|
|
3060
|
-
finding["remediation"],
|
|
3061
|
-
json.dumps(finding, allow_nan=False, sort_keys=True),
|
|
3062
|
-
timestamp,
|
|
3063
|
-
),
|
|
3064
|
-
)
|
|
3065
|
-
for index, location in enumerate(finding["locations"]):
|
|
3066
|
-
connection.execute(
|
|
3067
|
-
"""
|
|
3068
|
-
INSERT INTO finding_locations (
|
|
3069
|
-
occurrence_id, relative_path, start_line, end_line, role, sort_order
|
|
3070
|
-
) VALUES (?, ?, ?, ?, ?, ?)
|
|
3071
|
-
""",
|
|
3072
|
-
(
|
|
3073
|
-
finding["occurrenceId"],
|
|
3074
|
-
location["path"],
|
|
3075
|
-
location["startLine"],
|
|
3076
|
-
location.get("endLine", location["startLine"]),
|
|
3077
|
-
location.get("role"),
|
|
3078
|
-
index,
|
|
3079
|
-
),
|
|
3080
|
-
)
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
3017
|
def diff_target_summary(diff_target: dict[str, str]) -> str:
|
|
3084
3018
|
kind = diff_target["kind"]
|
|
3085
3019
|
if kind == "working_tree":
|
|
@@ -3095,6 +3029,7 @@ def workspace_state(
|
|
|
3095
3029
|
*,
|
|
3096
3030
|
result_scan_id: str | None = None,
|
|
3097
3031
|
thread_id: str | None = None,
|
|
3032
|
+
refresh_stopped: bool = False,
|
|
3098
3033
|
) -> dict[str, Any]:
|
|
3099
3034
|
workspace = require_workspace(connection, workspace_id)
|
|
3100
3035
|
if thread_id is not None and workspace["thread_id"] != optional_text(thread_id, maximum=512):
|
|
@@ -3115,6 +3050,8 @@ def workspace_state(
|
|
|
3115
3050
|
}
|
|
3116
3051
|
selected_scan_id = result_scan_id or workspace["active_scan_id"]
|
|
3117
3052
|
if selected_scan_id:
|
|
3053
|
+
if refresh_stopped:
|
|
3054
|
+
refresh_stopped_scan_results(connection, selected_scan_id)
|
|
3118
3055
|
selected_scan = require_scan(connection, selected_scan_id)
|
|
3119
3056
|
result["userContext"] = selected_scan["user_context"]
|
|
3120
3057
|
result["results"] = scan_result(connection, selected_scan)
|
|
@@ -3176,6 +3113,7 @@ def scan_context(
|
|
|
3176
3113
|
|
|
3177
3114
|
|
|
3178
3115
|
def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
3116
|
+
refresh_stopped_scan_results(connection, args.scan_id)
|
|
3179
3117
|
scan = require_scan(connection, args.scan_id)
|
|
3180
3118
|
backfill_legacy_finding_details(connection, scan)
|
|
3181
3119
|
limit = min(args.limit, FINDINGS_PAGE_MAX)
|
|
@@ -3335,6 +3273,8 @@ def scan_result(
|
|
|
3335
3273
|
|
|
3336
3274
|
|
|
3337
3275
|
def remediation_availability(scan: sqlite3.Row) -> tuple[bool, str | None]:
|
|
3276
|
+
if scan["status"] != "complete":
|
|
3277
|
+
return False, remediation.SCAN_STATUS_ERROR
|
|
3338
3278
|
try:
|
|
3339
3279
|
current_revision = git_revision(require_scan_target_identity(scan))
|
|
3340
3280
|
except SystemExit as exc:
|
|
@@ -3815,6 +3755,31 @@ def reject_non_finite_json(value: str) -> None:
|
|
|
3815
3755
|
raise ValueError(f"non-finite JSON number {value!r} is not supported")
|
|
3816
3756
|
|
|
3817
3757
|
|
|
3758
|
+
_WORKBENCH_DB_CONTEXT = saved_results.WorkbenchDbContext(
|
|
3759
|
+
ARTIFACTS=ARTIFACTS,
|
|
3760
|
+
artifact_path=artifact_path,
|
|
3761
|
+
deep_scan=deep_scan,
|
|
3762
|
+
expected_coverage_mode=expected_coverage_mode,
|
|
3763
|
+
handoff=handoff,
|
|
3764
|
+
index_findings=index_findings,
|
|
3765
|
+
now=now,
|
|
3766
|
+
optional_text=optional_text,
|
|
3767
|
+
parse_scan_cost=parse_scan_cost,
|
|
3768
|
+
published_manifest_digest=published_manifest_digest,
|
|
3769
|
+
read_json_object=read_json_object,
|
|
3770
|
+
require_canonical_scan_directory=require_canonical_scan_directory,
|
|
3771
|
+
require_recorded_manifest_digest=require_recorded_manifest_digest,
|
|
3772
|
+
require_scan=require_scan,
|
|
3773
|
+
require_uuid=require_uuid,
|
|
3774
|
+
require_workspace=require_workspace,
|
|
3775
|
+
scan_completion_lock=scan_completion_lock,
|
|
3776
|
+
scan_context=scan_context,
|
|
3777
|
+
verify_manifest_binding=verify_manifest_binding,
|
|
3778
|
+
workbench_completion_binding=workbench_completion_binding,
|
|
3779
|
+
workspace_state=workspace_state,
|
|
3780
|
+
)
|
|
3781
|
+
|
|
3782
|
+
|
|
3818
3783
|
def main() -> None:
|
|
3819
3784
|
# Workbench callers send UTF-8 even when Windows uses a legacy code page.
|
|
3820
3785
|
sys.stdin.reconfigure(encoding="utf-8")
|
|
@@ -3834,6 +3799,7 @@ def main() -> None:
|
|
|
3834
3799
|
safe_segment=safe_segment,
|
|
3835
3800
|
compact_timestamp=compact_timestamp,
|
|
3836
3801
|
scan_completion_lock=scan_completion_lock,
|
|
3802
|
+
preserve_stopped_results=preserve_stopped_results_after_transition,
|
|
3837
3803
|
)
|
|
3838
3804
|
)
|
|
3839
3805
|
if args.command == "inspect-target":
|
|
@@ -3845,10 +3811,16 @@ def main() -> None:
|
|
|
3845
3811
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3846
3812
|
return
|
|
3847
3813
|
with closing(connect()) as connection:
|
|
3814
|
+
remediation.require_available(connection, args, require_scan)
|
|
3848
3815
|
if args.command == "create-workspace":
|
|
3849
3816
|
result = create_workspace(connection, args)
|
|
3850
3817
|
elif args.command == "get-workspace":
|
|
3851
|
-
result = workspace_state(
|
|
3818
|
+
result = workspace_state(
|
|
3819
|
+
connection,
|
|
3820
|
+
args.workspace_id,
|
|
3821
|
+
thread_id=args.thread_id,
|
|
3822
|
+
refresh_stopped=True,
|
|
3823
|
+
)
|
|
3852
3824
|
elif args.command == "save-workspace":
|
|
3853
3825
|
result = save_workspace(connection, args)
|
|
3854
3826
|
elif args.command == "start-scan":
|
|
@@ -3873,11 +3845,15 @@ def main() -> None:
|
|
|
3873
3845
|
result = deep_scan.finish_deep_scan(connection, args)
|
|
3874
3846
|
elif args.command == "fail-deep-scan":
|
|
3875
3847
|
result = deep_scan.fail_deep_scan(connection, args)
|
|
3848
|
+
elif args.command == "record-deep-scan-publication-failure":
|
|
3849
|
+
result = deep_scan.record_deep_scan_publication_failure(connection, args)
|
|
3876
3850
|
elif args.command == "get-scan":
|
|
3851
|
+
refresh_stopped_scan_results(connection, args.scan_id)
|
|
3877
3852
|
result = scan_context(connection, args.scan_id, args.occurrence_id)
|
|
3878
3853
|
elif args.command == "get-scan-feedback":
|
|
3879
3854
|
result = get_scan_feedback(connection, require_scan(connection, args.scan_id))
|
|
3880
3855
|
elif args.command == "list-scans":
|
|
3856
|
+
refresh_all_stopped_scan_results(connection)
|
|
3881
3857
|
result = scan_history.list_scans(connection, args)
|
|
3882
3858
|
elif args.command == "list-unmatched-scan-pairs":
|
|
3883
3859
|
result = scan_history.list_unmatched_scan_pairs(
|
|
@@ -3911,8 +3887,10 @@ def main() -> None:
|
|
|
3911
3887
|
read_coverage=coverage_for_comparison,
|
|
3912
3888
|
)
|
|
3913
3889
|
elif args.command == "list-global-findings":
|
|
3890
|
+
refresh_all_stopped_scan_results(connection)
|
|
3914
3891
|
result = native_indexes.list_global_findings(connection, args)
|
|
3915
3892
|
elif args.command == "list-repositories":
|
|
3893
|
+
refresh_all_stopped_scan_results(connection)
|
|
3916
3894
|
result = native_indexes.list_repositories(connection, args)
|
|
3917
3895
|
elif args.command == "list-findings":
|
|
3918
3896
|
result = list_findings(connection, args)
|
|
@@ -3930,6 +3908,10 @@ def main() -> None:
|
|
|
3930
3908
|
result = cancel_scan(connection, args)
|
|
3931
3909
|
elif args.command == "fail-scan":
|
|
3932
3910
|
result = fail_scan(connection, args)
|
|
3911
|
+
elif args.command == "preserve-scan-results":
|
|
3912
|
+
result = preserve_scan_results(connection, args)
|
|
3913
|
+
elif args.command == "write-scan-draft":
|
|
3914
|
+
result = write_scan_draft(connection, args)
|
|
3933
3915
|
elif args.command == "mark-handoff-delivered":
|
|
3934
3916
|
result = handoff.mark_handoff_delivered(
|
|
3935
3917
|
connection,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Persist normalized scan findings and their occurrences."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sqlite3
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def index_findings(
|
|
12
|
+
connection: sqlite3.Connection,
|
|
13
|
+
scan_id: str,
|
|
14
|
+
document: dict[str, Any],
|
|
15
|
+
timestamp: str,
|
|
16
|
+
) -> None:
|
|
17
|
+
findings = document.get("findings")
|
|
18
|
+
if not isinstance(findings, list):
|
|
19
|
+
raise SystemExit("findings.json must contain a findings array.")
|
|
20
|
+
for finding in findings:
|
|
21
|
+
if not isinstance(finding, dict):
|
|
22
|
+
raise SystemExit("findings.json entries must be objects.")
|
|
23
|
+
identity = finding["identity"]
|
|
24
|
+
fingerprints = finding["fingerprints"]
|
|
25
|
+
severity = finding["severity"]
|
|
26
|
+
confidence = finding["confidence"]
|
|
27
|
+
connection.execute(
|
|
28
|
+
"""
|
|
29
|
+
INSERT INTO findings (
|
|
30
|
+
id, fingerprint, rule_id, identity_anchor, identity_instance, created_at, updated_at
|
|
31
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
32
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
33
|
+
fingerprint = excluded.fingerprint,
|
|
34
|
+
rule_id = excluded.rule_id,
|
|
35
|
+
identity_anchor = excluded.identity_anchor,
|
|
36
|
+
identity_instance = excluded.identity_instance,
|
|
37
|
+
updated_at = excluded.updated_at
|
|
38
|
+
""",
|
|
39
|
+
(
|
|
40
|
+
finding["findingId"],
|
|
41
|
+
fingerprints["primary"],
|
|
42
|
+
finding["ruleId"],
|
|
43
|
+
identity["anchor"],
|
|
44
|
+
identity.get("instance"),
|
|
45
|
+
timestamp,
|
|
46
|
+
timestamp,
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
connection.execute(
|
|
50
|
+
"""
|
|
51
|
+
INSERT INTO finding_occurrences (
|
|
52
|
+
id, finding_id, scan_id, title, summary, severity, confidence, remediation,
|
|
53
|
+
details_json, created_at
|
|
54
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
55
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
56
|
+
finding_id = excluded.finding_id,
|
|
57
|
+
scan_id = excluded.scan_id,
|
|
58
|
+
title = excluded.title,
|
|
59
|
+
summary = excluded.summary,
|
|
60
|
+
severity = excluded.severity,
|
|
61
|
+
confidence = excluded.confidence,
|
|
62
|
+
remediation = excluded.remediation,
|
|
63
|
+
details_json = excluded.details_json
|
|
64
|
+
""",
|
|
65
|
+
(
|
|
66
|
+
finding["occurrenceId"],
|
|
67
|
+
finding["findingId"],
|
|
68
|
+
scan_id,
|
|
69
|
+
finding["title"],
|
|
70
|
+
finding["summary"],
|
|
71
|
+
severity["level"],
|
|
72
|
+
confidence["level"],
|
|
73
|
+
finding["remediation"],
|
|
74
|
+
json.dumps(finding, allow_nan=False, sort_keys=True),
|
|
75
|
+
timestamp,
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
connection.execute(
|
|
79
|
+
"DELETE FROM finding_locations WHERE occurrence_id = ?",
|
|
80
|
+
(finding["occurrenceId"],),
|
|
81
|
+
)
|
|
82
|
+
for index, location in enumerate(finding["locations"]):
|
|
83
|
+
connection.execute(
|
|
84
|
+
"""
|
|
85
|
+
INSERT INTO finding_locations (
|
|
86
|
+
occurrence_id, relative_path, start_line, end_line, role, sort_order
|
|
87
|
+
) VALUES (?, ?, ?, ?, ?, ?)
|
|
88
|
+
""",
|
|
89
|
+
(
|
|
90
|
+
finding["occurrenceId"],
|
|
91
|
+
location["path"],
|
|
92
|
+
location["startLine"],
|
|
93
|
+
location.get("endLine", location["startLine"]),
|
|
94
|
+
location.get("role"),
|
|
95
|
+
index,
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
@@ -14,6 +14,25 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
14
14
|
from workbench_constants import CLAIM_LEASE_SECONDS, DELIVERED_ACTION_LEASE_SECONDS
|
|
15
15
|
from workbench_validation import require_occurrence, require_uuid
|
|
16
16
|
|
|
17
|
+
COMMANDS = {
|
|
18
|
+
"request-finding-remediation",
|
|
19
|
+
"request-finding-remediation-action",
|
|
20
|
+
"claim-finding-remediation-resend",
|
|
21
|
+
"mark-finding-remediation-delivered",
|
|
22
|
+
"release-finding-remediation-claim",
|
|
23
|
+
"cancel-finding-remediation-request",
|
|
24
|
+
"set-finding-remediation",
|
|
25
|
+
}
|
|
26
|
+
SCAN_STATUS_ERROR = "Remediation is available only for successfully completed scans."
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def require_available(connection: sqlite3.Connection, args: Any, require_scan: Any) -> None:
|
|
30
|
+
if args.command not in COMMANDS:
|
|
31
|
+
return
|
|
32
|
+
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
33
|
+
if require_scan(connection, occurrence["scan_id"])["status"] != "complete":
|
|
34
|
+
raise SystemExit(SCAN_STATUS_ERROR)
|
|
35
|
+
|
|
17
36
|
|
|
18
37
|
def remediation_claim_is_active(remediation: sqlite3.Row) -> bool:
|
|
19
38
|
if remediation["pending_action_claim_token"] is None:
|