@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
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render saved structured or Markdown threat models without running analysis."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import importlib.util
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
_STRUCTURED_SECTIONS = (
|
|
15
|
+
("Assets", "assets"),
|
|
16
|
+
("Trust Boundaries", "trustBoundaries"),
|
|
17
|
+
("Attacker Capabilities", "attackerCapabilities"),
|
|
18
|
+
("Security Objectives", "securityObjectives"),
|
|
19
|
+
("Assumptions", "assumptions"),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _is_structured_model(model: dict[str, Any]) -> bool:
|
|
24
|
+
summary = model.get("summary")
|
|
25
|
+
return (
|
|
26
|
+
isinstance(summary, str)
|
|
27
|
+
and bool(summary)
|
|
28
|
+
and all(
|
|
29
|
+
isinstance(values := model.get(key, []), list)
|
|
30
|
+
and all(isinstance(value, str) and value for value in values)
|
|
31
|
+
for _, key in _STRUCTURED_SECTIONS
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _markdown_content(model: dict[str, Any]) -> str | None:
|
|
37
|
+
content = model.get("content")
|
|
38
|
+
if model.get("format") == "markdown" and isinstance(content, str) and content.strip():
|
|
39
|
+
return content
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def threat_model_body(model: dict[str, Any]) -> str:
|
|
44
|
+
"""Keep authored Markdown intact, including summaries from older scans."""
|
|
45
|
+
content = _markdown_content(model)
|
|
46
|
+
if content is not None:
|
|
47
|
+
# The structured schema permits legacy metadata as extension fields.
|
|
48
|
+
if _is_structured_model(model):
|
|
49
|
+
return content
|
|
50
|
+
if "origin" in model and model["origin"] not in (
|
|
51
|
+
"generated",
|
|
52
|
+
"provided",
|
|
53
|
+
"reconciled",
|
|
54
|
+
"recovered",
|
|
55
|
+
):
|
|
56
|
+
raise ValueError("threatModel.origin: unsupported value")
|
|
57
|
+
if "scope" in model:
|
|
58
|
+
scope = model["scope"]
|
|
59
|
+
if not isinstance(scope, dict) or "includePaths" not in scope:
|
|
60
|
+
raise ValueError("threatModel.scope: expected an object with includePaths")
|
|
61
|
+
for key in ("includePaths", "excludePaths"):
|
|
62
|
+
if key in scope and (
|
|
63
|
+
not isinstance(scope[key], list)
|
|
64
|
+
or not all(isinstance(path, str) and path for path in scope[key])
|
|
65
|
+
):
|
|
66
|
+
raise ValueError(
|
|
67
|
+
f"threatModel.scope.{key}: expected an array of non-empty strings"
|
|
68
|
+
)
|
|
69
|
+
if "summary" in scope and (
|
|
70
|
+
not isinstance(scope["summary"], str) or not scope["summary"]
|
|
71
|
+
):
|
|
72
|
+
raise ValueError("threatModel.scope.summary: expected a non-empty string")
|
|
73
|
+
return content
|
|
74
|
+
summary = model.get("summary")
|
|
75
|
+
if not isinstance(summary, str) or not summary:
|
|
76
|
+
if model.get("format") == "markdown":
|
|
77
|
+
raise ValueError("threatModel.content: expected non-empty Markdown")
|
|
78
|
+
raise ValueError("threatModel.summary: expected a non-empty string")
|
|
79
|
+
sections = [
|
|
80
|
+
summary if summary.strip() else "No explicit canonical threat-model summary was recorded."
|
|
81
|
+
]
|
|
82
|
+
for heading, key in _STRUCTURED_SECTIONS:
|
|
83
|
+
values = model.get(key, [])
|
|
84
|
+
if not isinstance(values, list):
|
|
85
|
+
raise ValueError(f"threatModel.{key}: expected an array")
|
|
86
|
+
if not values:
|
|
87
|
+
continue
|
|
88
|
+
for index, value in enumerate(values):
|
|
89
|
+
if not isinstance(value, str) or not value:
|
|
90
|
+
raise ValueError(f"threatModel.{key}[{index}]: expected a non-empty string")
|
|
91
|
+
sections.append(f"## {heading}")
|
|
92
|
+
sections.append("\n".join("- " + value.replace("\n", "\n ") for value in values))
|
|
93
|
+
return "\n\n".join(sections)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _scope_lines(scope: Any, label: str, text: Callable[[Any, str], str]) -> list[str]:
|
|
97
|
+
# Older structured models may use these extension names for unrelated data.
|
|
98
|
+
included = scope.get("includePaths") if isinstance(scope, dict) else None
|
|
99
|
+
if not isinstance(included, list) or not all(isinstance(path, str) for path in included):
|
|
100
|
+
return [f"- {label}: not recorded"]
|
|
101
|
+
lines = [f"- {label}: {text(', '.join(included), 'none')}"]
|
|
102
|
+
excluded = scope.get("excludePaths")
|
|
103
|
+
if isinstance(excluded, list) and excluded and all(isinstance(path, str) for path in excluded):
|
|
104
|
+
lines.append(f"- {label} exclusions: {text(', '.join(excluded), 'none')}")
|
|
105
|
+
summary = scope.get("summary")
|
|
106
|
+
if isinstance(summary, str) and summary:
|
|
107
|
+
lines.append(f"- {label} description: {text(summary, 'not recorded')}")
|
|
108
|
+
return lines
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def render_threat_model(model: dict[str, Any], provenance: dict[str, Any] | None = None) -> bytes:
|
|
112
|
+
"""Render a portable document with authored content and recorded provenance."""
|
|
113
|
+
body = threat_model_body(model)
|
|
114
|
+
if _markdown_content(model) is None:
|
|
115
|
+
body = "# Threat Model\n\n" + body
|
|
116
|
+
script = Path(__file__).resolve().with_name("report_projection.py")
|
|
117
|
+
spec = importlib.util.spec_from_file_location("codex_security_report_projection", script)
|
|
118
|
+
if spec is None or spec.loader is None:
|
|
119
|
+
raise ValueError(f"could not load report projection helper: {script}")
|
|
120
|
+
report = importlib.util.module_from_spec(spec)
|
|
121
|
+
spec.loader.exec_module(report)
|
|
122
|
+
text = report._text
|
|
123
|
+
provenance = provenance or {}
|
|
124
|
+
footer = ["---", "", "## Saved Model Context", ""]
|
|
125
|
+
for key, label in (
|
|
126
|
+
("source", "Source"),
|
|
127
|
+
("scanId", "Scan"),
|
|
128
|
+
("target", "Target"),
|
|
129
|
+
("revision", "Revision"),
|
|
130
|
+
("snapshotDigest", "Snapshot"),
|
|
131
|
+
("status", "Result status"),
|
|
132
|
+
):
|
|
133
|
+
if provenance.get(key):
|
|
134
|
+
footer.append(f"- {label}: {text(str(provenance[key]), 'not recorded')}")
|
|
135
|
+
footer.append(
|
|
136
|
+
f"- Model origin: {text(str(model.get('origin', 'not recorded')), 'not recorded')}"
|
|
137
|
+
)
|
|
138
|
+
footer.extend(_scope_lines(model.get("scope"), "Model scope", text))
|
|
139
|
+
scan_scope = provenance.get("scanScope")
|
|
140
|
+
if isinstance(scan_scope, dict):
|
|
141
|
+
footer.extend(_scope_lines(scan_scope, "Scan scope", text))
|
|
142
|
+
if provenance.get("provisional"):
|
|
143
|
+
footer.extend(["", "This is a provisional model saved before successful completion."])
|
|
144
|
+
return (body + ("\n" if body.endswith("\n") else "\n\n") + "\n".join(footer) + "\n").encode(
|
|
145
|
+
"utf-8"
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def main() -> int:
|
|
150
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
151
|
+
parser.add_argument("--input-json-stdin", action="store_true", required=True)
|
|
152
|
+
parser.parse_args()
|
|
153
|
+
try:
|
|
154
|
+
payload = json.load(sys.stdin)
|
|
155
|
+
sys.stdout.buffer.write(
|
|
156
|
+
render_threat_model(payload["threatModel"], payload.get("provenance"))
|
|
157
|
+
)
|
|
158
|
+
except (KeyError, TypeError, ValueError) as exc:
|
|
159
|
+
parser.error(str(exc))
|
|
160
|
+
return 0
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
if __name__ == "__main__":
|
|
164
|
+
raise SystemExit(main())
|
|
@@ -453,6 +453,12 @@ def scan_root_identity(scan_dir: Path) -> tuple[Path, tuple[int, int]]:
|
|
|
453
453
|
def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
|
|
454
454
|
"""Open a verified regular file and return an owned binary read descriptor."""
|
|
455
455
|
|
|
456
|
+
return open_read_fd_with_path(scan_dir, relative_path, context)[0]
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def open_read_fd_with_path(scan_dir: Path, relative_path: str, context: str) -> tuple[int, str]:
|
|
460
|
+
"""Return the descriptor and its filename while the verified parents are held."""
|
|
461
|
+
|
|
456
462
|
try:
|
|
457
463
|
with _locked_parent(scan_dir, relative_path, create=False) as (parent_path, leaf_name):
|
|
458
464
|
path = parent_path / leaf_name
|
|
@@ -467,10 +473,13 @@ def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
|
|
|
467
473
|
assert handle is not None and handle.value is not None
|
|
468
474
|
with handle:
|
|
469
475
|
_verify_regular_file(handle.value, path)
|
|
476
|
+
filename = Path(_final_path(handle.value)).name
|
|
477
|
+
resolved_path = PurePosixPath(relative_path).with_name(filename).as_posix()
|
|
470
478
|
raw_handle = handle.detach()
|
|
471
479
|
try:
|
|
472
480
|
assert _msvcrt is not None
|
|
473
|
-
|
|
481
|
+
descriptor = _msvcrt.open_osfhandle(raw_handle, os.O_RDONLY | os.O_BINARY)
|
|
482
|
+
return descriptor, resolved_path
|
|
474
483
|
except BaseException:
|
|
475
484
|
_close_handle(raw_handle)
|
|
476
485
|
raise
|
|
@@ -686,9 +695,5 @@ def unlink_if_exists(scan_dir: Path, relative_path: str) -> None:
|
|
|
686
695
|
_mark_handle_for_deletion(handle.value)
|
|
687
696
|
|
|
688
697
|
|
|
689
|
-
def main() -> None:
|
|
690
|
-
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
691
|
-
|
|
692
|
-
|
|
693
698
|
if __name__ == "__main__":
|
|
694
|
-
|
|
699
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
@@ -16,3 +16,14 @@ def state_dir() -> Path:
|
|
|
16
16
|
|
|
17
17
|
def resolve_scan_root(scan_root: str | None) -> Path:
|
|
18
18
|
return Path(scan_root).expanduser().resolve() if scan_root else state_dir() / "scans"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def create_private_directory(path: Path) -> None:
|
|
22
|
+
"""Create missing directories privately without changing existing permissions."""
|
|
23
|
+
try:
|
|
24
|
+
path.mkdir(mode=0o700, exist_ok=True)
|
|
25
|
+
except FileNotFoundError:
|
|
26
|
+
if path.parent == path:
|
|
27
|
+
raise
|
|
28
|
+
create_private_directory(path.parent)
|
|
29
|
+
path.mkdir(mode=0o700, exist_ok=True)
|
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
10
10
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
11
11
|
import deep_scan_workbench as deep_scan
|
|
12
|
-
|
|
12
|
+
from deep_scan_workbench import non_negative_int
|
|
13
13
|
from workbench_constants import (
|
|
14
14
|
DIFF_TARGET_KINDS,
|
|
15
15
|
EXPORT_FORMATS,
|
|
@@ -21,6 +21,7 @@ from workbench_constants import (
|
|
|
21
21
|
PHASE_PROGRESS_UNITS,
|
|
22
22
|
PHASES,
|
|
23
23
|
REMEDIATION_UPDATE_STATES,
|
|
24
|
+
positive_int,
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
|
|
@@ -340,7 +341,10 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
340
341
|
release_finding_remediation_claim.add_argument("--request-id", required=True)
|
|
341
342
|
release_finding_remediation_claim.add_argument("--action-token", required=True)
|
|
342
343
|
|
|
343
|
-
|
|
344
|
+
cancel_remediation = subparsers.add_parser("cancel-finding-remediation-request")
|
|
345
|
+
cancel_remediation.add_argument("--occurrence-id", required=True)
|
|
346
|
+
cancel_remediation.add_argument("--request-id", required=True)
|
|
347
|
+
cancel_remediation.add_argument("--action-token", required=True)
|
|
344
348
|
|
|
345
349
|
set_finding_remediation = subparsers.add_parser("set-finding-remediation")
|
|
346
350
|
set_finding_remediation.add_argument("--occurrence-id", required=True)
|
|
@@ -358,7 +362,11 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
358
362
|
|
|
359
363
|
export_findings = subparsers.add_parser("export-findings")
|
|
360
364
|
export_findings.add_argument("--scan-id", required=True)
|
|
361
|
-
export_findings.add_argument(
|
|
365
|
+
export_findings.add_argument(
|
|
366
|
+
"--artifact", choices=("findings", "threat-model"), default="findings"
|
|
367
|
+
)
|
|
368
|
+
export_findings.add_argument("--format", choices=(*EXPORT_FORMATS, "md"))
|
|
369
|
+
export_findings.add_argument("--validate-only", action="store_true")
|
|
362
370
|
|
|
363
371
|
for command in (
|
|
364
372
|
"inspect-linear-publication",
|
|
@@ -395,19 +403,5 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
395
403
|
return parser.parse_args(arguments)
|
|
396
404
|
|
|
397
405
|
|
|
398
|
-
def non_negative_int(value: str) -> int:
|
|
399
|
-
parsed = int(value)
|
|
400
|
-
if parsed < 0:
|
|
401
|
-
raise argparse.ArgumentTypeError("expected a non-negative integer")
|
|
402
|
-
return parsed
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
def positive_int(value: str) -> int:
|
|
406
|
-
parsed = int(value)
|
|
407
|
-
if parsed < 1:
|
|
408
|
-
raise argparse.ArgumentTypeError("expected a positive integer")
|
|
409
|
-
return parsed
|
|
410
|
-
|
|
411
|
-
|
|
412
406
|
if __name__ == "__main__":
|
|
413
407
|
parse_args(__doc__)
|
|
@@ -16,18 +16,7 @@ PHASE_PROGRESS_UNITS = (
|
|
|
16
16
|
FINDING_SEVERITIES = ("critical", "high", "medium", "low", "informational")
|
|
17
17
|
FINDING_STATUSES = ("open", "closed")
|
|
18
18
|
FINDING_CLOSE_REASONS = ("already_fixed", "wont_fix", "false_positive")
|
|
19
|
-
REMEDIATION_STATES = (
|
|
20
|
-
"idle",
|
|
21
|
-
"requested",
|
|
22
|
-
"generated",
|
|
23
|
-
"applied",
|
|
24
|
-
"verifying",
|
|
25
|
-
"verified",
|
|
26
|
-
"failed",
|
|
27
|
-
"superseded",
|
|
28
|
-
)
|
|
29
19
|
REMEDIATION_UPDATE_STATES = ("generated", "applied", "verifying", "verified", "failed")
|
|
30
|
-
REMEDIATION_PENDING_ACTIONS = ("generate", "apply", "verify")
|
|
31
20
|
EXPORT_FORMATS = ("csv", "json", "sarif")
|
|
32
21
|
ARTIFACTS = {
|
|
33
22
|
"coverage": "coverage.json",
|
|
@@ -70,9 +59,12 @@ GIT_REPOSITORY_ENVIRONMENT = (
|
|
|
70
59
|
EMPTY_GIT_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
|
71
60
|
|
|
72
61
|
|
|
73
|
-
def
|
|
74
|
-
|
|
62
|
+
def positive_int(value: str) -> int:
|
|
63
|
+
parsed = int(value)
|
|
64
|
+
if parsed < 1:
|
|
65
|
+
raise argparse.ArgumentTypeError("expected a positive integer")
|
|
66
|
+
return parsed
|
|
75
67
|
|
|
76
68
|
|
|
77
69
|
if __name__ == "__main__":
|
|
78
|
-
|
|
70
|
+
argparse.ArgumentParser(description=__doc__).parse_args()
|