@openai/codex-security 0.1.31 → 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 +295 -32
- 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/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 +85 -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 +8 -3
- 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 +19 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +631 -714
- 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 +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +2 -2
- 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.map +1 -1
- package/dist/owner-evidence.js +2 -6
- package/dist/owner-evidence.js.map +1 -1
- 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 +203 -131
- 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 +3 -3
- 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 +2 -3
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +4 -5
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +24 -21
- package/dist/targets.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 +11 -10
- 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
|
@@ -16,9 +16,10 @@ import sys
|
|
|
16
16
|
import tempfile
|
|
17
17
|
import time
|
|
18
18
|
import uuid
|
|
19
|
-
from contextlib import closing, contextmanager
|
|
19
|
+
from contextlib import closing, contextmanager, nullcontext
|
|
20
20
|
from datetime import datetime, timedelta, timezone
|
|
21
21
|
from pathlib import Path, PurePosixPath
|
|
22
|
+
from types import SimpleNamespace
|
|
22
23
|
from typing import Any
|
|
23
24
|
|
|
24
25
|
try:
|
|
@@ -60,7 +61,7 @@ from finalize_scan_contract import (
|
|
|
60
61
|
)
|
|
61
62
|
from finding_preview import bounded_finding_details
|
|
62
63
|
from workbench import handoff
|
|
63
|
-
from workbench.storage import resolve_scan_root, state_dir
|
|
64
|
+
from workbench.storage import create_private_directory, resolve_scan_root, state_dir
|
|
64
65
|
from workbench_cli import parse_args
|
|
65
66
|
from workbench_constants import (
|
|
66
67
|
ARTIFACTS,
|
|
@@ -95,13 +96,15 @@ from workbench_findings import (
|
|
|
95
96
|
from workbench_remediation import remediation_claim_is_active
|
|
96
97
|
from workbench_scan_start import (
|
|
97
98
|
archive_scan,
|
|
98
|
-
compact_timestamp,
|
|
99
99
|
insert_running_scan,
|
|
100
100
|
safe_segment,
|
|
101
101
|
scan_diff_identity,
|
|
102
102
|
scan_target_identity,
|
|
103
103
|
stored_diff_target,
|
|
104
104
|
)
|
|
105
|
+
from workbench_scan_start import (
|
|
106
|
+
compact_timestamp as compact_timestamp,
|
|
107
|
+
)
|
|
105
108
|
from workbench_schema import (
|
|
106
109
|
MIGRATIONS,
|
|
107
110
|
)
|
|
@@ -116,13 +119,14 @@ from workbench_target import (
|
|
|
116
119
|
clean_worktree_content_digest,
|
|
117
120
|
copy_directory_excluding,
|
|
118
121
|
copy_git_worktree_files,
|
|
122
|
+
diff_snapshot_digest,
|
|
119
123
|
directory_content_digest,
|
|
120
124
|
directory_snapshot_regular_file_count,
|
|
121
125
|
git_bytes,
|
|
122
126
|
git_command,
|
|
123
127
|
git_output,
|
|
124
128
|
git_revision,
|
|
125
|
-
|
|
129
|
+
git_submodule_entries,
|
|
126
130
|
git_target_metadata,
|
|
127
131
|
git_worktree_context,
|
|
128
132
|
remediation_checkout_snapshot,
|
|
@@ -169,7 +173,7 @@ def database_path() -> Path:
|
|
|
169
173
|
@contextmanager
|
|
170
174
|
def scan_completion_lock(scan_id: str) -> Any:
|
|
171
175
|
lock_dir = state_dir() / "completion-locks"
|
|
172
|
-
lock_dir
|
|
176
|
+
create_private_directory(lock_dir)
|
|
173
177
|
lock_path = lock_dir / f"{require_uuid(scan_id, 'scan-id')}.lock"
|
|
174
178
|
descriptor = os.open(
|
|
175
179
|
lock_path,
|
|
@@ -230,16 +234,17 @@ def release_completion_file_lock(descriptor: int) -> None:
|
|
|
230
234
|
windows_file_lock.locking(descriptor, windows_file_lock.LK_UNLCK, 1)
|
|
231
235
|
|
|
232
236
|
|
|
233
|
-
def connect() -> sqlite3.Connection:
|
|
237
|
+
def connect(*, deferred: bool = False) -> sqlite3.Connection:
|
|
234
238
|
path = database_path()
|
|
235
|
-
path.parent
|
|
239
|
+
create_private_directory(path.parent)
|
|
236
240
|
for attempt in range(SQLITE_RETRY_ATTEMPTS):
|
|
237
241
|
connection = sqlite3.connect(path, timeout=5)
|
|
238
242
|
try:
|
|
239
243
|
connection.row_factory = sqlite3.Row
|
|
240
244
|
connection.execute("PRAGMA foreign_keys = ON")
|
|
241
245
|
connection.execute("PRAGMA busy_timeout = 5000")
|
|
242
|
-
|
|
246
|
+
# Keep writer admission retries; readers only wait when a repair needs to write.
|
|
247
|
+
apply_migrations(connection, immediate=not deferred or attempt > 0)
|
|
243
248
|
connection.execute("PRAGMA journal_mode = WAL")
|
|
244
249
|
path.chmod(0o600)
|
|
245
250
|
return connection
|
|
@@ -251,8 +256,10 @@ def connect() -> sqlite3.Connection:
|
|
|
251
256
|
raise AssertionError("SQLite retry loop exhausted unexpectedly.")
|
|
252
257
|
|
|
253
258
|
|
|
254
|
-
def apply_migrations(connection: sqlite3.Connection) -> None:
|
|
255
|
-
apply_schema_migrations(
|
|
259
|
+
def apply_migrations(connection: sqlite3.Connection, *, immediate: bool = False) -> None:
|
|
260
|
+
apply_schema_migrations(
|
|
261
|
+
connection, MIGRATIONS, now, backfill_security_targets, immediate=immediate
|
|
262
|
+
)
|
|
256
263
|
|
|
257
264
|
|
|
258
265
|
def require_target(value: str) -> Path:
|
|
@@ -395,18 +402,6 @@ def inspect_setup_values(
|
|
|
395
402
|
}
|
|
396
403
|
|
|
397
404
|
|
|
398
|
-
def inspect_setup(args: argparse.Namespace) -> dict[str, Any]:
|
|
399
|
-
return inspect_setup_values(
|
|
400
|
-
args.target_path,
|
|
401
|
-
args.scope,
|
|
402
|
-
args.mode,
|
|
403
|
-
args.diff_target_kind,
|
|
404
|
-
args.diff_base_revision,
|
|
405
|
-
args.diff_head_revision,
|
|
406
|
-
args.diff_content_digest,
|
|
407
|
-
)
|
|
408
|
-
|
|
409
|
-
|
|
410
405
|
def require_review_changes_target(target: Path) -> str:
|
|
411
406
|
revision = require_git_worktree_head(target)
|
|
412
407
|
repository_root = git_output(target, "rev-parse", "--show-toplevel")
|
|
@@ -514,8 +509,8 @@ def workbench_completion_binding(
|
|
|
514
509
|
if scan["mode"] == "diff":
|
|
515
510
|
target["baseRevision"] = scan["diff_base_revision"]
|
|
516
511
|
target["headRevision"] = scan["diff_head_revision"]
|
|
517
|
-
if
|
|
518
|
-
target["snapshotDigest"] =
|
|
512
|
+
if snapshot_digest := diff_snapshot_digest(scan, manifest):
|
|
513
|
+
target["snapshotDigest"] = snapshot_digest
|
|
519
514
|
else:
|
|
520
515
|
if scan["target_revision"] != "unversioned":
|
|
521
516
|
target["revision"] = scan["target_revision"]
|
|
@@ -855,7 +850,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
855
850
|
metadata=target_metadata,
|
|
856
851
|
)
|
|
857
852
|
target_root = scan_target_root(args.scan_root, target)
|
|
858
|
-
target_root
|
|
853
|
+
create_private_directory(target_root)
|
|
859
854
|
if manages_transaction:
|
|
860
855
|
connection.execute("BEGIN IMMEDIATE")
|
|
861
856
|
workspace = require_workspace(connection, workspace_id)
|
|
@@ -918,18 +913,6 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
918
913
|
return workspace_state(connection, workspace["id"])
|
|
919
914
|
|
|
920
915
|
|
|
921
|
-
def start_prompt_only_scan(
|
|
922
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
923
|
-
) -> dict[str, Any]:
|
|
924
|
-
return _start_prompt_driven_scan(connection, args, headless_standard=False)
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
def start_headless_standard_scan(
|
|
928
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
929
|
-
) -> dict[str, Any]:
|
|
930
|
-
return _start_prompt_driven_scan(connection, args, headless_standard=True)
|
|
931
|
-
|
|
932
|
-
|
|
933
916
|
def _start_prompt_driven_scan(
|
|
934
917
|
connection: sqlite3.Connection, args: argparse.Namespace, *, headless_standard: bool
|
|
935
918
|
) -> dict[str, Any]:
|
|
@@ -1023,7 +1006,7 @@ def _start_prompt_driven_scan(
|
|
|
1023
1006
|
**scan_context(connection, existing["id"]),
|
|
1024
1007
|
"startDisposition": "joined",
|
|
1025
1008
|
}
|
|
1026
|
-
target_root
|
|
1009
|
+
create_private_directory(target_root)
|
|
1027
1010
|
workspace_id = str(uuid.uuid4())
|
|
1028
1011
|
scan_id = str(uuid.uuid4())
|
|
1029
1012
|
timestamp = now()
|
|
@@ -1116,7 +1099,7 @@ def pin_legacy_manifest_digest(
|
|
|
1116
1099
|
connection: sqlite3.Connection, scan_id: str, manifest_digest: str
|
|
1117
1100
|
) -> None:
|
|
1118
1101
|
connection.execute("BEGIN IMMEDIATE")
|
|
1119
|
-
|
|
1102
|
+
with connection:
|
|
1120
1103
|
scan = require_scan(connection, scan_id)
|
|
1121
1104
|
current = scan["seal_manifest_digest"]
|
|
1122
1105
|
if current is not None and current != manifest_digest:
|
|
@@ -1126,10 +1109,6 @@ def pin_legacy_manifest_digest(
|
|
|
1126
1109
|
"UPDATE scans SET seal_manifest_digest = ? WHERE id = ?",
|
|
1127
1110
|
(manifest_digest, scan["id"]),
|
|
1128
1111
|
)
|
|
1129
|
-
connection.commit()
|
|
1130
|
-
except BaseException:
|
|
1131
|
-
connection.rollback()
|
|
1132
|
-
raise
|
|
1133
1112
|
|
|
1134
1113
|
|
|
1135
1114
|
def complete_scan(
|
|
@@ -1444,22 +1423,9 @@ def complete_scan_locked(
|
|
|
1444
1423
|
) -> dict[str, Any]:
|
|
1445
1424
|
scan = require_scan(connection, scan_id)
|
|
1446
1425
|
if scan["status"] == "complete":
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
try:
|
|
1451
|
-
manifest, _, _ = finalize_scan(
|
|
1452
|
-
scan_dir,
|
|
1453
|
-
expected_coverage_mode=expected_coverage_mode(scan),
|
|
1454
|
-
)
|
|
1455
|
-
except ContractError as exc:
|
|
1456
|
-
raise SystemExit(str(exc)) from exc
|
|
1457
|
-
verify_manifest_binding(scan, manifest)
|
|
1458
|
-
manifest_digest = published_manifest_digest(scan_dir, manifest)
|
|
1459
|
-
pin_legacy_manifest_digest(connection, scan["id"], manifest_digest)
|
|
1460
|
-
if cost_json is not None and scan["recipe_json"] is not None:
|
|
1461
|
-
scan_usage.reconcile_completed_scan_cost(connection, scan, cost_json)
|
|
1462
|
-
return scan_context(connection, scan["id"])
|
|
1426
|
+
return saved_results.refresh_completed_scan(
|
|
1427
|
+
_WORKBENCH_DB_CONTEXT, connection, scan, cost_json
|
|
1428
|
+
)
|
|
1463
1429
|
if scan["status"] != "running":
|
|
1464
1430
|
raise SystemExit("Only a running scan can be completed.")
|
|
1465
1431
|
handoff.require_current_continuation(
|
|
@@ -1484,13 +1450,6 @@ def complete_scan_locked(
|
|
|
1484
1450
|
current_manifest = None
|
|
1485
1451
|
if current_manifest_path is not None:
|
|
1486
1452
|
current_manifest = read_json_object(current_manifest_path)
|
|
1487
|
-
if (
|
|
1488
|
-
isinstance(current_manifest.get("scan"), dict)
|
|
1489
|
-
and current_manifest["scan"].get("complete") is False
|
|
1490
|
-
):
|
|
1491
|
-
raise SystemExit(
|
|
1492
|
-
"The latest saved scan draft is incomplete; continue the scan before completing it."
|
|
1493
|
-
)
|
|
1494
1453
|
already_sealed = (
|
|
1495
1454
|
current_manifest_path is not None
|
|
1496
1455
|
and isinstance(current_manifest.get("scan"), dict)
|
|
@@ -1519,33 +1478,53 @@ def complete_scan_locked(
|
|
|
1519
1478
|
f"{', '.join(missing_drafts)}. Check that the scan agent can run shell "
|
|
1520
1479
|
"commands and write to the scan directory before retrying."
|
|
1521
1480
|
)
|
|
1481
|
+
merge_parent_draft = (
|
|
1482
|
+
scan["mode"] != "deep" and current_manifest_path is not None and not already_sealed
|
|
1483
|
+
)
|
|
1522
1484
|
wrote = False
|
|
1523
1485
|
try:
|
|
1524
|
-
|
|
1525
|
-
scan_dir
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1486
|
+
with (
|
|
1487
|
+
saved_results.preserve_parent_head_on_error(scan_dir)
|
|
1488
|
+
if merge_parent_draft
|
|
1489
|
+
else nullcontext()
|
|
1490
|
+
):
|
|
1491
|
+
draft_documents = (
|
|
1492
|
+
saved_results.merge_saved_results(
|
|
1493
|
+
scan_dir,
|
|
1494
|
+
scan["id"],
|
|
1495
|
+
completion_binding,
|
|
1496
|
+
connection.execute(
|
|
1497
|
+
"SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",
|
|
1498
|
+
(scan["id"],),
|
|
1499
|
+
).fetchall(),
|
|
1500
|
+
warnings,
|
|
1501
|
+
stopped=False,
|
|
1502
|
+
reason="",
|
|
1503
|
+
)
|
|
1504
|
+
if merge_parent_draft
|
|
1505
|
+
else None
|
|
1506
|
+
)
|
|
1507
|
+
completion_manifest = draft_documents[0] if draft_documents else current_manifest
|
|
1508
|
+
if (
|
|
1509
|
+
completion_manifest is not None
|
|
1510
|
+
and isinstance(completion_manifest.get("scan"), dict)
|
|
1511
|
+
and completion_manifest["scan"].get("complete") is False
|
|
1512
|
+
):
|
|
1513
|
+
raise RecoverableContractError(
|
|
1514
|
+
"The latest saved scan draft is incomplete; continue the scan before completing it."
|
|
1515
|
+
)
|
|
1516
|
+
prepared = _prepare_scan_finalization(
|
|
1532
1517
|
scan_dir,
|
|
1533
|
-
scan
|
|
1534
|
-
completion_binding,
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
(scan["id"],),
|
|
1538
|
-
).fetchall(),
|
|
1539
|
-
warnings,
|
|
1540
|
-
stopped=False,
|
|
1541
|
-
reason="",
|
|
1518
|
+
expected_coverage_mode=expected_coverage_mode(scan),
|
|
1519
|
+
completion_binding=completion_binding,
|
|
1520
|
+
completion_warnings=warnings if scan["mode"] != "deep" else None,
|
|
1521
|
+
draft_documents=draft_documents,
|
|
1542
1522
|
)
|
|
1543
|
-
if scan["mode"] != "deep" and current_manifest_path is not None and not already_sealed
|
|
1544
|
-
else None,
|
|
1545
|
-
)
|
|
1546
1523
|
add_warning()
|
|
1547
1524
|
wrote = True
|
|
1548
|
-
manifest, findings, _ = _write_prepared_scan_finalization(
|
|
1525
|
+
manifest, findings, _ = _write_prepared_scan_finalization(
|
|
1526
|
+
prepared, projection_warnings=warnings
|
|
1527
|
+
)
|
|
1549
1528
|
except ContractError as exc:
|
|
1550
1529
|
if wrote or (
|
|
1551
1530
|
scan["mode"] == "deep"
|
|
@@ -1554,7 +1533,7 @@ def complete_scan_locked(
|
|
|
1554
1533
|
):
|
|
1555
1534
|
args = argparse.Namespace(claim_token=claim_token, cost_json=cost_json)
|
|
1556
1535
|
args.message, args.scan_id = str(exc), scan_id
|
|
1557
|
-
fail_scan_locked(connection, args)
|
|
1536
|
+
saved_results.fail_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1558
1537
|
raise SystemExit(str(exc)) from exc
|
|
1559
1538
|
artifacts = {
|
|
1560
1539
|
kind: artifact_path(scan_dir, filename, required=True)
|
|
@@ -1563,17 +1542,13 @@ def complete_scan_locked(
|
|
|
1563
1542
|
manifest_digest = published_manifest_digest(scan_dir, manifest)
|
|
1564
1543
|
if prepare_only:
|
|
1565
1544
|
connection.execute("BEGIN IMMEDIATE")
|
|
1566
|
-
|
|
1545
|
+
with connection:
|
|
1567
1546
|
updated = connection.execute(
|
|
1568
1547
|
"UPDATE scans SET completion_warnings_json = ? WHERE id = ? AND status = 'running'",
|
|
1569
1548
|
(json.dumps(warnings), scan["id"]),
|
|
1570
1549
|
)
|
|
1571
1550
|
if updated.rowcount != 1:
|
|
1572
1551
|
raise SystemExit("Only a running scan can be prepared for completion.")
|
|
1573
|
-
connection.commit()
|
|
1574
|
-
except BaseException:
|
|
1575
|
-
connection.rollback()
|
|
1576
|
-
raise
|
|
1577
1552
|
context = scan_context(connection, scan["id"])
|
|
1578
1553
|
context["targetWarnings"] = target_warnings
|
|
1579
1554
|
return context
|
|
@@ -1706,7 +1681,7 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1706
1681
|
workspace_id = str(uuid.uuid4())
|
|
1707
1682
|
|
|
1708
1683
|
connection.execute("BEGIN IMMEDIATE")
|
|
1709
|
-
|
|
1684
|
+
with connection:
|
|
1710
1685
|
archive_scan(connection, args, scan_dir, timestamp, require_canonical_scan_directory)
|
|
1711
1686
|
target_id = ensure_security_target(connection, str(repository))
|
|
1712
1687
|
if parent_scan_id is not None:
|
|
@@ -1761,10 +1736,6 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1761
1736
|
)
|
|
1762
1737
|
if workflow_id is not None:
|
|
1763
1738
|
register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
|
|
1764
|
-
connection.commit()
|
|
1765
|
-
except BaseException:
|
|
1766
|
-
connection.rollback()
|
|
1767
|
-
raise
|
|
1768
1739
|
scan = require_scan(connection, scan_id)
|
|
1769
1740
|
return {
|
|
1770
1741
|
"contract": scan_contract(scan),
|
|
@@ -1860,9 +1831,6 @@ def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
|
|
|
1860
1831
|
return recipe
|
|
1861
1832
|
|
|
1862
1833
|
|
|
1863
|
-
_WORKBENCH_DB_CONTEXT: saved_results.WorkbenchDbContext
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
1834
|
def coverage_for_comparison(scan: sqlite3.Row) -> dict[str, Any]:
|
|
1867
1835
|
return saved_results.coverage_for_comparison(_WORKBENCH_DB_CONTEXT, scan)
|
|
1868
1836
|
|
|
@@ -1877,28 +1845,10 @@ def recover_scan_results(
|
|
|
1877
1845
|
return saved_results.recover_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1878
1846
|
|
|
1879
1847
|
|
|
1880
|
-
def preserve_scan_results(
|
|
1881
|
-
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1882
|
-
) -> dict[str, Any]:
|
|
1883
|
-
return saved_results.preserve_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
def write_scan_draft(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1887
|
-
return saved_results.write_scan_draft(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
1848
|
def fail_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1891
1849
|
return saved_results.fail_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1892
1850
|
|
|
1893
1851
|
|
|
1894
|
-
def fail_scan_locked(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1895
|
-
return saved_results.fail_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
def cancel_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1899
|
-
return saved_results.cancel_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
1852
|
def cancel_scan_locked(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1903
1853
|
return saved_results.cancel_scan_locked(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
1904
1854
|
|
|
@@ -1918,7 +1868,7 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1918
1868
|
note = optional_text(args.note, maximum=2400)
|
|
1919
1869
|
require_close_note(close_reason, note)
|
|
1920
1870
|
connection.execute("BEGIN IMMEDIATE")
|
|
1921
|
-
|
|
1871
|
+
with connection:
|
|
1922
1872
|
timestamp = now()
|
|
1923
1873
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
1924
1874
|
if args.status == "closed":
|
|
@@ -1990,10 +1940,6 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1990
1940
|
""",
|
|
1991
1941
|
(occurrence["id"], args.status, close_reason, note, timestamp),
|
|
1992
1942
|
)
|
|
1993
|
-
connection.commit()
|
|
1994
|
-
except BaseException:
|
|
1995
|
-
connection.rollback()
|
|
1996
|
-
raise
|
|
1997
1943
|
return scan_context(connection, occurrence["scan_id"])
|
|
1998
1944
|
|
|
1999
1945
|
|
|
@@ -2317,7 +2263,7 @@ def set_finding_remediation(
|
|
|
2317
2263
|
action_token = require_uuid(args.action_token, "action-token")
|
|
2318
2264
|
summary = optional_text(args.summary, maximum=2400)
|
|
2319
2265
|
verification_summary = optional_text(args.verification_summary, maximum=2400)
|
|
2320
|
-
|
|
2266
|
+
with connection:
|
|
2321
2267
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
2322
2268
|
require_finding_open(connection, occurrence["id"])
|
|
2323
2269
|
scan = require_scan(connection, occurrence["scan_id"])
|
|
@@ -2432,20 +2378,9 @@ def set_finding_remediation(
|
|
|
2432
2378
|
raise SystemExit(
|
|
2433
2379
|
"This remediation request changed. Refresh it before recording an update."
|
|
2434
2380
|
)
|
|
2435
|
-
connection.commit()
|
|
2436
|
-
except BaseException:
|
|
2437
|
-
connection.rollback()
|
|
2438
|
-
raise
|
|
2439
2381
|
return scan_context(connection, occurrence["scan_id"])
|
|
2440
2382
|
|
|
2441
2383
|
|
|
2442
|
-
_WORKBENCH_PUBLICATION_CONTEXT: publication.WorkbenchPublicationContext
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
def inspect_linear_publication(args: argparse.Namespace) -> dict[str, Any]:
|
|
2446
|
-
return publication.inspect_linear_publication(_WORKBENCH_PUBLICATION_CONTEXT, args)
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
2384
|
def export_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
2450
2385
|
return publication.export_findings(_WORKBENCH_PUBLICATION_CONTEXT, connection, args)
|
|
2451
2386
|
|
|
@@ -2470,7 +2405,7 @@ def require_reviewed_patch_applied(
|
|
|
2470
2405
|
git_dir = git_output(target, "rev-parse", "--absolute-git-dir")
|
|
2471
2406
|
if git_dir is None:
|
|
2472
2407
|
raise SystemExit("Could not inspect the selected Git working tree.")
|
|
2473
|
-
excluded +=
|
|
2408
|
+
excluded += tuple(path for path, _ in git_submodule_entries(target))
|
|
2474
2409
|
with tempfile.TemporaryDirectory(prefix="codex-security-remediation-") as temporary:
|
|
2475
2410
|
reviewed_patch = Path(temporary) / "reviewed.patch"
|
|
2476
2411
|
digest = hashlib.sha256()
|
|
@@ -2772,6 +2707,9 @@ def scan_result(
|
|
|
2772
2707
|
)
|
|
2773
2708
|
if sarif_path is not None:
|
|
2774
2709
|
artifacts["sarifReport"] = str(sarif_path)
|
|
2710
|
+
model_fields = saved_results.threat_model_fields(_WORKBENCH_DB_CONTEXT, scan)
|
|
2711
|
+
if path := model_fields.get("threatModelPath"):
|
|
2712
|
+
artifacts["threatModel"] = path
|
|
2775
2713
|
occurrence_rows = scan_history.finding_occurrence_rows(
|
|
2776
2714
|
connection, scan["id"], offset=0, limit=FINDINGS_RESULT_LIMIT
|
|
2777
2715
|
)
|
|
@@ -2835,6 +2773,7 @@ def scan_result(
|
|
|
2835
2773
|
)
|
|
2836
2774
|
return {
|
|
2837
2775
|
"artifacts": artifacts,
|
|
2776
|
+
**model_fields,
|
|
2838
2777
|
"canceledAt": scan["canceled_at"],
|
|
2839
2778
|
**scan_usage.stored_scan_cost_fields(scan["cost_json"]),
|
|
2840
2779
|
"contract": scan_contract(scan),
|
|
@@ -2926,14 +2865,7 @@ def backfill_legacy_finding_details(connection: sqlite3.Connection, scan: sqlite
|
|
|
2926
2865
|
except (ContractError, OSError, SystemExit, ValueError):
|
|
2927
2866
|
return
|
|
2928
2867
|
|
|
2929
|
-
|
|
2930
|
-
if not isinstance(findings, list):
|
|
2931
|
-
return
|
|
2932
|
-
by_occurrence = {
|
|
2933
|
-
finding.get("occurrenceId"): finding
|
|
2934
|
-
for finding in findings
|
|
2935
|
-
if isinstance(finding, dict) and isinstance(finding.get("occurrenceId"), str)
|
|
2936
|
-
}
|
|
2868
|
+
by_occurrence = {finding["occurrenceId"]: finding for finding in findings_document["findings"]}
|
|
2937
2869
|
updates = []
|
|
2938
2870
|
for row in legacy_rows:
|
|
2939
2871
|
finding = by_occurrence.get(row["id"])
|
|
@@ -2949,8 +2881,16 @@ def backfill_legacy_finding_details(connection: sqlite3.Connection, scan: sqlite
|
|
|
2949
2881
|
if not updates:
|
|
2950
2882
|
return
|
|
2951
2883
|
|
|
2952
|
-
|
|
2953
|
-
|
|
2884
|
+
# Reads normally avoid writer admission, but legacy details still need a write.
|
|
2885
|
+
for attempt in range(SQLITE_RETRY_ATTEMPTS):
|
|
2886
|
+
try:
|
|
2887
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
2888
|
+
break
|
|
2889
|
+
except sqlite3.OperationalError as exc:
|
|
2890
|
+
if attempt == SQLITE_RETRY_ATTEMPTS - 1 or not sqlite_busy(exc):
|
|
2891
|
+
raise
|
|
2892
|
+
time.sleep(0.05 * (2**attempt))
|
|
2893
|
+
with connection:
|
|
2954
2894
|
current = require_scan(connection, scan["id"])
|
|
2955
2895
|
recorded_digest = current["seal_manifest_digest"]
|
|
2956
2896
|
if recorded_digest is not None and recorded_digest != manifest_digest:
|
|
@@ -2968,26 +2908,18 @@ def backfill_legacy_finding_details(connection: sqlite3.Connection, scan: sqlite
|
|
|
2968
2908
|
"UPDATE scans SET seal_manifest_digest = ? WHERE id = ?",
|
|
2969
2909
|
(manifest_digest, scan["id"]),
|
|
2970
2910
|
)
|
|
2971
|
-
connection.commit()
|
|
2972
|
-
except BaseException:
|
|
2973
|
-
connection.rollback()
|
|
2974
|
-
raise
|
|
2975
2911
|
|
|
2976
2912
|
|
|
2977
2913
|
def legacy_finding_matches(row: sqlite3.Row, finding: Any) -> bool:
|
|
2978
2914
|
if not isinstance(finding, dict):
|
|
2979
2915
|
return False
|
|
2980
|
-
severity = finding.get("severity")
|
|
2981
|
-
confidence = finding.get("confidence")
|
|
2982
2916
|
return (
|
|
2983
2917
|
finding.get("findingId") == row["finding_id"]
|
|
2984
2918
|
and finding.get("title") == row["title"]
|
|
2985
2919
|
and finding.get("summary") == row["summary"]
|
|
2986
2920
|
and finding.get("remediation") == row["remediation"]
|
|
2987
|
-
and
|
|
2988
|
-
and
|
|
2989
|
-
and isinstance(confidence, dict)
|
|
2990
|
-
and confidence.get("level") == row["confidence"]
|
|
2921
|
+
and finding["severity"]["level"] == row["severity"]
|
|
2922
|
+
and finding["confidence"]["level"] == row["confidence"]
|
|
2991
2923
|
)
|
|
2992
2924
|
|
|
2993
2925
|
|
|
@@ -3063,7 +2995,6 @@ def finding_result(
|
|
|
3063
2995
|
result["knownScanIds"] = known_scan_ids
|
|
3064
2996
|
if related:
|
|
3065
2997
|
result["related"] = related
|
|
3066
|
-
result.pop("artifactPaths", None)
|
|
3067
2998
|
source_excerpt = finding_source_excerpt(scan, target, locations)
|
|
3068
2999
|
if source_excerpt:
|
|
3069
3000
|
result["sourceExcerpt"] = source_excerpt
|
|
@@ -3095,13 +3026,10 @@ def finding_artifact_paths(scan_dir: Path, details: dict[str, Any]) -> list[str]
|
|
|
3095
3026
|
except OSError:
|
|
3096
3027
|
return artifacts
|
|
3097
3028
|
|
|
3098
|
-
directories_seen
|
|
3099
|
-
|
|
3100
|
-
poc_root, topdown=True, followlinks=False
|
|
3029
|
+
for directories_seen, (current_directory, directory_names, file_names) in enumerate(
|
|
3030
|
+
os.walk(poc_root, topdown=True, followlinks=False), start=1
|
|
3101
3031
|
):
|
|
3102
|
-
directories_seen += 1
|
|
3103
3032
|
if directories_seen > FINDING_ARTIFACT_DIRECTORIES_LIMIT:
|
|
3104
|
-
directory_names[:] = []
|
|
3105
3033
|
break
|
|
3106
3034
|
current_path = Path(current_directory)
|
|
3107
3035
|
directory_names[:] = [
|
|
@@ -3122,15 +3050,15 @@ def finding_artifact_paths(scan_dir: Path, details: dict[str, Any]) -> list[str]
|
|
|
3122
3050
|
|
|
3123
3051
|
|
|
3124
3052
|
def scan_local_regular_file(scan_dir: Path, relative_path: str) -> bool:
|
|
3125
|
-
if len(relative_path.encode("utf-8")) > FINDING_LOCATION_PATH_BYTES:
|
|
3126
|
-
return False
|
|
3127
3053
|
try:
|
|
3054
|
+
if len(relative_path.encode("utf-8")) > FINDING_LOCATION_PATH_BYTES:
|
|
3055
|
+
return False
|
|
3128
3056
|
descriptor = open_scan_local_file_descriptor(
|
|
3129
3057
|
scan_dir,
|
|
3130
3058
|
relative_path,
|
|
3131
3059
|
f"finding artifact {relative_path}",
|
|
3132
3060
|
)
|
|
3133
|
-
except (ContractError, OSError):
|
|
3061
|
+
except (ContractError, OSError, UnicodeEncodeError):
|
|
3134
3062
|
return False
|
|
3135
3063
|
try:
|
|
3136
3064
|
return stat.S_ISREG(os.fstat(descriptor).st_mode)
|
|
@@ -3358,48 +3286,10 @@ def read_json_object(path: Path) -> dict[str, Any]:
|
|
|
3358
3286
|
return payload
|
|
3359
3287
|
|
|
3360
3288
|
|
|
3361
|
-
_WORKBENCH_PUBLICATION_CONTEXT =
|
|
3362
|
-
ARTIFACTS=ARTIFACTS,
|
|
3363
|
-
artifact_path=artifact_path,
|
|
3364
|
-
available_artifact_path=available_artifact_path,
|
|
3365
|
-
database_path=database_path,
|
|
3366
|
-
expected_coverage_mode=expected_coverage_mode,
|
|
3367
|
-
now=now,
|
|
3368
|
-
pin_legacy_manifest_digest=pin_legacy_manifest_digest,
|
|
3369
|
-
published_manifest_digest=published_manifest_digest,
|
|
3370
|
-
read_json_object=read_json_object,
|
|
3371
|
-
require_canonical_scan_directory=require_canonical_scan_directory,
|
|
3372
|
-
require_recorded_manifest_digest=require_recorded_manifest_digest,
|
|
3373
|
-
require_scan=require_scan,
|
|
3374
|
-
scan_result=scan_result,
|
|
3375
|
-
verify_manifest_binding=verify_manifest_binding,
|
|
3376
|
-
workspace_state=workspace_state,
|
|
3377
|
-
)
|
|
3289
|
+
_WORKBENCH_PUBLICATION_CONTEXT = SimpleNamespace(**globals())
|
|
3378
3290
|
|
|
3379
3291
|
|
|
3380
|
-
_WORKBENCH_DB_CONTEXT =
|
|
3381
|
-
ARTIFACTS=ARTIFACTS,
|
|
3382
|
-
artifact_path=artifact_path,
|
|
3383
|
-
deep_scan=deep_scan,
|
|
3384
|
-
expected_coverage_mode=expected_coverage_mode,
|
|
3385
|
-
handoff=handoff,
|
|
3386
|
-
index_findings=index_findings,
|
|
3387
|
-
now=now,
|
|
3388
|
-
optional_text=optional_text,
|
|
3389
|
-
parse_scan_cost=parse_scan_cost,
|
|
3390
|
-
published_manifest_digest=published_manifest_digest,
|
|
3391
|
-
read_json_object=read_json_object,
|
|
3392
|
-
require_canonical_scan_directory=require_canonical_scan_directory,
|
|
3393
|
-
require_recorded_manifest_digest=require_recorded_manifest_digest,
|
|
3394
|
-
require_scan=require_scan,
|
|
3395
|
-
require_uuid=require_uuid,
|
|
3396
|
-
require_workspace=require_workspace,
|
|
3397
|
-
scan_completion_lock=scan_completion_lock,
|
|
3398
|
-
scan_context=scan_context,
|
|
3399
|
-
verify_manifest_binding=verify_manifest_binding,
|
|
3400
|
-
workbench_completion_binding=workbench_completion_binding,
|
|
3401
|
-
workspace_state=workspace_state,
|
|
3402
|
-
)
|
|
3292
|
+
_WORKBENCH_DB_CONTEXT = SimpleNamespace(**globals())
|
|
3403
3293
|
|
|
3404
3294
|
|
|
3405
3295
|
def main() -> None:
|
|
@@ -3407,20 +3297,8 @@ def main() -> None:
|
|
|
3407
3297
|
sys.stdin.reconfigure(encoding="utf-8")
|
|
3408
3298
|
args = parse_args(__doc__)
|
|
3409
3299
|
deep_scan.configure(
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
state_dir=state_dir,
|
|
3413
|
-
require_scan=require_scan,
|
|
3414
|
-
require_workspace=require_workspace,
|
|
3415
|
-
require_target=require_target,
|
|
3416
|
-
require_remediation_target=require_remediation_target,
|
|
3417
|
-
require_scannable_target=require_scannable_target,
|
|
3418
|
-
require_scope=require_scope,
|
|
3419
|
-
ensure_security_target=ensure_security_target,
|
|
3420
|
-
require_canonical_scan_directory=require_canonical_scan_directory,
|
|
3421
|
-
safe_segment=safe_segment,
|
|
3422
|
-
compact_timestamp=compact_timestamp,
|
|
3423
|
-
scan_completion_lock=scan_completion_lock,
|
|
3300
|
+
SimpleNamespace(
|
|
3301
|
+
**globals(),
|
|
3424
3302
|
preserve_stopped_results=preserve_stopped_results_after_transition,
|
|
3425
3303
|
)
|
|
3426
3304
|
)
|
|
@@ -3432,7 +3310,15 @@ def main() -> None:
|
|
|
3432
3310
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3433
3311
|
return
|
|
3434
3312
|
if args.command == "inspect-setup":
|
|
3435
|
-
result =
|
|
3313
|
+
result = inspect_setup_values(
|
|
3314
|
+
args.target_path,
|
|
3315
|
+
args.scope,
|
|
3316
|
+
args.mode,
|
|
3317
|
+
args.diff_target_kind,
|
|
3318
|
+
args.diff_base_revision,
|
|
3319
|
+
args.diff_head_revision,
|
|
3320
|
+
args.diff_content_digest,
|
|
3321
|
+
)
|
|
3436
3322
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3437
3323
|
return
|
|
3438
3324
|
if args.command in {"save-artifact", "read-artifact"}:
|
|
@@ -3443,10 +3329,12 @@ def main() -> None:
|
|
|
3443
3329
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3444
3330
|
return
|
|
3445
3331
|
if args.command == "inspect-linear-publication":
|
|
3446
|
-
result = inspect_linear_publication(args)
|
|
3332
|
+
result = publication.inspect_linear_publication(_WORKBENCH_PUBLICATION_CONTEXT, args)
|
|
3447
3333
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3448
3334
|
return
|
|
3449
|
-
with closing(
|
|
3335
|
+
with closing(
|
|
3336
|
+
connect(deferred=args.command in {"get-scan", "list-scans", "database-info"})
|
|
3337
|
+
) as connection:
|
|
3450
3338
|
remediation.require_available(connection, args, require_scan)
|
|
3451
3339
|
if args.command == "create-workspace":
|
|
3452
3340
|
result = create_workspace(connection, args)
|
|
@@ -3461,9 +3349,9 @@ def main() -> None:
|
|
|
3461
3349
|
elif args.command == "start-scan":
|
|
3462
3350
|
result = start_scan(connection, args)
|
|
3463
3351
|
elif args.command == "start-prompt-only-scan":
|
|
3464
|
-
result =
|
|
3352
|
+
result = _start_prompt_driven_scan(connection, args, headless_standard=False)
|
|
3465
3353
|
elif args.command == "start-headless-standard-scan":
|
|
3466
|
-
result =
|
|
3354
|
+
result = _start_prompt_driven_scan(connection, args, headless_standard=True)
|
|
3467
3355
|
elif args.command == "begin-deep-scan":
|
|
3468
3356
|
result = deep_scan.begin_deep_scan(connection, args)
|
|
3469
3357
|
elif args.command == "get-deep-scan":
|
|
@@ -3556,15 +3444,15 @@ def main() -> None:
|
|
|
3556
3444
|
elif args.command == "complete-budget-exhausted-scan":
|
|
3557
3445
|
result = complete_budget_exhausted_scan(connection, args)
|
|
3558
3446
|
elif args.command == "cancel-scan":
|
|
3559
|
-
result = cancel_scan(connection, args)
|
|
3447
|
+
result = saved_results.cancel_scan(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3560
3448
|
elif args.command == "fail-scan":
|
|
3561
3449
|
result = fail_scan(connection, args)
|
|
3562
3450
|
elif args.command == "preserve-scan-results":
|
|
3563
|
-
result = preserve_scan_results(connection, args)
|
|
3451
|
+
result = saved_results.preserve_scan_results(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3564
3452
|
elif args.command == "recover-scan-results":
|
|
3565
3453
|
result = recover_scan_results(connection, args)
|
|
3566
3454
|
elif args.command == "write-scan-draft":
|
|
3567
|
-
result = write_scan_draft(connection, args)
|
|
3455
|
+
result = saved_results.write_scan_draft(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3568
3456
|
elif args.command == "save-scan-artifact":
|
|
3569
3457
|
result = saved_results.save_scan_artifact(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3570
3458
|
elif args.command == "mark-handoff-delivered":
|