@openai/codex-security 0.1.15 → 0.1.17
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 +204 -4
- package/_bundled_plugin/.app.json +1 -1
- package/_bundled_plugin/.mcp.json +9 -3
- 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/config-preflight.md +1 -1
- package/_bundled_plugin/references/sarif-adapter.md +5 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +34 -6
- package/_bundled_plugin/scripts/finalize_scan_contract.py +121 -32
- package/_bundled_plugin/scripts/generate_in_scope_files.py +20 -0
- package/_bundled_plugin/scripts/generate_rank_input.py +23 -7
- package/_bundled_plugin/scripts/launch_codex_security_mcp +32 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +27 -0
- package/_bundled_plugin/scripts/workbench_cli.py +22 -15
- package/_bundled_plugin/scripts/workbench_db.py +35 -35
- package/_bundled_plugin/scripts/workbench_progress.py +6 -3
- package/_bundled_plugin/scripts/workbench_scan_history.py +17 -2
- package/_bundled_plugin/scripts/workbench_target.py +36 -5
- package/_bundled_plugin/scripts/workbench_validation.py +9 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +17 -1
- package/_bundled_plugin/skills/verify-fix/SKILL.md +44 -0
- package/_bundled_plugin/skills/verify-fix/agents/openai.yaml +4 -0
- package/dist/api.d.ts +16 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +180 -11
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +12 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +781 -62
- package/dist/cli.js.map +1 -1
- package/dist/component-plan.d.ts +15 -0
- package/dist/component-plan.d.ts.map +1 -0
- package/dist/component-plan.js +145 -0
- package/dist/component-plan.js.map +1 -0
- package/dist/component-scan.d.ts +83 -0
- package/dist/component-scan.d.ts.map +1 -0
- package/dist/component-scan.js +279 -0
- package/dist/component-scan.js.map +1 -0
- package/dist/contract.d.ts +8 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +27 -8
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +20 -0
- package/dist/cost-model.d.ts.map +1 -0
- package/dist/cost-model.js +86 -0
- package/dist/cost-model.js.map +1 -0
- package/dist/cost.d.ts +2 -11
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -95
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +4 -0
- package/dist/custom-validation-prompt.d.ts.map +1 -0
- package/dist/custom-validation-prompt.js +94 -0
- package/dist/custom-validation-prompt.js.map +1 -0
- package/dist/custom-validation.d.ts +45 -0
- package/dist/custom-validation.d.ts.map +1 -0
- package/dist/custom-validation.js +292 -0
- package/dist/custom-validation.js.map +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/multiscan.d.ts +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +53 -5
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.js +1 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +3 -4
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +109 -38
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +12 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +72 -28
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +9 -2
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +205 -7
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -21
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts +4 -0
- package/dist/scan-sessions.d.ts.map +1 -0
- package/dist/scan-sessions.js +35 -0
- package/dist/scan-sessions.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +16 -1
- package/dist/targets.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -20
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts +3 -0
- package/dist/windows-path.d.ts.map +1 -0
- package/dist/windows-path.js +16 -0
- package/dist/windows-path.js.map +1 -0
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +12 -0
- package/dist/worker-progress.js.map +1 -1
- package/package.json +8 -2
|
@@ -51,6 +51,13 @@ SARIF_LEVELS = {
|
|
|
51
51
|
"low": "note",
|
|
52
52
|
"informational": "note",
|
|
53
53
|
}
|
|
54
|
+
SARIF_SECURITY_SCORES = {
|
|
55
|
+
"critical": 9.5,
|
|
56
|
+
"high": 8.0,
|
|
57
|
+
"medium": 5.0,
|
|
58
|
+
"low": 2.0,
|
|
59
|
+
"informational": 0.0,
|
|
60
|
+
}
|
|
54
61
|
SLUG_RE = re.compile(r"^[a-z0-9][a-z0-9._/-]*$")
|
|
55
62
|
RFC3339_RE = re.compile(
|
|
56
63
|
r"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$"
|
|
@@ -66,6 +73,10 @@ EXPORT_PATHS = {
|
|
|
66
73
|
"json": "exports/findings.json",
|
|
67
74
|
"sarif": "exports/results.sarif",
|
|
68
75
|
}
|
|
76
|
+
WINDOWS_UNSAFE_PATH_COMPONENT_RE = re.compile(
|
|
77
|
+
r'[<>:"|?*\x00-\x1f]|[ .]$|^(?:con|prn|aux|nul|conin\$|conout\$|com[1-9¹²³]|lpt[1-9¹²³])(?:\..*)?$',
|
|
78
|
+
re.IGNORECASE,
|
|
79
|
+
)
|
|
69
80
|
|
|
70
81
|
|
|
71
82
|
class ContractError(ValueError):
|
|
@@ -218,10 +229,12 @@ def _require_safe_relative_path(value: str, context: str, *, allow_dot: bool = F
|
|
|
218
229
|
path = PurePosixPath(value)
|
|
219
230
|
normalized = path.as_posix()
|
|
220
231
|
if (
|
|
221
|
-
not value
|
|
232
|
+
not value.strip()
|
|
222
233
|
or (normalized == "." and not allow_dot)
|
|
234
|
+
or (len(value) >= 2 and value[0].isalpha() and value[1] == ":")
|
|
223
235
|
or "\\" in value
|
|
224
236
|
or "\0" in value
|
|
237
|
+
or any(ord(character) < 32 for character in value)
|
|
225
238
|
or path.is_absolute()
|
|
226
239
|
or ".." in path.parts
|
|
227
240
|
):
|
|
@@ -229,6 +242,21 @@ def _require_safe_relative_path(value: str, context: str, *, allow_dot: bool = F
|
|
|
229
242
|
return normalized
|
|
230
243
|
|
|
231
244
|
|
|
245
|
+
def _require_portable_relative_path(
|
|
246
|
+
value: str, context: str, *, allow_dot: bool = False
|
|
247
|
+
) -> str:
|
|
248
|
+
normalized = _require_safe_relative_path(value, context, allow_dot=allow_dot)
|
|
249
|
+
if any(_windows_unsafe_path_component(part) for part in value.split("/")):
|
|
250
|
+
raise ContractError(f"{context}: expected a safe scan-relative POSIX path")
|
|
251
|
+
return normalized
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _windows_unsafe_path_component(value: str) -> bool:
|
|
255
|
+
if not value or value == ".":
|
|
256
|
+
return False
|
|
257
|
+
return WINDOWS_UNSAFE_PATH_COMPONENT_RE.search(value) is not None
|
|
258
|
+
|
|
259
|
+
|
|
232
260
|
def _require_scan_directory(scan_dir: Path) -> Path:
|
|
233
261
|
scan_dir = scan_dir.absolute()
|
|
234
262
|
try:
|
|
@@ -340,7 +368,7 @@ def _open_scan_local_directory(root_fd: int, parts: tuple[str, ...], *, create:
|
|
|
340
368
|
|
|
341
369
|
def open_scan_local_file_descriptor(scan_dir: Path, relative_path: str, context: str) -> int:
|
|
342
370
|
scan_dir = _require_scan_directory(scan_dir)
|
|
343
|
-
relative_path =
|
|
371
|
+
relative_path = _require_portable_relative_path(relative_path, context)
|
|
344
372
|
if not _descriptor_relative_reads_available():
|
|
345
373
|
if not _is_windows():
|
|
346
374
|
raise ContractError("scan-local input requires descriptor-relative file operations")
|
|
@@ -471,7 +499,7 @@ def write_scan_local_bytes(
|
|
|
471
499
|
if relative_path in {"", ".", ".."} or "/" in relative_path or "\0" in relative_path:
|
|
472
500
|
raise ContractError("external output path: expected a safe file name")
|
|
473
501
|
else:
|
|
474
|
-
relative_path =
|
|
502
|
+
relative_path = _require_portable_relative_path(relative_path, "scan-local output path")
|
|
475
503
|
path = scan_dir / relative_path
|
|
476
504
|
if not _descriptor_relative_writes_available():
|
|
477
505
|
if not _is_windows():
|
|
@@ -522,7 +550,7 @@ def write_scan_local_bytes(
|
|
|
522
550
|
|
|
523
551
|
def _remove_scan_local_file_if_exists(scan_dir: Path, relative_path: str) -> None:
|
|
524
552
|
scan_dir = _require_scan_directory(scan_dir)
|
|
525
|
-
relative_path =
|
|
553
|
+
relative_path = _require_portable_relative_path(relative_path, "scan-local cleanup path")
|
|
526
554
|
if not _descriptor_relative_writes_available():
|
|
527
555
|
if not _is_windows():
|
|
528
556
|
raise ContractError("scan-local cleanup requires descriptor-relative file operations")
|
|
@@ -929,7 +957,7 @@ def _recover_unsealed_coverage(
|
|
|
929
957
|
try:
|
|
930
958
|
if not isinstance(ref, str):
|
|
931
959
|
raise ContractError(f"{ref_context}: expected a string")
|
|
932
|
-
normalized_ref =
|
|
960
|
+
normalized_ref = _require_portable_relative_path(ref, ref_context)
|
|
933
961
|
if not normalized_ref.startswith("artifacts/"):
|
|
934
962
|
raise ContractError(
|
|
935
963
|
f"{ref_context}: expected a file under artifacts/"
|
|
@@ -1315,7 +1343,9 @@ def _validate_coverage(manifest: dict[str, Any], coverage: dict[str, Any], scan_
|
|
|
1315
1343
|
for ref_index, ref in enumerate(receipt_refs):
|
|
1316
1344
|
if not isinstance(ref, str):
|
|
1317
1345
|
raise ContractError(f"{context}.receiptRefs[{ref_index}]: expected a string")
|
|
1318
|
-
normalized_ref =
|
|
1346
|
+
normalized_ref = _require_portable_relative_path(
|
|
1347
|
+
ref, f"{context}.receiptRefs[{ref_index}]"
|
|
1348
|
+
)
|
|
1319
1349
|
if not normalized_ref.startswith("artifacts/"):
|
|
1320
1350
|
raise ContractError(
|
|
1321
1351
|
f"{context}.receiptRefs[{ref_index}]: expected a file under artifacts/"
|
|
@@ -1360,16 +1390,19 @@ def _validate_manifest(manifest: dict[str, Any]) -> None:
|
|
|
1360
1390
|
if not artifacts:
|
|
1361
1391
|
raise ContractError("manifest.scan.artifacts: expected generated artifact records")
|
|
1362
1392
|
artifact_paths: set[str] = set()
|
|
1393
|
+
artifact_collision_keys: set[str] = set()
|
|
1363
1394
|
for index, artifact in enumerate(artifacts):
|
|
1364
1395
|
context = f"manifest.scan.artifacts[{index}]"
|
|
1365
1396
|
if not isinstance(artifact, dict):
|
|
1366
1397
|
raise ContractError(f"{context}: expected an object")
|
|
1367
|
-
path =
|
|
1398
|
+
path = _require_portable_relative_path(
|
|
1368
1399
|
_require_str(artifact, "path", context), f"{context}.path"
|
|
1369
1400
|
)
|
|
1370
|
-
|
|
1401
|
+
collision_key = path.lower()
|
|
1402
|
+
if collision_key in artifact_collision_keys:
|
|
1371
1403
|
raise ContractError(f"{context}.path: duplicate artifact path")
|
|
1372
1404
|
artifact_paths.add(path)
|
|
1405
|
+
artifact_collision_keys.add(collision_key)
|
|
1373
1406
|
_require_str(artifact, "sha256", context)
|
|
1374
1407
|
_require_str(artifact, "mediaType", context)
|
|
1375
1408
|
for required_path in ("findings.json", "coverage.json"):
|
|
@@ -1586,6 +1619,7 @@ def _legacy_sealed_findings_for_validation(findings: dict[str, Any]) -> dict[str
|
|
|
1586
1619
|
and evidence["id"]
|
|
1587
1620
|
}
|
|
1588
1621
|
for section_name, list_fields in (
|
|
1622
|
+
("rootCause", ("evidenceRefs", "evidence_refs")),
|
|
1589
1623
|
("root_cause", ("evidenceRefs", "evidence_refs")),
|
|
1590
1624
|
(
|
|
1591
1625
|
"validation",
|
|
@@ -1701,15 +1735,67 @@ def _validate_contract_refs(scan: dict[str, Any]) -> None:
|
|
|
1701
1735
|
raise ContractError(f"manifest.scan.{field}: expected {expected!r}")
|
|
1702
1736
|
|
|
1703
1737
|
|
|
1704
|
-
def
|
|
1738
|
+
def _sarif_label(value: str) -> str:
|
|
1739
|
+
words = re.sub(r"[-_./]+", " ", value).split()
|
|
1740
|
+
acronyms = {"api", "csrf", "html", "http", "id", "rce", "sql", "ssrf", "url", "xml", "xss"}
|
|
1741
|
+
label = " ".join(word.upper() if word.lower() in acronyms else word for word in words)
|
|
1742
|
+
return label[:1].upper() + label[1:]
|
|
1743
|
+
|
|
1744
|
+
|
|
1745
|
+
def _sarif_rule(rule_id: str, findings: list[dict[str, Any]]) -> dict[str, Any]:
|
|
1746
|
+
name = ": ".join(_sarif_label(part) for part in rule_id.split("."))
|
|
1747
|
+
categories = sorted({finding["taxonomy"]["category"] for finding in findings})
|
|
1748
|
+
cwes = sorted({cwe for finding in findings for cwe in finding["taxonomy"]["cwe"]})
|
|
1749
|
+
tags = {"security", *categories}
|
|
1750
|
+
for cwe in cwes:
|
|
1751
|
+
match = re.fullmatch(r"CWE-([0-9]+)", cwe, re.IGNORECASE)
|
|
1752
|
+
if match and int(match[1]) > 0:
|
|
1753
|
+
tags.add(f"external/cwe/cwe-{int(match[1]):03d}")
|
|
1754
|
+
description = f"{name}. Categories: {', '.join(map(_sarif_label, categories))}."
|
|
1755
|
+
if cwes:
|
|
1756
|
+
description += f" Weaknesses: {', '.join(cwes)}."
|
|
1757
|
+
remediation = "\n\n".join(sorted({finding["remediation"] for finding in findings}))
|
|
1758
|
+
properties: dict[str, Any] = {"tags": sorted(tags)}
|
|
1759
|
+
# GitHub assigns security severity to the shared rule, not each result.
|
|
1760
|
+
score = max(
|
|
1761
|
+
finding["severity"].get("score", SARIF_SECURITY_SCORES[finding["severity"]["level"]])
|
|
1762
|
+
for finding in findings
|
|
1763
|
+
)
|
|
1764
|
+
if score > 0:
|
|
1765
|
+
properties["security-severity"] = str(score)
|
|
1705
1766
|
return {
|
|
1706
1767
|
"id": rule_id,
|
|
1707
|
-
"name":
|
|
1708
|
-
"shortDescription": {"text":
|
|
1709
|
-
"
|
|
1768
|
+
"name": name,
|
|
1769
|
+
"shortDescription": {"text": name},
|
|
1770
|
+
"fullDescription": {"text": description},
|
|
1771
|
+
"help": {
|
|
1772
|
+
"text": f"{description}\n\nRemediation:\n\n{remediation}",
|
|
1773
|
+
"markdown": f"{description}\n\n## Remediation\n\n{remediation}",
|
|
1774
|
+
},
|
|
1775
|
+
"properties": properties,
|
|
1710
1776
|
}
|
|
1711
1777
|
|
|
1712
1778
|
|
|
1779
|
+
def _sarif_finding_message(finding: dict[str, Any]) -> str:
|
|
1780
|
+
taxonomy = finding["taxonomy"]
|
|
1781
|
+
details = [
|
|
1782
|
+
finding["title"],
|
|
1783
|
+
finding["summary"],
|
|
1784
|
+
f"Severity: {finding['severity']['level']}",
|
|
1785
|
+
f"Category: {_sarif_label(taxonomy['category'])}",
|
|
1786
|
+
]
|
|
1787
|
+
if taxonomy["cwe"]:
|
|
1788
|
+
details.append(f"Weaknesses: {', '.join(taxonomy['cwe'])}")
|
|
1789
|
+
details.append(f"Remediation:\n{finding['remediation']}")
|
|
1790
|
+
for key, label in (
|
|
1791
|
+
("remediationTests", "Remediation tests"),
|
|
1792
|
+
("preventiveControls", "Preventive controls"),
|
|
1793
|
+
):
|
|
1794
|
+
if finding.get(key):
|
|
1795
|
+
details.append(f"{label}:\n" + "\n".join(f"- {item}" for item in finding[key]))
|
|
1796
|
+
return "\n\n".join(details)
|
|
1797
|
+
|
|
1798
|
+
|
|
1713
1799
|
def _utf16_code_units(value: str) -> Iterator[int]:
|
|
1714
1800
|
encoded = value.encode("utf-16-le")
|
|
1715
1801
|
for index in range(0, len(encoded), 2):
|
|
@@ -2013,7 +2099,7 @@ def _sarif_result(
|
|
|
2013
2099
|
"ruleId": finding["ruleId"],
|
|
2014
2100
|
"ruleIndex": rule_index,
|
|
2015
2101
|
"level": SARIF_LEVELS[finding["severity"]["level"]],
|
|
2016
|
-
"message": {"text": finding
|
|
2102
|
+
"message": {"text": _sarif_finding_message(finding)},
|
|
2017
2103
|
"locations": [_sarif_location(location) for location in _sarif_locations(finding)],
|
|
2018
2104
|
"partialFingerprints": partial_fingerprints,
|
|
2019
2105
|
"properties": properties,
|
|
@@ -2038,7 +2124,9 @@ def build_sarif(
|
|
|
2038
2124
|
"driver": {
|
|
2039
2125
|
"name": "Codex Security",
|
|
2040
2126
|
"version": scan["producer"]["version"],
|
|
2041
|
-
"rules": [
|
|
2127
|
+
"rules": [
|
|
2128
|
+
_sarif_rule(rule_id, findings_by_rule[rule_id]) for rule_id in ordered_rule_ids
|
|
2129
|
+
],
|
|
2042
2130
|
}
|
|
2043
2131
|
},
|
|
2044
2132
|
"automationDetails": {"id": scan["id"]},
|
|
@@ -2085,7 +2173,7 @@ def _validate_sarif(sarif: dict[str, Any]) -> None:
|
|
|
2085
2173
|
def _artifact_record(
|
|
2086
2174
|
scan_dir: Path, relative_path: str, media_type: str, contents: bytes | None = None
|
|
2087
2175
|
) -> dict[str, str]:
|
|
2088
|
-
relative_path =
|
|
2176
|
+
relative_path = _require_portable_relative_path(relative_path, "artifact path")
|
|
2089
2177
|
if contents is not None:
|
|
2090
2178
|
_require_scan_local_file(scan_dir, relative_path, relative_path)
|
|
2091
2179
|
return {
|
|
@@ -2106,7 +2194,7 @@ def _coverage_receipt_refs(coverage: dict[str, Any]) -> list[str]:
|
|
|
2106
2194
|
|
|
2107
2195
|
def _validate_sealed_coverage_receipts(scan: dict[str, Any], coverage: dict[str, Any]) -> None:
|
|
2108
2196
|
artifact_paths = {
|
|
2109
|
-
|
|
2197
|
+
_require_portable_relative_path(artifact["path"], "sealed artifact path")
|
|
2110
2198
|
for artifact in scan["artifacts"]
|
|
2111
2199
|
}
|
|
2112
2200
|
for ref in _coverage_receipt_refs(coverage):
|
|
@@ -2129,16 +2217,19 @@ def _validate_existing_seal(
|
|
|
2129
2217
|
if not isinstance(artifacts, list) or not artifacts:
|
|
2130
2218
|
raise ContractError("manifest.scan.artifacts: sealed manifest requires artifact records")
|
|
2131
2219
|
artifact_paths: set[str] = set()
|
|
2220
|
+
artifact_collision_keys: set[str] = set()
|
|
2132
2221
|
for index, artifact in enumerate(artifacts):
|
|
2133
2222
|
context = f"manifest.scan.artifacts[{index}]"
|
|
2134
2223
|
if not isinstance(artifact, dict):
|
|
2135
2224
|
raise ContractError(f"{context}: expected an object")
|
|
2136
|
-
path =
|
|
2225
|
+
path = _require_portable_relative_path(
|
|
2137
2226
|
_require_str(artifact, "path", context), f"{context}.path"
|
|
2138
2227
|
)
|
|
2139
|
-
|
|
2228
|
+
collision_key = path.lower()
|
|
2229
|
+
if collision_key in artifact_collision_keys:
|
|
2140
2230
|
raise ContractError(f"{context}.path: duplicate artifact path")
|
|
2141
2231
|
artifact_paths.add(path)
|
|
2232
|
+
artifact_collision_keys.add(collision_key)
|
|
2142
2233
|
expected_sha256 = _require_str(artifact, "sha256", context)
|
|
2143
2234
|
contents = (artifact_contents or {}).get(path)
|
|
2144
2235
|
actual_sha256 = (
|
|
@@ -2199,19 +2290,17 @@ def build_sarif_projection(
|
|
|
2199
2290
|
raise ContractError("source root: expected an existing directory")
|
|
2200
2291
|
manifest, findings, coverage, _ = _read_sealed_scan(scan_dir, schema_dir, "SARIF projection")
|
|
2201
2292
|
sarif = build_sarif(manifest, findings, source_root)
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
}
|
|
2214
|
-
]
|
|
2293
|
+
run = sarif["runs"][0]
|
|
2294
|
+
completeness = coverage["completeness"]
|
|
2295
|
+
run["invocations"] = [{"executionSuccessful": completeness == "complete"}]
|
|
2296
|
+
if completeness != "complete":
|
|
2297
|
+
run["properties"]["codexSecurityCoverageCompleteness"] = completeness
|
|
2298
|
+
reasons = [item["reason"] for item in coverage["deferred"]] or [
|
|
2299
|
+
f"Scan coverage is {completeness}; results may be incomplete."
|
|
2300
|
+
]
|
|
2301
|
+
run["invocations"][0]["toolExecutionNotifications"] = [
|
|
2302
|
+
{"level": "warning", "message": {"text": reason}} for reason in reasons
|
|
2303
|
+
]
|
|
2215
2304
|
_validate_sarif(sarif)
|
|
2216
2305
|
return sarif
|
|
2217
2306
|
|
|
@@ -2363,7 +2452,7 @@ def write_export_output(scan_dir: Path, output: Path, export_format: str, conten
|
|
|
2363
2452
|
scan = _require_dict(manifest, "scan", "manifest")
|
|
2364
2453
|
artifacts = _require_list(scan, "artifacts", "manifest.scan")
|
|
2365
2454
|
artifact_paths = [
|
|
2366
|
-
|
|
2455
|
+
_require_portable_relative_path(
|
|
2367
2456
|
_require_str(artifact, "path", f"manifest.scan.artifacts[{index}]"),
|
|
2368
2457
|
f"manifest.scan.artifacts[{index}].path",
|
|
2369
2458
|
)
|
|
@@ -15,6 +15,21 @@ class InventoryError(ValueError):
|
|
|
15
15
|
"""Raised when the repository, scope, or inventory cannot be used safely."""
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
def windows_stream_component(path: Path) -> str | None:
|
|
19
|
+
"""Return the first NTFS alternate-data-stream component."""
|
|
20
|
+
|
|
21
|
+
if os.name != "nt":
|
|
22
|
+
return None
|
|
23
|
+
return next(
|
|
24
|
+
(
|
|
25
|
+
component
|
|
26
|
+
for component in path.parts
|
|
27
|
+
if component != path.anchor and ":" in component
|
|
28
|
+
),
|
|
29
|
+
None,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
18
33
|
def resolve_repository(value: str) -> Path:
|
|
19
34
|
"""Resolve the repository once so every scope is bound to its real root."""
|
|
20
35
|
try:
|
|
@@ -32,6 +47,11 @@ def resolve_scope(repository: Path, value: str) -> str:
|
|
|
32
47
|
raise InventoryError("--scope: expected a non-empty file or directory")
|
|
33
48
|
|
|
34
49
|
requested = Path(value).expanduser()
|
|
50
|
+
stream = windows_stream_component(requested)
|
|
51
|
+
if stream is not None:
|
|
52
|
+
raise InventoryError(
|
|
53
|
+
f"--scope: NTFS alternate data streams are not supported: {stream}"
|
|
54
|
+
)
|
|
35
55
|
scope = requested if requested.is_absolute() else repository / requested
|
|
36
56
|
try:
|
|
37
57
|
resolved = scope.resolve(strict=True)
|
|
@@ -293,6 +293,21 @@ def path_is_excluded(path: Path) -> bool:
|
|
|
293
293
|
return path.name.endswith((".min.js", ".map"))
|
|
294
294
|
|
|
295
295
|
|
|
296
|
+
def windows_stream_component(path: Path) -> str | None:
|
|
297
|
+
"""Return the first NTFS alternate-data-stream component."""
|
|
298
|
+
|
|
299
|
+
if os.name != "nt":
|
|
300
|
+
return None
|
|
301
|
+
return next(
|
|
302
|
+
(
|
|
303
|
+
component
|
|
304
|
+
for component in path.parts
|
|
305
|
+
if component != path.anchor and ":" in component
|
|
306
|
+
),
|
|
307
|
+
None,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
|
|
296
311
|
def resolve_scope(
|
|
297
312
|
repo: Path,
|
|
298
313
|
scope: str,
|
|
@@ -301,6 +316,9 @@ def resolve_scope(
|
|
|
301
316
|
reject_symlinks: bool = False,
|
|
302
317
|
) -> Path:
|
|
303
318
|
scope_path = Path(scope).expanduser() if expand_user else Path(scope)
|
|
319
|
+
stream = windows_stream_component(scope_path)
|
|
320
|
+
if stream is not None:
|
|
321
|
+
raise SystemExit(f"Scope must not use an NTFS alternate data stream: {stream}")
|
|
304
322
|
if not scope_path.is_absolute():
|
|
305
323
|
scope_path = repo / scope_path
|
|
306
324
|
if reject_symlinks:
|
|
@@ -621,20 +639,19 @@ def run_git_changed_paths(repo: Path, diff_args: list[str]) -> list[tuple[Path,
|
|
|
621
639
|
],
|
|
622
640
|
check=True,
|
|
623
641
|
capture_output=True,
|
|
624
|
-
text=True,
|
|
625
642
|
)
|
|
626
|
-
fields = result.stdout.split("\0")
|
|
643
|
+
fields = result.stdout.split(b"\0")
|
|
627
644
|
if fields and not fields[-1]:
|
|
628
645
|
fields.pop()
|
|
629
646
|
|
|
630
647
|
changed: list[tuple[Path, str]] = []
|
|
631
648
|
index = 0
|
|
632
649
|
while index < len(fields):
|
|
633
|
-
status = fields[index][0]
|
|
650
|
+
status = chr(fields[index][0])
|
|
634
651
|
index += 1
|
|
635
652
|
if status in {"C", "R"}:
|
|
636
653
|
index += 1
|
|
637
|
-
path = repo / fields[index]
|
|
654
|
+
path = repo / os.fsdecode(fields[index])
|
|
638
655
|
index += 1
|
|
639
656
|
changed.append((path, status))
|
|
640
657
|
return changed
|
|
@@ -649,14 +666,13 @@ def git_changed_paths(repo: Path, base: str, head: str, mode: str) -> list[tuple
|
|
|
649
666
|
untracked = subprocess.run(
|
|
650
667
|
["git", "-C", str(repo), "ls-files", "--others", "--exclude-standard", "-z"],
|
|
651
668
|
capture_output=True,
|
|
652
|
-
text=True,
|
|
653
669
|
check=True,
|
|
654
670
|
)
|
|
655
671
|
combined = dict(staged)
|
|
656
672
|
combined.update(unstaged)
|
|
657
673
|
combined.update(
|
|
658
|
-
(repo / relative, "A")
|
|
659
|
-
for relative in untracked.stdout.split("\0")
|
|
674
|
+
(repo / os.fsdecode(relative), "A")
|
|
675
|
+
for relative in untracked.stdout.split(b"\0")
|
|
660
676
|
if relative
|
|
661
677
|
)
|
|
662
678
|
return sorted(combined.items())
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
|
|
4
|
+
PATH="${PATH:-/usr/bin:/bin}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
5
|
+
export PATH
|
|
6
|
+
|
|
7
|
+
launcher_dir=$(CDPATH= cd "$(dirname "$0")" && pwd)
|
|
8
|
+
server_path=$launcher_dir/../mcp/server.mjs
|
|
9
|
+
cache_root=${XDG_CACHE_HOME:-${HOME:-}/.cache}
|
|
10
|
+
codex_resources=
|
|
11
|
+
case "${CODEX_CLI_PATH:-}" in
|
|
12
|
+
*/*) codex_resources=${CODEX_CLI_PATH%/*} ;;
|
|
13
|
+
esac
|
|
14
|
+
|
|
15
|
+
for candidate in \
|
|
16
|
+
"${CODEX_MCP_NODE_PATH:-}" \
|
|
17
|
+
"${CODEX_BROWSER_USE_NODE_PATH:-}" \
|
|
18
|
+
"${CODEX_ELECTRON_RESOURCES_PATH:-}/cua_node/bin/node" \
|
|
19
|
+
"$codex_resources/cua_node/bin/node" \
|
|
20
|
+
"$cache_root/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node"
|
|
21
|
+
do
|
|
22
|
+
if [ -n "$candidate" ] && [ -x "$candidate" ]; then
|
|
23
|
+
exec "$candidate" "$server_path" "$@"
|
|
24
|
+
fi
|
|
25
|
+
done
|
|
26
|
+
|
|
27
|
+
if command -v node >/dev/null 2>&1; then
|
|
28
|
+
exec node "$server_path" "$@"
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
printf '%s\n' 'Codex Security could not find a Node runtime. Reinstall or update Codex, or set CODEX_MCP_NODE_PATH to an executable Node runtime.' >&2
|
|
32
|
+
exit 127
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal DisableDelayedExpansion
|
|
3
|
+
|
|
4
|
+
set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\server.mjs"
|
|
5
|
+
|
|
6
|
+
rem This process waits for Node and must not keep the installed plugin directory locked.
|
|
7
|
+
if "%~d0"=="" (cd /d "%SystemRoot%") else (cd /d "%~d0\")
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo Codex Security could not start: no safe Windows working directory. 1>&2
|
|
10
|
+
exit /b 1
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
rem WindowsApps can expose a Node path that exists but cannot be executed.
|
|
14
|
+
rem Prefer relocated user-writable runtimes before probing packaged paths.
|
|
15
|
+
if defined LOCALAPPDATA for /d %%D in ("%LOCALAPPDATA%\OpenAI\Codex\runtimes\cua_node\*") do if exist "%%~fD\bin\node.exe" ("%%~fD\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
16
|
+
if defined XDG_CACHE_HOME if exist "%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" ("%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
17
|
+
if defined USERPROFILE if exist "%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" ("%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
18
|
+
if defined CODEX_MCP_NODE_PATH if exist "%CODEX_MCP_NODE_PATH%" ("%CODEX_MCP_NODE_PATH%" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
19
|
+
if defined CODEX_BROWSER_USE_NODE_PATH if exist "%CODEX_BROWSER_USE_NODE_PATH%" ("%CODEX_BROWSER_USE_NODE_PATH%" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
20
|
+
if defined CODEX_ELECTRON_RESOURCES_PATH if exist "%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe" ("%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
21
|
+
if defined CODEX_CLI_PATH for %%I in ("%CODEX_CLI_PATH%") do if exist "%%~dpIcua_node\bin\node.exe" ("%%~dpIcua_node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
22
|
+
|
|
23
|
+
where node >nul 2>&1
|
|
24
|
+
if not errorlevel 1 (node "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
25
|
+
|
|
26
|
+
echo Codex Security could not find a Node runtime. Reinstall or update Codex, or set CODEX_MCP_NODE_PATH to an executable Node runtime. 1>&2
|
|
27
|
+
exit /b 127
|
|
@@ -24,6 +24,12 @@ from workbench_constants import (
|
|
|
24
24
|
)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
def add_user_context(parser: argparse.ArgumentParser, *, required: bool = False) -> None:
|
|
28
|
+
context = parser.add_mutually_exclusive_group(required=required)
|
|
29
|
+
context.add_argument("--user-context")
|
|
30
|
+
context.add_argument("--user-context-stdin", action="store_true")
|
|
31
|
+
|
|
32
|
+
|
|
27
33
|
def parse_args(description: str) -> argparse.Namespace:
|
|
28
34
|
parser = argparse.ArgumentParser(description=description)
|
|
29
35
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
@@ -34,7 +40,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
34
40
|
create_workspace.add_argument("--target-path")
|
|
35
41
|
create_workspace.add_argument("--target-title")
|
|
36
42
|
create_workspace.add_argument("--target-summary")
|
|
37
|
-
create_workspace
|
|
43
|
+
add_user_context(create_workspace)
|
|
38
44
|
create_workspace.add_argument("--scope")
|
|
39
45
|
create_workspace.add_argument("--mode", choices=MODES, default="standard")
|
|
40
46
|
create_workspace.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
@@ -64,7 +70,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
64
70
|
save_workspace.add_argument("--scope", required=True)
|
|
65
71
|
save_workspace.add_argument("--mode", choices=MODES, required=True)
|
|
66
72
|
save_workspace.add_argument("--target-summary")
|
|
67
|
-
save_workspace
|
|
73
|
+
add_user_context(save_workspace)
|
|
68
74
|
save_workspace.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
69
75
|
save_workspace.add_argument("--diff-base-revision")
|
|
70
76
|
save_workspace.add_argument("--diff-head-revision")
|
|
@@ -82,7 +88,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
82
88
|
start_prompt_only_scan.add_argument("--scope", required=True)
|
|
83
89
|
start_prompt_only_scan.add_argument("--mode", choices=("diff", "standard"), required=True)
|
|
84
90
|
start_prompt_only_scan.add_argument("--target-summary")
|
|
85
|
-
start_prompt_only_scan
|
|
91
|
+
add_user_context(start_prompt_only_scan)
|
|
86
92
|
start_prompt_only_scan.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
87
93
|
start_prompt_only_scan.add_argument("--diff-base-revision")
|
|
88
94
|
start_prompt_only_scan.add_argument("--diff-head-revision")
|
|
@@ -96,7 +102,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
96
102
|
start_headless_standard_scan.add_argument("--target-path", required=True)
|
|
97
103
|
start_headless_standard_scan.add_argument("--scope", required=True)
|
|
98
104
|
start_headless_standard_scan.add_argument("--target-summary")
|
|
99
|
-
start_headless_standard_scan
|
|
105
|
+
add_user_context(start_headless_standard_scan)
|
|
100
106
|
start_headless_standard_scan.add_argument("--scan-root")
|
|
101
107
|
start_headless_standard_scan.add_argument("--model")
|
|
102
108
|
start_headless_standard_scan.add_argument("--reasoning-effort")
|
|
@@ -119,7 +125,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
119
125
|
|
|
120
126
|
update_scan_context = subparsers.add_parser("update-scan-context")
|
|
121
127
|
update_scan_context.add_argument("--scan-id", required=True)
|
|
122
|
-
update_scan_context
|
|
128
|
+
add_user_context(update_scan_context, required=True)
|
|
123
129
|
update_scan_context_owner = update_scan_context.add_mutually_exclusive_group(required=True)
|
|
124
130
|
update_scan_context_owner.add_argument("--workspace-id")
|
|
125
131
|
update_scan_context_owner.add_argument("--thread-id")
|
|
@@ -142,7 +148,10 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
142
148
|
register_cli_scan = subparsers.add_parser("register-cli-scan")
|
|
143
149
|
register_cli_scan.add_argument("--scan-dir", required=True)
|
|
144
150
|
register_cli_scan.add_argument("--repository", required=True)
|
|
145
|
-
register_cli_scan.
|
|
151
|
+
recipe = register_cli_scan.add_mutually_exclusive_group(required=True)
|
|
152
|
+
recipe.add_argument("--recipe-json")
|
|
153
|
+
recipe.add_argument("--recipe-json-stdin", action="store_true")
|
|
154
|
+
recipe.add_argument("--registration-json-stdin", action="store_true")
|
|
146
155
|
register_cli_scan.add_argument("--parent-scan-id")
|
|
147
156
|
register_cli_scan.add_argument("--archive-existing", action="store_true")
|
|
148
157
|
register_cli_scan.add_argument("--archived-scan-dir")
|
|
@@ -163,7 +172,9 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
163
172
|
save_scan_comparison = subparsers.add_parser("save-scan-comparison")
|
|
164
173
|
save_scan_comparison.add_argument("--before-scan-id", required=True)
|
|
165
174
|
save_scan_comparison.add_argument("--after-scan-id", required=True)
|
|
166
|
-
save_scan_comparison.
|
|
175
|
+
matches = save_scan_comparison.add_mutually_exclusive_group(required=True)
|
|
176
|
+
matches.add_argument("--matches-json")
|
|
177
|
+
matches.add_argument("--matches-json-stdin", action="store_true")
|
|
167
178
|
|
|
168
179
|
list_global_findings = subparsers.add_parser("list-global-findings")
|
|
169
180
|
list_global_findings.add_argument("--query")
|
|
@@ -193,7 +204,9 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
193
204
|
update_progress.add_argument("--phase-items-total", type=non_negative_int)
|
|
194
205
|
update_progress.add_argument("--phase-items-completed", type=non_negative_int)
|
|
195
206
|
update_progress.add_argument("--phase-progress-unit", choices=PHASE_PROGRESS_UNITS)
|
|
196
|
-
update_progress.
|
|
207
|
+
preflight_issues = update_progress.add_mutually_exclusive_group()
|
|
208
|
+
preflight_issues.add_argument("--preflight-issues-json")
|
|
209
|
+
preflight_issues.add_argument("--preflight-issues-json-stdin", action="store_true")
|
|
197
210
|
update_progress.add_argument("--review-items-total", type=non_negative_int)
|
|
198
211
|
update_progress.add_argument("--review-items-completed", type=non_negative_int)
|
|
199
212
|
update_progress.add_argument("--reportable-findings-count", type=non_negative_int)
|
|
@@ -309,13 +322,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
309
322
|
publication.add_argument("--input-file", required=True)
|
|
310
323
|
|
|
311
324
|
subparsers.add_parser("database-info")
|
|
312
|
-
|
|
313
|
-
if "--user-context-stdin" in arguments:
|
|
314
|
-
if arguments.count("--user-context-stdin") != 1 or "--user-context" in arguments:
|
|
315
|
-
parser.error("pass exactly one user-context transport")
|
|
316
|
-
index = arguments.index("--user-context-stdin")
|
|
317
|
-
arguments[index : index + 1] = ["--user-context", sys.stdin.read()]
|
|
318
|
-
return parser.parse_args(arguments)
|
|
325
|
+
return parser.parse_args()
|
|
319
326
|
|
|
320
327
|
|
|
321
328
|
def non_negative_int(value: str) -> int:
|