@openai/codex-security 0.8.2 → 0.8.3
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 +43 -61
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- 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/permission-profile-preflight.mjs +46 -12
- 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/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +28 -0
- package/_bundled_plugin/references/finding-detail-fields.md +1 -0
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
- package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
- package/_bundled_plugin/scripts/finding_preview.py +5 -29
- package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
- package/_bundled_plugin/scripts/report_projection.py +87 -136
- package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
- package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
- package/_bundled_plugin/scripts/workbench_cli.py +102 -13
- package/_bundled_plugin/scripts/workbench_constants.py +9 -0
- package/_bundled_plugin/scripts/workbench_db.py +186 -360
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
- package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
- package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
- package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
- package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_setup.py +239 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
- package/_bundled_plugin/scripts/workbench_target.py +213 -20
- package/_bundled_plugin/scripts/workbench_validation.py +1 -9
- package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
- package/_bundled_plugin/shared/workbench-migrations.json +19 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +64 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +14 -8
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +411 -160
- package/dist/api.js.map +1 -1
- package/dist/auth.js +6 -1
- package/dist/auth.js.map +1 -1
- package/dist/blackduck-findings.d.ts +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +305 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +6 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +28 -9
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +608 -258
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +6 -5
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +162 -40
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +157 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +28 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +75 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +1 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +19 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2120 -39
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deep-scan.d.ts +11 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +235 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +7 -37
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +5 -11
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +9 -0
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +325 -179
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +12 -0
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1202 -214
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +8 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +65 -54
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +2 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +111 -0
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +29 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +314 -44
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-normalization.d.ts +1 -1
- package/dist/finding-normalization.d.ts.map +1 -1
- package/dist/finding-normalization.js +46 -11
- package/dist/finding-normalization.js.map +1 -1
- package/dist/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -29
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +7 -16
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +344 -56
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +55 -33
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +13 -18
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.js +18 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +131 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +22 -12
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +34 -20
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +90 -35
- package/dist/patch-tui.js.map +1 -1
- package/dist/private-finding-import.d.ts +246 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +387 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +10 -2
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +72 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/reader-selection.d.ts +13 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +81 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +5 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +30 -0
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -1
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +95 -52
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.js +40 -17
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +11 -13
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +16 -37
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +2 -0
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +22 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +46 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +208 -42
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +14 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +67 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +20 -48
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +12 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +198 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +21 -20
- package/dist/snyk-findings.js.map +1 -1
- package/dist/sonar-collector.d.ts +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +383 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +279 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +3 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +18 -12
- package/dist/targets.js.map +1 -1
- package/dist/terminal-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +0 -16
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +7 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +371 -0
- package/dist/veracode-findings.js.map +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -0
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +10 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +88 -49
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +1 -1
- package/docs/cli.md +310 -477
- package/docs/dedupe-records.md +10 -0
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +8 -9
- package/schemas/external-findings.schema.json +12 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -1
- package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
|
@@ -11,7 +11,7 @@ import sys
|
|
|
11
11
|
import uuid
|
|
12
12
|
from datetime import datetime, timedelta
|
|
13
13
|
from pathlib import Path
|
|
14
|
-
from typing import Any
|
|
14
|
+
from typing import Any
|
|
15
15
|
|
|
16
16
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
17
|
import workbench_saved_results as saved_results
|
|
@@ -22,118 +22,11 @@ from workbench_source_scopes import capture_source_scopes
|
|
|
22
22
|
from workbench_target import directory_snapshot_regular_file_count
|
|
23
23
|
from workbench_validation import optional_text, require_uuid, user_context_argument
|
|
24
24
|
|
|
25
|
-
DEEP_SCAN_WORKER_KINDS = ("setup", "discovery", "dedup")
|
|
26
|
-
DEEP_SCAN_WORKER_STATUSES = ("queued", "running", "succeeded", "failed", "canceled")
|
|
27
|
-
DEEP_SCAN_REPLACEABLE_FAILURE_KINDS = (
|
|
28
|
-
"policy_refusal",
|
|
29
|
-
"transient_error",
|
|
30
|
-
"invalid_discovery_artifacts",
|
|
31
|
-
)
|
|
32
|
-
DEEP_SCAN_TERMINAL_REASONS = ("saturated", "capped")
|
|
33
|
-
DEEP_SCAN_WORKFLOW_VERSION = "deep-security-scan/v1"
|
|
34
25
|
DEEP_SCAN_COORDINATOR_LEASE_SECONDS = 30
|
|
35
26
|
DEEP_SCAN_LEGACY_COORDINATOR_GRACE_SECONDS = 120
|
|
36
27
|
DEEP_SCAN_PUBLICATION_ERROR_SEPARATOR = "\nOriginal Deep Scan failure:\n"
|
|
37
28
|
|
|
38
29
|
|
|
39
|
-
def register_subcommands(subparsers: Any, positive_int: Callable[[str], int]) -> None:
|
|
40
|
-
begin_deep_scan = subparsers.add_parser("begin-deep-scan")
|
|
41
|
-
begin_deep_scan.add_argument("--thread-id", required=True)
|
|
42
|
-
begin_target = begin_deep_scan.add_mutually_exclusive_group(required=True)
|
|
43
|
-
begin_target.add_argument("--scan-id")
|
|
44
|
-
begin_target.add_argument("--target-path")
|
|
45
|
-
begin_deep_scan.add_argument("--scope", default=".")
|
|
46
|
-
begin_user_context = begin_deep_scan.add_mutually_exclusive_group()
|
|
47
|
-
begin_user_context.add_argument("--user-context")
|
|
48
|
-
begin_user_context.add_argument("--user-context-stdin", action="store_true")
|
|
49
|
-
begin_deep_scan.add_argument("--scan-root")
|
|
50
|
-
begin_deep_scan.add_argument("--claim-token")
|
|
51
|
-
begin_deep_scan.add_argument("--model")
|
|
52
|
-
begin_deep_scan.add_argument("--reasoning-effort")
|
|
53
|
-
begin_deep_scan.add_argument("--available-parallelism", type=positive_int)
|
|
54
|
-
begin_deep_scan.add_argument("--deep-scan-project-json")
|
|
55
|
-
begin_deep_scan.add_argument("--project-config-path")
|
|
56
|
-
begin_deep_scan.add_argument("--join-only", action="store_true")
|
|
57
|
-
begin_deep_scan.add_argument("--workflow-version", default=DEEP_SCAN_WORKFLOW_VERSION)
|
|
58
|
-
|
|
59
|
-
get_deep_scan = subparsers.add_parser("get-deep-scan")
|
|
60
|
-
get_deep_scan.add_argument("--scan-id", required=True)
|
|
61
|
-
get_deep_scan.add_argument("--thread-id", required=True)
|
|
62
|
-
|
|
63
|
-
acknowledge_result = subparsers.add_parser("acknowledge-deep-scan-result")
|
|
64
|
-
acknowledge_result.add_argument("--scan-id", required=True)
|
|
65
|
-
|
|
66
|
-
claim_coordinator = subparsers.add_parser("claim-deep-scan-coordinator")
|
|
67
|
-
claim_coordinator.add_argument("--scan-id", required=True)
|
|
68
|
-
claim_coordinator.add_argument("--thread-id", required=True)
|
|
69
|
-
claim_coordinator.add_argument("--claim-token")
|
|
70
|
-
claim_coordinator.add_argument("--coordinator-generation", type=positive_int)
|
|
71
|
-
|
|
72
|
-
upsert_deep_worker = subparsers.add_parser("upsert-deep-scan-worker")
|
|
73
|
-
upsert_deep_worker.add_argument("--scan-id", required=True)
|
|
74
|
-
upsert_deep_worker.add_argument("--worker-id", required=True)
|
|
75
|
-
upsert_deep_worker.add_argument("--kind", choices=DEEP_SCAN_WORKER_KINDS, required=True)
|
|
76
|
-
upsert_deep_worker.add_argument("--status", choices=DEEP_SCAN_WORKER_STATUSES, required=True)
|
|
77
|
-
upsert_deep_worker.add_argument("--prompt-path", required=True)
|
|
78
|
-
upsert_deep_worker.add_argument("--artifact-dir", required=True)
|
|
79
|
-
upsert_deep_worker.add_argument("--result-manifest-path")
|
|
80
|
-
upsert_deep_worker.add_argument("--attempt", type=non_negative_int)
|
|
81
|
-
upsert_deep_worker.add_argument("--sdk-thread-id")
|
|
82
|
-
upsert_deep_worker.add_argument("--error-message")
|
|
83
|
-
upsert_deep_worker.add_argument(
|
|
84
|
-
"--replaceable-failure-kind", choices=DEEP_SCAN_REPLACEABLE_FAILURE_KINDS
|
|
85
|
-
)
|
|
86
|
-
upsert_deep_worker.add_argument("--coordinator-generation", type=positive_int)
|
|
87
|
-
|
|
88
|
-
claim_deep_dedup = subparsers.add_parser("claim-deep-scan-dedup")
|
|
89
|
-
claim_deep_dedup.add_argument("--scan-id", required=True)
|
|
90
|
-
claim_deep_dedup.add_argument("--worker-id", required=True)
|
|
91
|
-
claim_deep_dedup.add_argument("--prompt-path", required=True)
|
|
92
|
-
claim_deep_dedup.add_argument("--artifact-dir", required=True)
|
|
93
|
-
claim_deep_dedup.add_argument("--input-worker-id", action="append", required=True)
|
|
94
|
-
claim_deep_dedup.add_argument("--coordinator-generation", type=positive_int)
|
|
95
|
-
|
|
96
|
-
commit_deep_dedup = subparsers.add_parser("commit-deep-scan-dedup")
|
|
97
|
-
commit_deep_dedup.add_argument("--scan-id", required=True)
|
|
98
|
-
commit_deep_dedup.add_argument("--worker-id", required=True)
|
|
99
|
-
commit_deep_dedup.add_argument("--result-manifest-path", required=True)
|
|
100
|
-
commit_deep_dedup.add_argument("--candidate-ledger-path")
|
|
101
|
-
commit_deep_dedup.add_argument("--new-findings-count", type=non_negative_int, required=True)
|
|
102
|
-
commit_deep_dedup.add_argument("--coordinator-generation", type=positive_int)
|
|
103
|
-
|
|
104
|
-
finish_deep_scan = subparsers.add_parser("finish-deep-scan")
|
|
105
|
-
finish_deep_scan.add_argument("--scan-id", required=True)
|
|
106
|
-
finish_deep_scan.add_argument(
|
|
107
|
-
"--terminal-reason", choices=DEEP_SCAN_TERMINAL_REASONS, required=True
|
|
108
|
-
)
|
|
109
|
-
finish_deep_scan.add_argument("--manifest-path", required=True)
|
|
110
|
-
finish_deep_scan.add_argument("--staged-manifest-path")
|
|
111
|
-
finish_deep_scan.add_argument("--omitted-worker-id", action="append", default=[])
|
|
112
|
-
finish_deep_scan.add_argument("--coordinator-generation", type=positive_int)
|
|
113
|
-
|
|
114
|
-
fail_deep_scan = subparsers.add_parser("fail-deep-scan")
|
|
115
|
-
fail_deep_scan.add_argument("--scan-id", required=True)
|
|
116
|
-
fail_deep_scan.add_argument("--message", required=True)
|
|
117
|
-
fail_deep_scan.add_argument("--manifest-path")
|
|
118
|
-
fail_deep_scan.add_argument("--staged-manifest-path")
|
|
119
|
-
fail_deep_scan.add_argument(
|
|
120
|
-
"--deep-status", choices=("failed", "interrupted"), default="failed"
|
|
121
|
-
)
|
|
122
|
-
fail_deep_scan.add_argument("--coordinator-generation", type=positive_int)
|
|
123
|
-
|
|
124
|
-
publication_failure = subparsers.add_parser("record-deep-scan-publication-failure")
|
|
125
|
-
publication_failure.add_argument("--scan-id", required=True)
|
|
126
|
-
publication_failure.add_argument("--message", required=True)
|
|
127
|
-
publication_failure.add_argument("--coordinator-generation", type=positive_int)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def non_negative_int(value: str) -> int:
|
|
131
|
-
parsed = int(value)
|
|
132
|
-
if parsed < 0:
|
|
133
|
-
raise argparse.ArgumentTypeError("expected a non-negative integer")
|
|
134
|
-
return parsed
|
|
135
|
-
|
|
136
|
-
|
|
137
30
|
_dependencies: Any = None
|
|
138
31
|
|
|
139
32
|
|
|
@@ -432,9 +325,12 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A
|
|
|
432
325
|
"A capped Deep Scan without completed discoveries requires an empty "
|
|
433
326
|
"candidate ledger."
|
|
434
327
|
)
|
|
328
|
+
recipe = json.loads(scan["recipe_json"]) if scan["recipe_json"] is not None else {}
|
|
435
329
|
return {
|
|
436
330
|
"scanId": run["scan_id"],
|
|
437
331
|
"sdkOwnsCompletion": scan["recipe_json"] is not None,
|
|
332
|
+
"serviceTier": run["service_tier"],
|
|
333
|
+
**({"severityRubric": recipe["severityRubric"]} if "severityRubric" in recipe else {}),
|
|
438
334
|
"targetPath": scan["target_path"],
|
|
439
335
|
"scope": scan["scope"],
|
|
440
336
|
"includePaths": dependencies().requested_scan_paths(scan),
|
|
@@ -562,6 +458,7 @@ def ensure_deep_scan_run(
|
|
|
562
458
|
workflow_version: str,
|
|
563
459
|
timestamp: str,
|
|
564
460
|
*,
|
|
461
|
+
service_tier: str | None,
|
|
565
462
|
pending_target_project_path: str | None = None,
|
|
566
463
|
) -> sqlite3.Row:
|
|
567
464
|
existing = connection.execute(
|
|
@@ -579,8 +476,8 @@ def ensure_deep_scan_run(
|
|
|
579
476
|
scan_id, schema_version, workflow_version, status, phase,
|
|
580
477
|
workers, subagents, stop_after_no_new, stop_after_consecutive_errors,
|
|
581
478
|
max_discovery_runs, max_time_hours, discovery_user_context_json,
|
|
582
|
-
created_at, updated_at, pending_target_project_path
|
|
583
|
-
) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
479
|
+
created_at, updated_at, service_tier, pending_target_project_path
|
|
480
|
+
) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
584
481
|
""",
|
|
585
482
|
(
|
|
586
483
|
scan["id"],
|
|
@@ -594,6 +491,7 @@ def ensure_deep_scan_run(
|
|
|
594
491
|
json.dumps(scan["user_context"]),
|
|
595
492
|
timestamp,
|
|
596
493
|
timestamp,
|
|
494
|
+
service_tier,
|
|
597
495
|
pending_target_project_path,
|
|
598
496
|
),
|
|
599
497
|
)
|
|
@@ -768,7 +666,14 @@ def begin_deep_scan_for_scan(
|
|
|
768
666
|
"UPDATE workspaces SET deep_scan_config_json = ? WHERE id = ? AND deep_scan_config_json IS NULL",
|
|
769
667
|
(json.dumps(configuration), workspace["id"]),
|
|
770
668
|
)
|
|
771
|
-
ensure_deep_scan_run(
|
|
669
|
+
ensure_deep_scan_run(
|
|
670
|
+
connection,
|
|
671
|
+
scan,
|
|
672
|
+
config,
|
|
673
|
+
workflow_version,
|
|
674
|
+
dependencies().now(),
|
|
675
|
+
service_tier=args.service_tier,
|
|
676
|
+
)
|
|
772
677
|
return deep_scan_result(connection, scan_id, start_disposition="created")
|
|
773
678
|
|
|
774
679
|
|
|
@@ -917,6 +822,7 @@ def begin_deep_scan_for_target(
|
|
|
917
822
|
config,
|
|
918
823
|
workflow_version,
|
|
919
824
|
timestamp,
|
|
825
|
+
service_tier=args.service_tier,
|
|
920
826
|
pending_target_project_path=project_path,
|
|
921
827
|
)
|
|
922
828
|
return deep_scan_result(connection, scan_id, start_disposition="created")
|
|
@@ -2040,6 +1946,11 @@ def fail_from_parent_scan(
|
|
|
2040
1946
|
message: str | None,
|
|
2041
1947
|
timestamp: str,
|
|
2042
1948
|
) -> None:
|
|
1949
|
+
# Parent failure may supersede a prepared seal even after the coordinator succeeded.
|
|
1950
|
+
connection.execute(
|
|
1951
|
+
"UPDATE deep_scan_runs SET terminal_reviewed_surface_count = NULL WHERE scan_id = ?",
|
|
1952
|
+
(scan_id,),
|
|
1953
|
+
)
|
|
2043
1954
|
connection.execute(
|
|
2044
1955
|
"""
|
|
2045
1956
|
UPDATE deep_scan_runs
|
|
@@ -2057,7 +1968,7 @@ def cancel_from_parent_scan(connection: sqlite3.Connection, scan_id: str, timest
|
|
|
2057
1968
|
"""
|
|
2058
1969
|
UPDATE deep_scan_runs
|
|
2059
1970
|
SET status = 'canceled', phase = 'terminal', cancel_requested = 1,
|
|
2060
|
-
completed_at = ?, updated_at = ?
|
|
1971
|
+
terminal_reviewed_surface_count = NULL, completed_at = ?, updated_at = ?
|
|
2061
1972
|
WHERE scan_id = ? AND status IN ('running', 'succeeded')
|
|
2062
1973
|
""",
|
|
2063
1974
|
(timestamp, timestamp, scan_id),
|
|
@@ -14,10 +14,11 @@ import json
|
|
|
14
14
|
import math
|
|
15
15
|
import os
|
|
16
16
|
import re
|
|
17
|
-
import secrets
|
|
18
17
|
import stat
|
|
19
18
|
import struct
|
|
20
19
|
import sys
|
|
20
|
+
from collections.abc import Callable, Iterator
|
|
21
|
+
from contextlib import contextmanager
|
|
21
22
|
from datetime import datetime, timezone
|
|
22
23
|
from pathlib import Path, PurePosixPath
|
|
23
24
|
from typing import Any, NamedTuple, TextIO
|
|
@@ -28,6 +29,10 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
28
29
|
import report_projection
|
|
29
30
|
import servicenow_avit
|
|
30
31
|
import threat_model_projection
|
|
32
|
+
from posix_scan_local_files import (
|
|
33
|
+
descriptor_relative_writes_available as _descriptor_relative_writes_available,
|
|
34
|
+
)
|
|
35
|
+
from posix_scan_local_files import managed_fd, stage_write
|
|
31
36
|
from review_state import checkpoint_review_state, review_state, review_summary
|
|
32
37
|
|
|
33
38
|
SCHEMA_VERSION = "1.0"
|
|
@@ -500,15 +505,6 @@ def _is_windows() -> bool:
|
|
|
500
505
|
return os.name == "nt"
|
|
501
506
|
|
|
502
507
|
|
|
503
|
-
def _descriptor_relative_writes_available() -> bool:
|
|
504
|
-
# os.replace accepts src_dir_fd/dst_dir_fd wherever descriptor-relative
|
|
505
|
-
# os.rename is supported, but Python lists only os.rename in supports_dir_fd.
|
|
506
|
-
required_operations = (os.mkdir, os.open, os.rename, os.stat, os.unlink)
|
|
507
|
-
return hasattr(os, "O_NOFOLLOW") and all(
|
|
508
|
-
operation in os.supports_dir_fd for operation in required_operations
|
|
509
|
-
)
|
|
510
|
-
|
|
511
|
-
|
|
512
508
|
def _windows_scan_local_files() -> Any:
|
|
513
509
|
"""Load the Win32 backend and shared stream comparison lazily."""
|
|
514
510
|
import windows_scan_local_files
|
|
@@ -534,13 +530,12 @@ def _open_verified_scan_directory(
|
|
|
534
530
|
raise _scan_local_directory_error(
|
|
535
531
|
"scan directory: expected an existing non-symlink directory", exc
|
|
536
532
|
) from exc
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
):
|
|
533
|
+
try:
|
|
534
|
+
if not os.path.samestat(expected, os.fstat(descriptor)):
|
|
535
|
+
raise ContractError("scan directory: changed while it was being opened")
|
|
536
|
+
except BaseException:
|
|
542
537
|
os.close(descriptor)
|
|
543
|
-
raise
|
|
538
|
+
raise
|
|
544
539
|
return descriptor
|
|
545
540
|
|
|
546
541
|
|
|
@@ -560,23 +555,41 @@ def scan_root_identity(scan_dir: Path) -> tuple[Path, tuple[int, int]]:
|
|
|
560
555
|
os.close(descriptor)
|
|
561
556
|
|
|
562
557
|
|
|
563
|
-
def _open_scan_local_directory(
|
|
558
|
+
def _open_scan_local_directory(
|
|
559
|
+
root_fd: int,
|
|
560
|
+
parts: tuple[str, ...],
|
|
561
|
+
*,
|
|
562
|
+
create: bool,
|
|
563
|
+
owner_read_write: bool = False,
|
|
564
|
+
sync_parents: bool = False,
|
|
565
|
+
) -> int:
|
|
564
566
|
descriptor = os.dup(root_fd)
|
|
565
567
|
try:
|
|
566
568
|
for part in parts:
|
|
569
|
+
if sync_parents:
|
|
570
|
+
os.fsync(descriptor)
|
|
567
571
|
if create:
|
|
568
572
|
try:
|
|
569
573
|
os.mkdir(part, mode=0o700, dir_fd=descriptor)
|
|
570
574
|
except FileExistsError:
|
|
571
575
|
# The open below verifies that an existing entry is a real directory.
|
|
572
576
|
pass
|
|
573
|
-
|
|
577
|
+
else:
|
|
578
|
+
if owner_read_write:
|
|
579
|
+
mode = os.stat(part, dir_fd=descriptor, follow_symlinks=False).st_mode
|
|
580
|
+
if mode & stat.S_IRWXU != stat.S_IRWXU:
|
|
581
|
+
os.rmdir(part, dir_fd=descriptor)
|
|
582
|
+
raise ScanLocalIOError(
|
|
583
|
+
f"{part}: process umask prevents owner access to the new directory"
|
|
584
|
+
)
|
|
585
|
+
parent_descriptor = descriptor
|
|
586
|
+
descriptor = os.open(
|
|
574
587
|
part,
|
|
575
588
|
os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0),
|
|
576
|
-
dir_fd=
|
|
589
|
+
dir_fd=parent_descriptor,
|
|
577
590
|
)
|
|
578
|
-
|
|
579
|
-
|
|
591
|
+
# If closing the parent fails, cleanup now owns the child.
|
|
592
|
+
os.close(parent_descriptor)
|
|
580
593
|
return descriptor
|
|
581
594
|
except BaseException:
|
|
582
595
|
os.close(descriptor)
|
|
@@ -766,6 +779,40 @@ def _sha256_scan_local_file(scan_dir: Path, relative_path: str, context: str) ->
|
|
|
766
779
|
return digest.hexdigest()
|
|
767
780
|
|
|
768
781
|
|
|
782
|
+
def scan_local_file_version(descriptor: int) -> tuple[os.stat_result, int]:
|
|
783
|
+
metadata = os.fstat(descriptor)
|
|
784
|
+
changed = (
|
|
785
|
+
_windows_scan_local_files().file_change_time(descriptor)
|
|
786
|
+
if _is_windows()
|
|
787
|
+
else metadata.st_ctime_ns
|
|
788
|
+
)
|
|
789
|
+
return metadata, changed
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
def _scan_local_write_path(
|
|
793
|
+
scan_dir: Path, relative_path: str, external_name: bool
|
|
794
|
+
) -> tuple[Path, str]:
|
|
795
|
+
scan_dir = _require_scan_directory(scan_dir)
|
|
796
|
+
if external_name:
|
|
797
|
+
if relative_path in {"", ".", ".."} or "/" in relative_path or "\0" in relative_path:
|
|
798
|
+
raise ContractError("external output path: expected a safe file name")
|
|
799
|
+
else:
|
|
800
|
+
relative_path = _require_portable_relative_path(relative_path, "scan-local output path")
|
|
801
|
+
return scan_dir, relative_path
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
@contextmanager
|
|
805
|
+
def _windows_write_errors(backend: Any, relative_path: str) -> Iterator[None]:
|
|
806
|
+
try:
|
|
807
|
+
yield
|
|
808
|
+
except FileExistsError:
|
|
809
|
+
raise
|
|
810
|
+
except backend.WindowsScanLocalPathError as exc:
|
|
811
|
+
raise ContractError(f"{relative_path}: {exc}") from exc
|
|
812
|
+
except OSError as exc:
|
|
813
|
+
raise ScanLocalIOError(f"{relative_path}: {exc}") from exc
|
|
814
|
+
|
|
815
|
+
|
|
769
816
|
def write_scan_local_bytes(
|
|
770
817
|
scan_dir: Path,
|
|
771
818
|
relative_path: str,
|
|
@@ -774,111 +821,96 @@ def write_scan_local_bytes(
|
|
|
774
821
|
external_name: bool = False,
|
|
775
822
|
expected_root_identity: tuple[int, int] | None = None,
|
|
776
823
|
owner_read_write: bool = False,
|
|
824
|
+
replace_existing: bool = True,
|
|
777
825
|
) -> None:
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
826
|
+
if _is_windows() and not _descriptor_relative_writes_available():
|
|
827
|
+
scan_dir, relative_path = _scan_local_write_path(scan_dir, relative_path, external_name)
|
|
828
|
+
backend = _windows_scan_local_files()
|
|
829
|
+
with _windows_write_errors(backend, relative_path):
|
|
830
|
+
backend.atomic_write(
|
|
831
|
+
scan_dir,
|
|
832
|
+
relative_path,
|
|
833
|
+
payload,
|
|
834
|
+
expected_root_identity=expected_root_identity,
|
|
835
|
+
replace_existing=replace_existing,
|
|
836
|
+
)
|
|
837
|
+
return
|
|
838
|
+
with stage_scan_local_bytes(
|
|
839
|
+
scan_dir,
|
|
840
|
+
relative_path,
|
|
841
|
+
payload,
|
|
842
|
+
external_name=external_name,
|
|
843
|
+
expected_root_identity=expected_root_identity,
|
|
844
|
+
owner_read_write=owner_read_write,
|
|
845
|
+
replace_existing=replace_existing,
|
|
846
|
+
) as publish:
|
|
847
|
+
publish()
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
@contextmanager
|
|
851
|
+
def stage_scan_local_bytes(
|
|
852
|
+
scan_dir: Path,
|
|
853
|
+
relative_path: str,
|
|
854
|
+
payload: bytes,
|
|
855
|
+
*,
|
|
856
|
+
external_name: bool = False,
|
|
857
|
+
expected_root_identity: tuple[int, int] | None = None,
|
|
858
|
+
owner_read_write: bool = False,
|
|
859
|
+
replace_existing: bool = False,
|
|
860
|
+
) -> Iterator[Callable[..., tuple[os.stat_result, int]]]:
|
|
861
|
+
scan_dir, relative_path = _scan_local_write_path(scan_dir, relative_path, external_name)
|
|
785
862
|
if not _descriptor_relative_writes_available():
|
|
786
863
|
if not _is_windows():
|
|
787
864
|
raise ContractError("scan-local output requires descriptor-relative file operations")
|
|
788
865
|
backend = _windows_scan_local_files()
|
|
789
|
-
|
|
790
|
-
backend.
|
|
866
|
+
with _windows_write_errors(backend, relative_path):
|
|
867
|
+
with backend.stage_write(
|
|
791
868
|
scan_dir,
|
|
792
869
|
relative_path,
|
|
793
870
|
payload,
|
|
794
871
|
expected_root_identity=expected_root_identity,
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
except OSError as exc:
|
|
799
|
-
raise ScanLocalIOError(f"{relative_path}: {exc}") from exc
|
|
872
|
+
replace_existing=replace_existing,
|
|
873
|
+
) as publish:
|
|
874
|
+
yield publish
|
|
800
875
|
return
|
|
801
|
-
|
|
802
|
-
parent_fd: int | None = None
|
|
803
|
-
temp_name: str | None = None
|
|
804
|
-
try:
|
|
805
|
-
root_fd = _open_verified_scan_directory(scan_dir, expected_root_identity)
|
|
876
|
+
with managed_fd(_open_verified_scan_directory(scan_dir, expected_root_identity)) as root_fd:
|
|
806
877
|
parts = PurePosixPath(relative_path).parts
|
|
807
878
|
try:
|
|
808
|
-
parent_fd = _open_scan_local_directory(
|
|
879
|
+
parent_fd = _open_scan_local_directory(
|
|
880
|
+
root_fd, parts[:-1], create=True, owner_read_write=owner_read_write
|
|
881
|
+
)
|
|
809
882
|
except OSError as exc:
|
|
810
883
|
raise _scan_local_directory_error(
|
|
811
884
|
f"{relative_path}: expected a path inside the scan directory", exc
|
|
812
885
|
) from exc
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
raise ContractError(f"{relative_path}: changed while it was being opened")
|
|
842
|
-
if expected_root_identity is not None and opened.st_size == len(payload):
|
|
843
|
-
try:
|
|
844
|
-
with os.fdopen(existing_fd, "rb") as handle:
|
|
845
|
-
existing_fd = -1
|
|
846
|
-
if _windows_scan_local_files().stream_matches_payload(
|
|
847
|
-
handle, payload
|
|
848
|
-
):
|
|
849
|
-
return
|
|
850
|
-
except OSError:
|
|
851
|
-
# A failed content comparison still allows an atomic replacement.
|
|
852
|
-
pass
|
|
853
|
-
finally:
|
|
854
|
-
if existing_fd >= 0:
|
|
855
|
-
os.close(existing_fd)
|
|
856
|
-
temp_name = f".{path.name}.{secrets.token_hex(8)}.tmp"
|
|
857
|
-
temp_fd = os.open(temp_name, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=parent_fd)
|
|
858
|
-
with os.fdopen(temp_fd, "wb") as handle:
|
|
859
|
-
if owner_read_write:
|
|
860
|
-
# Generated Markdown must remain editable under a restrictive umask.
|
|
861
|
-
os.fchmod(handle.fileno(), 0o600)
|
|
862
|
-
handle.write(payload)
|
|
863
|
-
handle.flush()
|
|
864
|
-
os.fsync(handle.fileno())
|
|
865
|
-
os.replace(temp_name, parts[-1], src_dir_fd=parent_fd, dst_dir_fd=parent_fd)
|
|
866
|
-
temp_name = None
|
|
867
|
-
finally:
|
|
868
|
-
try:
|
|
869
|
-
if temp_name is not None and parent_fd is not None:
|
|
870
|
-
try:
|
|
871
|
-
os.unlink(temp_name, dir_fd=parent_fd)
|
|
872
|
-
except FileNotFoundError:
|
|
873
|
-
# The temporary file is already gone, so cleanup is complete.
|
|
874
|
-
pass
|
|
875
|
-
finally:
|
|
876
|
-
try:
|
|
877
|
-
if parent_fd is not None:
|
|
878
|
-
os.close(parent_fd)
|
|
879
|
-
finally:
|
|
880
|
-
if root_fd is not None:
|
|
881
|
-
os.close(root_fd)
|
|
886
|
+
|
|
887
|
+
with managed_fd(parent_fd):
|
|
888
|
+
|
|
889
|
+
def check_parent(directory: Path) -> None:
|
|
890
|
+
# Admission can follow an archive while the staged parent stays open.
|
|
891
|
+
root = os.fstat(root_fd)
|
|
892
|
+
with (
|
|
893
|
+
managed_fd(
|
|
894
|
+
_open_verified_scan_directory(directory, (root.st_dev, root.st_ino))
|
|
895
|
+
) as current,
|
|
896
|
+
managed_fd(
|
|
897
|
+
_open_scan_local_directory(current, parts[:-1], create=False)
|
|
898
|
+
) as parent,
|
|
899
|
+
):
|
|
900
|
+
if not os.path.samestat(os.fstat(parent_fd), os.fstat(parent)):
|
|
901
|
+
raise ContractError(f"{relative_path}: parent changed before publication")
|
|
902
|
+
|
|
903
|
+
with stage_write(
|
|
904
|
+
parent_fd,
|
|
905
|
+
relative_path,
|
|
906
|
+
payload,
|
|
907
|
+
owner_read_write=owner_read_write,
|
|
908
|
+
replace_existing=replace_existing,
|
|
909
|
+
compare_existing=expected_root_identity is not None,
|
|
910
|
+
check_parent=check_parent,
|
|
911
|
+
contract_error=ContractError,
|
|
912
|
+
) as publish:
|
|
913
|
+
yield publish
|
|
882
914
|
|
|
883
915
|
|
|
884
916
|
def _remove_scan_local_file_if_exists(scan_dir: Path, relative_path: str) -> None:
|
|
@@ -1842,6 +1874,18 @@ def _validate_coverage(manifest: dict[str, Any], coverage: dict[str, Any], scan_
|
|
|
1842
1874
|
_require_safe_json_value(coverage, "coverage.json")
|
|
1843
1875
|
|
|
1844
1876
|
|
|
1877
|
+
def _require_unique_artifact_path(artifact: Any, context: str, collision_keys: set[str]) -> str:
|
|
1878
|
+
if not isinstance(artifact, dict):
|
|
1879
|
+
raise ContractError(f"{context}: expected an object")
|
|
1880
|
+
value = _require_str(artifact, "path", context)
|
|
1881
|
+
path = _require_portable_relative_path(value, f"{context}.path")
|
|
1882
|
+
collision_key = path.lower()
|
|
1883
|
+
if collision_key in collision_keys:
|
|
1884
|
+
raise ContractError(f"{context}.path: duplicate artifact path")
|
|
1885
|
+
collision_keys.add(collision_key)
|
|
1886
|
+
return path
|
|
1887
|
+
|
|
1888
|
+
|
|
1845
1889
|
def _validate_manifest(manifest: dict[str, Any]) -> None:
|
|
1846
1890
|
if manifest.get("documentType") != "codex-security.scan-manifest":
|
|
1847
1891
|
raise ContractError("manifest.documentType: expected codex-security.scan-manifest")
|
|
@@ -1873,16 +1917,8 @@ def _validate_manifest(manifest: dict[str, Any]) -> None:
|
|
|
1873
1917
|
artifact_collision_keys: set[str] = set()
|
|
1874
1918
|
for index, artifact in enumerate(artifacts):
|
|
1875
1919
|
context = f"manifest.scan.artifacts[{index}]"
|
|
1876
|
-
|
|
1877
|
-
raise ContractError(f"{context}: expected an object")
|
|
1878
|
-
path = _require_portable_relative_path(
|
|
1879
|
-
_require_str(artifact, "path", context), f"{context}.path"
|
|
1880
|
-
)
|
|
1881
|
-
collision_key = path.lower()
|
|
1882
|
-
if collision_key in artifact_collision_keys:
|
|
1883
|
-
raise ContractError(f"{context}.path: duplicate artifact path")
|
|
1920
|
+
path = _require_unique_artifact_path(artifact, context, artifact_collision_keys)
|
|
1884
1921
|
artifact_paths.add(path)
|
|
1885
|
-
artifact_collision_keys.add(collision_key)
|
|
1886
1922
|
_require_str(artifact, "sha256", context)
|
|
1887
1923
|
_require_str(artifact, "mediaType", context)
|
|
1888
1924
|
for required_path in ("findings.json", *(["coverage.json"] if "coverageRef" in scan else [])):
|
|
@@ -2201,17 +2237,9 @@ def _legacy_sealed_findings_for_validation(findings: dict[str, Any]) -> dict[str
|
|
|
2201
2237
|
legacy_evidence = finding.get("code_evidence")
|
|
2202
2238
|
if isinstance(legacy_evidence, list):
|
|
2203
2239
|
compatible_legacy_evidence = []
|
|
2204
|
-
for evidence in legacy_evidence:
|
|
2205
|
-
if not isinstance(evidence, dict):
|
|
2206
|
-
continue
|
|
2240
|
+
for evidence in report_projection.code_evidence_rows(legacy_evidence):
|
|
2207
2241
|
evidence_id = evidence.get("id")
|
|
2208
|
-
|
|
2209
|
-
if (
|
|
2210
|
-
not isinstance(evidence_id, str)
|
|
2211
|
-
or not evidence_id.strip()
|
|
2212
|
-
or not isinstance(evidence_code, str)
|
|
2213
|
-
or not evidence_code.strip()
|
|
2214
|
-
):
|
|
2242
|
+
if not isinstance(evidence_id, str) or not evidence_id.strip():
|
|
2215
2243
|
continue
|
|
2216
2244
|
if evidence_id in evidence_ids:
|
|
2217
2245
|
continue
|
|
@@ -2520,23 +2548,17 @@ def _finding_evidence_strength(finding: dict[str, Any]) -> int:
|
|
|
2520
2548
|
section = finding.get(section_name)
|
|
2521
2549
|
if not isinstance(section, dict):
|
|
2522
2550
|
continue
|
|
2523
|
-
for
|
|
2524
|
-
|
|
2525
|
-
if
|
|
2551
|
+
for item in report_projection.embedded_code_evidence(section):
|
|
2552
|
+
code = item["code"]
|
|
2553
|
+
if code in seen_codes:
|
|
2526
2554
|
continue
|
|
2527
|
-
|
|
2528
|
-
|
|
2555
|
+
evidence_id = item.get("id")
|
|
2556
|
+
if isinstance(evidence_id, str) and evidence_id.strip():
|
|
2557
|
+
if evidence_id in seen_ids:
|
|
2529
2558
|
continue
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
evidence_id = item.get("id")
|
|
2534
|
-
if isinstance(evidence_id, str) and evidence_id.strip():
|
|
2535
|
-
if evidence_id in seen_ids:
|
|
2536
|
-
continue
|
|
2537
|
-
seen_ids.add(evidence_id)
|
|
2538
|
-
seen_codes.add(code)
|
|
2539
|
-
strength += 1
|
|
2559
|
+
seen_ids.add(evidence_id)
|
|
2560
|
+
seen_codes.add(code)
|
|
2561
|
+
strength += 1
|
|
2540
2562
|
code = section.get("code")
|
|
2541
2563
|
if isinstance(code, str) and code.strip() and code not in seen_codes:
|
|
2542
2564
|
seen_codes.add(code)
|
|
@@ -2776,15 +2798,7 @@ def _validate_existing_seal(
|
|
|
2776
2798
|
artifact_collision_keys: set[str] = set()
|
|
2777
2799
|
for index, artifact in enumerate(artifacts):
|
|
2778
2800
|
context = f"manifest.scan.artifacts[{index}]"
|
|
2779
|
-
|
|
2780
|
-
raise ContractError(f"{context}: expected an object")
|
|
2781
|
-
path = _require_portable_relative_path(
|
|
2782
|
-
_require_str(artifact, "path", context), f"{context}.path"
|
|
2783
|
-
)
|
|
2784
|
-
collision_key = path.lower()
|
|
2785
|
-
if collision_key in artifact_collision_keys:
|
|
2786
|
-
raise ContractError(f"{context}.path: duplicate artifact path")
|
|
2787
|
-
artifact_collision_keys.add(collision_key)
|
|
2801
|
+
path = _require_unique_artifact_path(artifact, context, artifact_collision_keys)
|
|
2788
2802
|
expected_sha256 = _require_str(artifact, "sha256", context)
|
|
2789
2803
|
contents = (artifact_contents or {}).get(path)
|
|
2790
2804
|
actual_sha256 = (
|