@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
|
@@ -7,12 +7,12 @@ import json
|
|
|
7
7
|
import re
|
|
8
8
|
import sys
|
|
9
9
|
from bisect import bisect_right
|
|
10
|
-
from itertools import
|
|
10
|
+
from itertools import islice
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
from typing import Any
|
|
13
13
|
|
|
14
14
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
15
|
-
from report_projection import merged_root_cause
|
|
15
|
+
from report_projection import code_evidence_rows, merged_root_cause
|
|
16
16
|
from workbench_constants import (
|
|
17
17
|
FINDING_ATTACK_PATH_PREVIEW_BYTES,
|
|
18
18
|
FINDING_CODE_EVIDENCE_LIMIT,
|
|
@@ -35,14 +35,12 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
35
35
|
("rootCause", "root_cause"),
|
|
36
36
|
FINDING_ROOT_CAUSE_PREVIEW_BYTES,
|
|
37
37
|
(
|
|
38
|
-
"summary",
|
|
39
38
|
"description",
|
|
40
39
|
"detail",
|
|
41
40
|
"cause",
|
|
42
41
|
"rationale",
|
|
43
42
|
"why",
|
|
44
43
|
"explanation",
|
|
45
|
-
"evidenceRefs",
|
|
46
44
|
"evidence_refs",
|
|
47
45
|
),
|
|
48
46
|
(
|
|
@@ -54,21 +52,13 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
54
52
|
("validation",),
|
|
55
53
|
FINDING_VALIDATION_PREVIEW_BYTES,
|
|
56
54
|
(
|
|
57
|
-
"summary",
|
|
58
55
|
"conclusion",
|
|
59
|
-
"method",
|
|
60
|
-
"status",
|
|
61
56
|
"disposition",
|
|
62
57
|
"result",
|
|
63
58
|
"rationale",
|
|
64
59
|
"evidenceRef",
|
|
65
60
|
"evidence_ref",
|
|
66
|
-
"evidenceRefs",
|
|
67
61
|
"evidence_refs",
|
|
68
|
-
"assertions",
|
|
69
|
-
"evidence",
|
|
70
|
-
"counterEvidence",
|
|
71
|
-
"limitations",
|
|
72
62
|
),
|
|
73
63
|
(
|
|
74
64
|
(("summary", "conclusion", "rationale", "detail", "disposition"), 800),
|
|
@@ -85,23 +75,14 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
85
75
|
("attackPath",),
|
|
86
76
|
FINDING_ATTACK_PATH_PREVIEW_BYTES,
|
|
87
77
|
(
|
|
88
|
-
"narrative",
|
|
89
78
|
"summary",
|
|
90
79
|
"description",
|
|
91
|
-
"dataFlow",
|
|
92
80
|
"data_flow",
|
|
93
81
|
"dataflow",
|
|
94
82
|
"path",
|
|
95
|
-
"reachability",
|
|
96
|
-
"steps",
|
|
97
|
-
"authScope",
|
|
98
83
|
"auth_scope",
|
|
99
|
-
"vector",
|
|
100
|
-
"preconditions",
|
|
101
|
-
"assumptions",
|
|
102
84
|
"impact",
|
|
103
85
|
"likelihood",
|
|
104
|
-
"evidenceRefs",
|
|
105
86
|
"evidence_refs",
|
|
106
87
|
),
|
|
107
88
|
(
|
|
@@ -277,6 +258,7 @@ def bounded_finding_section(
|
|
|
277
258
|
key = next((alias for alias in aliases if alias in value), None)
|
|
278
259
|
if key is not None:
|
|
279
260
|
ordered[key] = bounded_json_value(value[key], [field_bytes])
|
|
261
|
+
# Reserved fields already come first. Order the remaining aliases and fields next.
|
|
280
262
|
for key in (*priority_keys, *value):
|
|
281
263
|
if key in value and key not in ordered:
|
|
282
264
|
ordered[key] = value[key]
|
|
@@ -295,14 +277,8 @@ def merged_bounded_code_evidence(value: dict[str, Any]) -> tuple[str | None, Any
|
|
|
295
277
|
if not catalogs:
|
|
296
278
|
return evidence_keys[0], value[evidence_keys[0]]
|
|
297
279
|
bounded = {}
|
|
298
|
-
for item in
|
|
299
|
-
if not (
|
|
300
|
-
isinstance(item, dict)
|
|
301
|
-
and isinstance(item.get("id"), str)
|
|
302
|
-
and bool(item["id"].strip())
|
|
303
|
-
and isinstance(item.get("code"), str)
|
|
304
|
-
and bool(item["code"].strip())
|
|
305
|
-
):
|
|
280
|
+
for item in code_evidence_rows(*catalogs):
|
|
281
|
+
if not isinstance(item.get("id"), str) or not item["id"].strip():
|
|
306
282
|
continue
|
|
307
283
|
if item["id"] in bounded:
|
|
308
284
|
continue
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Stage and publish POSIX scan-local files through verified directory descriptors."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import errno
|
|
7
|
+
import os
|
|
8
|
+
import secrets
|
|
9
|
+
import stat
|
|
10
|
+
import sys
|
|
11
|
+
from collections.abc import Callable, Iterator
|
|
12
|
+
from contextlib import contextmanager
|
|
13
|
+
from pathlib import Path, PurePosixPath
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def descriptor_relative_writes_available() -> bool:
|
|
17
|
+
# os.replace accepts src_dir_fd/dst_dir_fd wherever descriptor-relative
|
|
18
|
+
# os.rename is supported, but Python lists only os.rename in supports_dir_fd.
|
|
19
|
+
required_operations = (os.mkdir, os.open, os.rename, os.stat, os.unlink)
|
|
20
|
+
return hasattr(os, "O_NOFOLLOW") and all(
|
|
21
|
+
operation in os.supports_dir_fd for operation in required_operations
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@contextmanager
|
|
26
|
+
def managed_fd(descriptor: int) -> Iterator[int]:
|
|
27
|
+
try:
|
|
28
|
+
yield descriptor
|
|
29
|
+
finally:
|
|
30
|
+
os.close(descriptor)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@contextmanager
|
|
34
|
+
def stage_file(
|
|
35
|
+
parent_fd: int, filename: str, payload: bytes, owner_read_write: bool
|
|
36
|
+
) -> Iterator[int]:
|
|
37
|
+
descriptor = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=parent_fd)
|
|
38
|
+
try:
|
|
39
|
+
with os.fdopen(descriptor, "wb", closefd=False) as handle:
|
|
40
|
+
if owner_read_write:
|
|
41
|
+
os.fchmod(descriptor, 0o600)
|
|
42
|
+
handle.write(payload)
|
|
43
|
+
handle.flush()
|
|
44
|
+
os.fsync(descriptor)
|
|
45
|
+
yield descriptor
|
|
46
|
+
finally:
|
|
47
|
+
try:
|
|
48
|
+
entry = os.stat(filename, dir_fd=parent_fd, follow_symlinks=False)
|
|
49
|
+
if os.path.samestat(os.fstat(descriptor), entry):
|
|
50
|
+
os.unlink(filename, dir_fd=parent_fd)
|
|
51
|
+
except FileNotFoundError:
|
|
52
|
+
# Successful publication has already removed the temporary name.
|
|
53
|
+
pass
|
|
54
|
+
finally:
|
|
55
|
+
os.close(descriptor)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _rename_exclusive(parent_fd: int, source: str, destination: str) -> None:
|
|
59
|
+
import ctypes
|
|
60
|
+
|
|
61
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
62
|
+
if sys.platform == "linux":
|
|
63
|
+
rename = getattr(libc, "renameat2", None)
|
|
64
|
+
flag = 1 # RENAME_NOREPLACE
|
|
65
|
+
elif sys.platform == "darwin":
|
|
66
|
+
rename = getattr(libc, "renameatx_np", None)
|
|
67
|
+
flag = 4 # RENAME_EXCL
|
|
68
|
+
else:
|
|
69
|
+
rename = None
|
|
70
|
+
code = errno.ENOSYS
|
|
71
|
+
if rename is not None:
|
|
72
|
+
rename.argtypes = [
|
|
73
|
+
ctypes.c_int,
|
|
74
|
+
ctypes.c_char_p,
|
|
75
|
+
ctypes.c_int,
|
|
76
|
+
ctypes.c_char_p,
|
|
77
|
+
ctypes.c_uint,
|
|
78
|
+
]
|
|
79
|
+
rename.restype = ctypes.c_int
|
|
80
|
+
if rename(parent_fd, os.fsencode(source), parent_fd, os.fsencode(destination), flag) == 0:
|
|
81
|
+
return
|
|
82
|
+
code = ctypes.get_errno()
|
|
83
|
+
detail = os.strerror(code)
|
|
84
|
+
if code in {errno.ENOSYS, errno.ENOTSUP, errno.EOPNOTSUPP, errno.EINVAL}:
|
|
85
|
+
detail = f"cannot publish a new file atomically without hard links or exclusive rename ({detail})"
|
|
86
|
+
raise OSError(code, detail, destination)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def publish_new_file(parent_fd: int, source: str, destination: str) -> None:
|
|
90
|
+
try:
|
|
91
|
+
os.link(
|
|
92
|
+
source, destination, src_dir_fd=parent_fd, dst_dir_fd=parent_fd, follow_symlinks=False
|
|
93
|
+
)
|
|
94
|
+
except OSError as exc:
|
|
95
|
+
if exc.errno not in {
|
|
96
|
+
errno.EPERM,
|
|
97
|
+
errno.ENOTSUP,
|
|
98
|
+
errno.EOPNOTSUPP,
|
|
99
|
+
errno.ENOSYS,
|
|
100
|
+
errno.EXDEV,
|
|
101
|
+
errno.EMLINK,
|
|
102
|
+
}:
|
|
103
|
+
raise
|
|
104
|
+
_rename_exclusive(parent_fd, source, destination)
|
|
105
|
+
else:
|
|
106
|
+
os.unlink(source, dir_fd=parent_fd)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@contextmanager
|
|
110
|
+
def stage_write(
|
|
111
|
+
parent_fd: int,
|
|
112
|
+
relative_path: str,
|
|
113
|
+
payload: bytes,
|
|
114
|
+
*,
|
|
115
|
+
owner_read_write: bool,
|
|
116
|
+
replace_existing: bool,
|
|
117
|
+
compare_existing: bool,
|
|
118
|
+
check_parent: Callable[[Path], None],
|
|
119
|
+
contract_error: type[ValueError],
|
|
120
|
+
) -> Iterator[Callable[..., tuple[os.stat_result, int]]]:
|
|
121
|
+
name = PurePosixPath(relative_path).name
|
|
122
|
+
# Stage through the held parent so a replacement path cannot redirect the write.
|
|
123
|
+
try:
|
|
124
|
+
metadata = os.stat(name, dir_fd=parent_fd, follow_symlinks=False)
|
|
125
|
+
except FileNotFoundError:
|
|
126
|
+
pass
|
|
127
|
+
else:
|
|
128
|
+
if not replace_existing:
|
|
129
|
+
raise FileExistsError(errno.EEXIST, os.strerror(errno.EEXIST), relative_path)
|
|
130
|
+
if not stat.S_ISREG(metadata.st_mode):
|
|
131
|
+
raise contract_error(f"{relative_path}: expected a regular non-symlink file")
|
|
132
|
+
try:
|
|
133
|
+
existing_fd = os.open(
|
|
134
|
+
name,
|
|
135
|
+
os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0) | getattr(os, "O_NONBLOCK", 0),
|
|
136
|
+
dir_fd=parent_fd,
|
|
137
|
+
)
|
|
138
|
+
except OSError as exc:
|
|
139
|
+
if exc.errno not in {errno.ENOENT, errno.EACCES, errno.EPERM}:
|
|
140
|
+
raise
|
|
141
|
+
else:
|
|
142
|
+
with managed_fd(existing_fd):
|
|
143
|
+
opened = os.fstat(existing_fd)
|
|
144
|
+
if not stat.S_ISREG(opened.st_mode):
|
|
145
|
+
raise contract_error(f"{relative_path}: expected a regular non-symlink file")
|
|
146
|
+
if not os.path.samestat(opened, metadata):
|
|
147
|
+
raise contract_error(f"{relative_path}: changed while it was being opened")
|
|
148
|
+
if compare_existing and opened.st_size == len(payload):
|
|
149
|
+
from windows_scan_local_files import stream_matches_payload
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
with os.fdopen(existing_fd, "rb", closefd=False) as handle:
|
|
153
|
+
matches = stream_matches_payload(handle, payload)
|
|
154
|
+
except OSError:
|
|
155
|
+
# A failed content comparison still allows an atomic replacement.
|
|
156
|
+
matches = False
|
|
157
|
+
if matches:
|
|
158
|
+
yield lambda _directory=None: (opened, opened.st_ctime_ns)
|
|
159
|
+
return
|
|
160
|
+
candidate = f".{name}.{secrets.token_hex(8)}.tmp"
|
|
161
|
+
|
|
162
|
+
with stage_file(parent_fd, candidate, payload, owner_read_write) as staged_fd:
|
|
163
|
+
staged = os.fstat(staged_fd)
|
|
164
|
+
|
|
165
|
+
def publish(directory: Path | None = None) -> tuple[os.stat_result, int]:
|
|
166
|
+
if directory is not None:
|
|
167
|
+
check_parent(directory)
|
|
168
|
+
if replace_existing:
|
|
169
|
+
os.replace(candidate, name, src_dir_fd=parent_fd, dst_dir_fd=parent_fd)
|
|
170
|
+
return staged, staged.st_ctime_ns
|
|
171
|
+
named = os.stat(candidate, dir_fd=parent_fd, follow_symlinks=False)
|
|
172
|
+
if not os.path.samestat(staged, named) or staged.st_ctime_ns != named.st_ctime_ns:
|
|
173
|
+
raise contract_error(f"{relative_path}: staged file changed before publication")
|
|
174
|
+
publish_new_file(parent_fd, candidate, name)
|
|
175
|
+
published = os.fstat(staged_fd)
|
|
176
|
+
if (staged.st_size, staged.st_mtime_ns) != (
|
|
177
|
+
published.st_size,
|
|
178
|
+
published.st_mtime_ns,
|
|
179
|
+
):
|
|
180
|
+
raise contract_error(f"{relative_path}: staged contents changed during publication")
|
|
181
|
+
return published, published.st_ctime_ns
|
|
182
|
+
|
|
183
|
+
yield publish
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
if __name__ == "__main__":
|
|
187
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
@@ -7,6 +7,8 @@ import argparse
|
|
|
7
7
|
import json
|
|
8
8
|
import re
|
|
9
9
|
from collections import Counter
|
|
10
|
+
from collections.abc import Iterator
|
|
11
|
+
from itertools import chain
|
|
10
12
|
from typing import Any
|
|
11
13
|
|
|
12
14
|
SEVERITY_ORDER = {"critical": 0, "high": 1, "medium": 2, "low": 3, "informational": 4}
|
|
@@ -60,12 +62,15 @@ def _text(value: Any, fallback: str) -> str:
|
|
|
60
62
|
return _escape_markdown(normalized)
|
|
61
63
|
|
|
62
64
|
|
|
63
|
-
def
|
|
65
|
+
def _string_values(value: Any) -> Iterator[str]:
|
|
64
66
|
if isinstance(value, str):
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
yield value
|
|
68
|
+
elif isinstance(value, list):
|
|
69
|
+
yield from (item for item in value if isinstance(item, str))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _strings(value: Any) -> list[str]:
|
|
73
|
+
return [text for item in _string_values(value) if (text := _text(item, ""))]
|
|
69
74
|
|
|
70
75
|
|
|
71
76
|
def _path_label(value: str, *, ensure_ascii: bool = False) -> str:
|
|
@@ -139,7 +144,7 @@ def uses_deep_presentation(coverage: dict[str, Any], findings: list[dict[str, An
|
|
|
139
144
|
return any(_has_deep_child_metadata(finding) for finding in findings)
|
|
140
145
|
|
|
141
146
|
|
|
142
|
-
def _deep_title_parts(finding: dict[str, Any]) -> tuple[str, str | None]:
|
|
147
|
+
def _deep_title_parts(finding: dict[str, Any], report_id: str) -> tuple[str, str | None]:
|
|
143
148
|
title = finding.get("title")
|
|
144
149
|
if not isinstance(title, str):
|
|
145
150
|
return "Untitled finding", None
|
|
@@ -149,7 +154,7 @@ def _deep_title_parts(finding: dict[str, Any]) -> tuple[str, str | None]:
|
|
|
149
154
|
return normalized, None
|
|
150
155
|
annotation = match.group(2)
|
|
151
156
|
extensions = finding.get("extensions")
|
|
152
|
-
recognized_ids = [
|
|
157
|
+
recognized_ids = [report_id]
|
|
153
158
|
if isinstance(extensions, dict):
|
|
154
159
|
ledger_row_id = extensions.get("ledgerRowId")
|
|
155
160
|
if isinstance(ledger_row_id, str) and ledger_row_id.strip():
|
|
@@ -171,12 +176,6 @@ def _deep_finding_groups(
|
|
|
171
176
|
return list(groups.values())
|
|
172
177
|
|
|
173
178
|
|
|
174
|
-
def _deep_group_titles(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
|
|
175
|
-
return "<br>".join(
|
|
176
|
-
dict.fromkeys(_cell(_deep_title_parts(finding)[0]) for _, finding, _ in group)
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
|
|
180
179
|
def _deep_group_levels(
|
|
181
180
|
group: list[tuple[int, dict[str, Any], str | None]],
|
|
182
181
|
field: str,
|
|
@@ -186,47 +185,34 @@ def _deep_group_levels(
|
|
|
186
185
|
return "<br>".join(sorted(levels, key=lambda level: order.get(level, len(order))))
|
|
187
186
|
|
|
188
187
|
|
|
189
|
-
def
|
|
190
|
-
group: list[tuple[int, dict[str, Any], str | None]],
|
|
191
|
-
) -> list[str]:
|
|
188
|
+
def _deep_group_row(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
|
|
192
189
|
report_ids = [_deep_report_id(finding) for _, finding, _ in group]
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return [
|
|
201
|
-
(
|
|
202
|
-
finding.get("identity", {}).get("instance")
|
|
203
|
-
if label_counts[label] > 1 and isinstance(finding.get("identity"), dict)
|
|
204
|
-
else label
|
|
205
|
-
)
|
|
206
|
-
or _deep_report_id(finding)
|
|
207
|
-
for label, (_, finding, _) in zip(labels, group, strict=True)
|
|
208
|
-
]
|
|
209
|
-
|
|
190
|
+
report_counts = Counter(report_ids)
|
|
191
|
+
titles = []
|
|
192
|
+
labels = []
|
|
193
|
+
for report_id, (_, finding, _) in zip(report_ids, group, strict=True):
|
|
194
|
+
title, annotation = _deep_title_parts(finding, report_id)
|
|
195
|
+
titles.append(_cell(title))
|
|
196
|
+
labels.append(annotation if report_counts[report_id] > 1 and annotation else report_id)
|
|
210
197
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
198
|
+
label_counts = Counter(labels)
|
|
199
|
+
report_links = []
|
|
200
|
+
writeup_links = []
|
|
201
|
+
for report_id, label, (number, finding, path) in zip(report_ids, labels, group, strict=True):
|
|
202
|
+
identity = finding.get("identity")
|
|
203
|
+
if label_counts[label] > 1 and isinstance(identity, dict):
|
|
204
|
+
label = identity.get("instance") or report_id
|
|
205
|
+
label = _cell(label)
|
|
206
|
+
report_links.append(f"[{label}](#finding-{number})")
|
|
207
|
+
writeup_links.append(f"[Open {label}]({path})" if path else f"{label}: inline below")
|
|
208
|
+
return (
|
|
209
|
+
f"| {'<br>'.join(dict.fromkeys(titles))} | {'<br>'.join(report_links)} "
|
|
210
|
+
f"| {_deep_group_levels(group, 'severity', SEVERITY_ORDER)} "
|
|
211
|
+
f"| {_deep_group_levels(group, 'confidence', CONFIDENCE_ORDER)} "
|
|
212
|
+
f"| {'<br>'.join(writeup_links)} |"
|
|
216
213
|
)
|
|
217
214
|
|
|
218
215
|
|
|
219
|
-
def _deep_group_writeup_links(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
|
|
220
|
-
labels = _deep_group_report_labels(group)
|
|
221
|
-
links: list[str] = []
|
|
222
|
-
for label, (_, _, report_path) in zip(labels, group, strict=True):
|
|
223
|
-
report_id = _cell(label)
|
|
224
|
-
links.append(
|
|
225
|
-
f"[Open {report_id}]({report_path})" if report_path else f"{report_id}: inline below"
|
|
226
|
-
)
|
|
227
|
-
return "<br>".join(links)
|
|
228
|
-
|
|
229
|
-
|
|
230
216
|
def _writeup_report_path(finding: dict[str, Any]) -> str | None:
|
|
231
217
|
writeup = finding.get("writeup")
|
|
232
218
|
if writeup is None:
|
|
@@ -255,51 +241,43 @@ def _bullet_section(heading: str, items: list[str]) -> list[str]:
|
|
|
255
241
|
return ["", heading, *(f"- {item}" for item in items)] if items else []
|
|
256
242
|
|
|
257
243
|
|
|
258
|
-
def
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
isinstance(item, dict)
|
|
267
|
-
and isinstance(item.get("id"), str)
|
|
244
|
+
def code_evidence_rows(*catalogs: Any) -> Iterator[dict[str, Any]]:
|
|
245
|
+
for items in catalogs:
|
|
246
|
+
if isinstance(items, list):
|
|
247
|
+
yield from (
|
|
248
|
+
item
|
|
249
|
+
for item in items
|
|
250
|
+
if isinstance(item, dict)
|
|
268
251
|
and isinstance(item.get("code"), str)
|
|
269
252
|
and item["code"].strip()
|
|
270
|
-
)
|
|
271
|
-
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def embedded_code_evidence(section: dict[str, Any]) -> Iterator[dict[str, Any]]:
|
|
257
|
+
return code_evidence_rows(section.get("codeEvidence"), section.get("code_evidence"))
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _code_evidence_catalog(finding: dict[str, Any]) -> dict[str, dict[str, Any]]:
|
|
261
|
+
catalog = {}
|
|
262
|
+
for item in embedded_code_evidence(finding):
|
|
263
|
+
if isinstance(item.get("id"), str):
|
|
264
|
+
catalog.setdefault(item["id"], item)
|
|
272
265
|
return catalog
|
|
273
266
|
|
|
274
267
|
|
|
275
268
|
def _section_code_evidence(
|
|
276
|
-
|
|
269
|
+
catalog: dict[str, dict[str, Any]], *sections: dict[str, Any]
|
|
277
270
|
) -> list[dict[str, Any]]:
|
|
278
|
-
catalog = _code_evidence_catalog(finding)
|
|
279
|
-
resolved: list[dict[str, Any]] = []
|
|
280
|
-
for section in sections:
|
|
281
|
-
for key in ("evidenceRefs", "evidence_refs"):
|
|
282
|
-
refs = section.get(key, [])
|
|
283
|
-
if isinstance(refs, str):
|
|
284
|
-
refs = [refs]
|
|
285
|
-
if isinstance(refs, list):
|
|
286
|
-
resolved.extend(
|
|
287
|
-
catalog[ref] for ref in refs if isinstance(ref, str) and ref in catalog
|
|
288
|
-
)
|
|
289
|
-
for key in ("codeEvidence", "code_evidence"):
|
|
290
|
-
embedded = section.get(key, [])
|
|
291
|
-
if isinstance(embedded, list):
|
|
292
|
-
resolved.extend(
|
|
293
|
-
item
|
|
294
|
-
for item in embedded
|
|
295
|
-
if isinstance(item, dict)
|
|
296
|
-
and isinstance(item.get("code"), str)
|
|
297
|
-
and item["code"].strip()
|
|
298
|
-
)
|
|
299
271
|
unique: dict[tuple[str, str], dict[str, Any]] = {}
|
|
300
|
-
for
|
|
301
|
-
|
|
302
|
-
|
|
272
|
+
for section in sections:
|
|
273
|
+
referenced = (
|
|
274
|
+
catalog[ref]
|
|
275
|
+
for key in ("evidenceRefs", "evidence_refs")
|
|
276
|
+
for ref in _string_values(section.get(key))
|
|
277
|
+
if ref in catalog
|
|
278
|
+
)
|
|
279
|
+
for item in chain(referenced, embedded_code_evidence(section)):
|
|
280
|
+
unique.setdefault((str(item.get("id", "")), item["code"]), item)
|
|
303
281
|
return list(unique.values())
|
|
304
282
|
|
|
305
283
|
|
|
@@ -359,12 +337,7 @@ def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
|
|
|
359
337
|
]
|
|
360
338
|
if evidence_values:
|
|
361
339
|
merged["evidenceRefs"] = list(
|
|
362
|
-
dict.fromkeys(
|
|
363
|
-
item
|
|
364
|
-
for evidence in evidence_values
|
|
365
|
-
for item in (evidence if isinstance(evidence, list) else [evidence])
|
|
366
|
-
if isinstance(item, str)
|
|
367
|
-
)
|
|
340
|
+
dict.fromkeys(item for evidence in evidence_values for item in _string_values(evidence))
|
|
368
341
|
)
|
|
369
342
|
|
|
370
343
|
embedded_evidence = [
|
|
@@ -396,9 +369,9 @@ def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
|
|
|
396
369
|
|
|
397
370
|
|
|
398
371
|
def _root_cause_code_evidence(
|
|
399
|
-
finding: dict[str, Any], root_cause: dict[str, Any]
|
|
372
|
+
finding: dict[str, Any], root_cause: dict[str, Any], catalog: dict[str, dict[str, Any]]
|
|
400
373
|
) -> list[dict[str, Any]]:
|
|
401
|
-
evidence = _section_code_evidence(
|
|
374
|
+
evidence = _section_code_evidence(catalog, root_cause)
|
|
402
375
|
legacy_code = root_cause.get("code")
|
|
403
376
|
if not isinstance(legacy_code, str) or not legacy_code.strip():
|
|
404
377
|
return evidence
|
|
@@ -599,33 +572,17 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
599
572
|
if isinstance((value := attack_path.get(key)), (str, dict))
|
|
600
573
|
]
|
|
601
574
|
dataflow: dict[str, Any] = {}
|
|
602
|
-
for
|
|
603
|
-
|
|
604
|
-
(
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
)
|
|
611
|
-
if value
|
|
612
|
-
dataflow[key] = value
|
|
613
|
-
transformations = list(
|
|
614
|
-
dict.fromkeys(
|
|
615
|
-
transformation
|
|
616
|
-
for section in dataflow_sections
|
|
617
|
-
for transformation in (
|
|
618
|
-
[section.get("transformations")]
|
|
619
|
-
if isinstance(section.get("transformations"), str)
|
|
620
|
-
else section.get("transformations")
|
|
621
|
-
if isinstance(section.get("transformations"), list)
|
|
622
|
-
else []
|
|
623
|
-
)
|
|
624
|
-
if isinstance(transformation, str) and transformation.strip()
|
|
625
|
-
)
|
|
575
|
+
for section in dataflow_sections:
|
|
576
|
+
for key in ("summary", "source", "sink", "outcome"):
|
|
577
|
+
value = section.get(key)
|
|
578
|
+
if isinstance(value, str) and value.strip():
|
|
579
|
+
dataflow.setdefault(key, value)
|
|
580
|
+
transformations = dict.fromkeys(
|
|
581
|
+
value
|
|
582
|
+
for section in dataflow_sections
|
|
583
|
+
for value in _string_values(section.get("transformations"))
|
|
584
|
+
if value.strip()
|
|
626
585
|
)
|
|
627
|
-
if transformations:
|
|
628
|
-
dataflow["transformations"] = transformations
|
|
629
586
|
raw_reachability = attack_path.get("reachability")
|
|
630
587
|
reachability = (
|
|
631
588
|
{"summary": raw_reachability}
|
|
@@ -654,10 +611,11 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
654
611
|
raw_root_cause if isinstance(raw_root_cause, str) else root_cause.get("summary"),
|
|
655
612
|
"",
|
|
656
613
|
)
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
614
|
+
catalog = _code_evidence_catalog(finding)
|
|
615
|
+
root_cause_code_evidence = _root_cause_code_evidence(finding, root_cause, catalog)
|
|
616
|
+
validation_code_evidence = _section_code_evidence(catalog, validation)
|
|
617
|
+
dataflow_code_evidence = _section_code_evidence(catalog, attack_path, *dataflow_sections)
|
|
618
|
+
reachability_code_evidence = _section_code_evidence(catalog, reachability)
|
|
661
619
|
dataflow_summary = _text(dataflow.get("summary"), "") or (
|
|
662
620
|
f"The canonical finding records the affected path at {_locations(finding)}, "
|
|
663
621
|
"but no expanded source-to-sink narrative was recorded."
|
|
@@ -704,7 +662,9 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
704
662
|
for label, key in (("Source", "source"), ("Sink", "sink"), ("Outcome", "outcome")):
|
|
705
663
|
if dataflow.get(key):
|
|
706
664
|
lines.extend(["", f"- **{label}:** {_text(dataflow[key], 'not recorded')}"])
|
|
707
|
-
lines.extend(
|
|
665
|
+
lines.extend(
|
|
666
|
+
_bullet_section("Transformations:", [_text(value, "") for value in transformations])
|
|
667
|
+
)
|
|
708
668
|
lines.extend(_code_evidence_lines(dataflow_code_evidence))
|
|
709
669
|
lines.extend(["", "#### Reachability", "", reachability_summary])
|
|
710
670
|
for label, key in (
|
|
@@ -718,10 +678,7 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
718
678
|
lines.extend(["", f"- **{label}:** {_text(reachability[key], 'not recorded')}"])
|
|
719
679
|
preconditions = list(
|
|
720
680
|
dict.fromkeys(
|
|
721
|
-
|
|
722
|
-
*_strings(attack_path.get("preconditions")),
|
|
723
|
-
*_strings(reachability.get("preconditions")),
|
|
724
|
-
]
|
|
681
|
+
_strings(attack_path.get("preconditions")) + _strings(reachability.get("preconditions"))
|
|
725
682
|
)
|
|
726
683
|
)
|
|
727
684
|
lines.extend(_bullet_section("Preconditions:", preconditions))
|
|
@@ -912,13 +869,7 @@ def build_report_markdown(
|
|
|
912
869
|
"| --- | --- | --- | --- | --- |",
|
|
913
870
|
]
|
|
914
871
|
)
|
|
915
|
-
for group in deep_finding_groups
|
|
916
|
-
lines.append(
|
|
917
|
-
f"| {_deep_group_titles(group)} | {_deep_group_report_links(group)} "
|
|
918
|
-
f"| {_deep_group_levels(group, 'severity', SEVERITY_ORDER)} "
|
|
919
|
-
f"| {_deep_group_levels(group, 'confidence', CONFIDENCE_ORDER)} "
|
|
920
|
-
f"| {_deep_group_writeup_links(group)} |"
|
|
921
|
-
)
|
|
872
|
+
lines.extend(_deep_group_row(group) for group in deep_finding_groups)
|
|
922
873
|
else:
|
|
923
874
|
lines.extend(
|
|
924
875
|
[
|
|
@@ -57,14 +57,10 @@ def receipt(validated: dict[str, Any]) -> dict[str, Any]:
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def
|
|
60
|
+
def main(argv: list[str] | None = None) -> int:
|
|
61
61
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
62
62
|
parser.add_argument("--scan-dir", required=True, type=Path)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def main(argv: list[str] | None = None) -> int:
|
|
67
|
-
args = _parse_args(sys.argv[1:] if argv is None else argv)
|
|
63
|
+
args = parser.parse_args(argv)
|
|
68
64
|
try:
|
|
69
65
|
validated = validate_contract(args.scan_dir)
|
|
70
66
|
except (OSError, ValueError, RecursionError) as exc:
|