@openai/codex-security 0.1.13 → 0.1.15
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 +90 -29
- package/_bundled_plugin/.app.json +5 -0
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/examples/completed-scan/report.md +96 -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/config-preflight.md +5 -1
- package/_bundled_plugin/references/core-scan.md +6 -15
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/scan-artifacts.md +1 -1
- package/_bundled_plugin/references/threat-model.md +64 -0
- package/_bundled_plugin/schemas/findings.schema.json +327 -2
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +286 -4
- package/_bundled_plugin/scripts/config_preflight.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +12 -6
- package/_bundled_plugin/scripts/finalize_scan_contract.py +322 -33
- package/_bundled_plugin/scripts/finding_preview.py +81 -19
- package/_bundled_plugin/scripts/report_projection.py +253 -33
- package/_bundled_plugin/scripts/validate_scan_contract.py +5 -2
- package/_bundled_plugin/scripts/workbench_cli.py +7 -1
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +4 -0
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +6 -49
- package/dist/api.d.ts +5 -73
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +266 -211
- package/dist/api.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +3 -3
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -7
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +18 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +785 -121
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +4 -0
- package/dist/codex-prompt.d.ts.map +1 -0
- package/dist/codex-prompt.js +14 -0
- package/dist/codex-prompt.js.map +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -1
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +198 -2
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts +7 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +68 -47
- package/dist/cost.js.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linear.d.ts +19 -0
- package/dist/linear.d.ts.map +1 -0
- package/dist/linear.js +106 -0
- package/dist/linear.js.map +1 -0
- package/dist/models.d.ts +89 -2
- 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 +7 -6
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.d.ts +28 -0
- package/dist/patch-tui.d.ts.map +1 -0
- package/dist/patch-tui.js +384 -0
- package/dist/patch-tui.js.map +1 -0
- package/dist/publish.d.ts +2 -2
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +4 -8
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +10 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +63 -35
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +2 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +17 -15
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +2 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +219 -11
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/targets.d.ts +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +4 -2
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +26 -11
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +7 -3
- package/_bundled_plugin/skills/threat-model/references/threat-model-guidance.md +0 -48
|
@@ -4,11 +4,13 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
6
6
|
import json
|
|
7
|
+
import re
|
|
7
8
|
import sys
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
from typing import Any
|
|
10
11
|
|
|
11
12
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
13
|
+
from report_projection import merged_root_cause
|
|
12
14
|
from workbench_constants import (
|
|
13
15
|
FINDING_ATTACK_PATH_PREVIEW_BYTES,
|
|
14
16
|
FINDING_CODE_EVIDENCE_LIMIT,
|
|
@@ -61,6 +63,7 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
61
63
|
"evidence_refs",
|
|
62
64
|
"assertions",
|
|
63
65
|
"evidence",
|
|
66
|
+
"counterEvidence",
|
|
64
67
|
"limitations",
|
|
65
68
|
),
|
|
66
69
|
(
|
|
@@ -70,6 +73,7 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
70
73
|
(("evidenceRefs", "evidence_refs"), 400),
|
|
71
74
|
(("assertions",), 400),
|
|
72
75
|
(("evidence",), 400),
|
|
76
|
+
(("counterEvidence",), 400),
|
|
73
77
|
(("limitations",), 400),
|
|
74
78
|
),
|
|
75
79
|
),
|
|
@@ -109,14 +113,27 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
109
113
|
),
|
|
110
114
|
),
|
|
111
115
|
):
|
|
112
|
-
|
|
116
|
+
if aliases == ("rootCause", "root_cause"):
|
|
117
|
+
key, section = merged_root_cause(value)
|
|
118
|
+
else:
|
|
119
|
+
key = next((alias for alias in aliases if alias in value), None)
|
|
120
|
+
section = value[key] if key is not None else None
|
|
113
121
|
if key is not None:
|
|
114
|
-
section = value[key]
|
|
115
122
|
if key == "attackPath" and isinstance(section, dict):
|
|
116
123
|
section = dict(section)
|
|
117
124
|
for assessment in ("impact", "likelihood"):
|
|
118
125
|
if isinstance(section.get(assessment), str):
|
|
119
|
-
|
|
126
|
+
assessment_value = section[assessment]
|
|
127
|
+
assessment_key = (
|
|
128
|
+
"level"
|
|
129
|
+
if re.fullmatch(
|
|
130
|
+
r"critical|high|medium|low|informational|ignore|unknown",
|
|
131
|
+
assessment_value,
|
|
132
|
+
flags=re.IGNORECASE,
|
|
133
|
+
)
|
|
134
|
+
else "rationale"
|
|
135
|
+
)
|
|
136
|
+
section[assessment] = {assessment_key: assessment_value}
|
|
120
137
|
prepared[key] = bounded_finding_section(
|
|
121
138
|
section,
|
|
122
139
|
maximum_bytes,
|
|
@@ -128,12 +145,9 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
128
145
|
if isinstance(writeup, dict) and isinstance(writeup.get("reportPath"), str):
|
|
129
146
|
prepared["writeup"] = {"reportPath": bounded_json_text(writeup["reportPath"], 512)[0]}
|
|
130
147
|
|
|
131
|
-
evidence_key =
|
|
132
|
-
(key for key in ("codeEvidence", "code_evidence") if key in value),
|
|
133
|
-
None,
|
|
134
|
-
)
|
|
148
|
+
evidence_key, evidence = merged_code_evidence(value)
|
|
135
149
|
if evidence_key is not None:
|
|
136
|
-
prepared[evidence_key] = bounded_code_evidence(
|
|
150
|
+
prepared[evidence_key] = bounded_code_evidence(evidence)
|
|
137
151
|
|
|
138
152
|
for key in (
|
|
139
153
|
"confidence",
|
|
@@ -185,9 +199,7 @@ def bounded_finding_details(value: Any) -> dict[str, Any]:
|
|
|
185
199
|
)
|
|
186
200
|
core = {key: prepared[key] for key in core_keys if key in prepared}
|
|
187
201
|
extras = {
|
|
188
|
-
key: item
|
|
189
|
-
for key, item in prepared.items()
|
|
190
|
-
if key not in core and key not in guidance
|
|
202
|
+
key: item for key, item in prepared.items() if key not in core and key not in guidance
|
|
191
203
|
}
|
|
192
204
|
complete_guidance = {key: items[:1] for key, items in guidance.items()}
|
|
193
205
|
minimum_guidance = {
|
|
@@ -233,25 +245,75 @@ def bounded_finding_section(
|
|
|
233
245
|
for key in (*priority_keys, *value):
|
|
234
246
|
if key in value and key not in ordered:
|
|
235
247
|
ordered[key] = value[key]
|
|
236
|
-
evidence_key =
|
|
237
|
-
(key for key in ("codeEvidence", "code_evidence") if key in ordered),
|
|
238
|
-
None,
|
|
239
|
-
)
|
|
248
|
+
evidence_key, evidence = merged_code_evidence(ordered)
|
|
240
249
|
if evidence_key is not None:
|
|
241
|
-
ordered[evidence_key] = bounded_code_evidence(
|
|
250
|
+
ordered[evidence_key] = bounded_code_evidence(evidence)
|
|
242
251
|
ordered.pop("code_evidence" if evidence_key == "codeEvidence" else "codeEvidence", None)
|
|
243
252
|
return bounded_json_value(ordered, [maximum_bytes])
|
|
244
253
|
|
|
245
254
|
|
|
255
|
+
def merged_code_evidence(value: dict[str, Any]) -> tuple[str | None, Any]:
|
|
256
|
+
evidence_keys = [key for key in ("codeEvidence", "code_evidence") if key in value]
|
|
257
|
+
if not evidence_keys:
|
|
258
|
+
return None, None
|
|
259
|
+
catalogs = [value[key] for key in evidence_keys if isinstance(value[key], list)]
|
|
260
|
+
if catalogs:
|
|
261
|
+
merged = []
|
|
262
|
+
seen_ids: set[str] = set()
|
|
263
|
+
for catalog in catalogs:
|
|
264
|
+
for item in catalog:
|
|
265
|
+
if not _is_valid_code_evidence(item):
|
|
266
|
+
continue
|
|
267
|
+
evidence_id = item["id"]
|
|
268
|
+
if evidence_id in seen_ids:
|
|
269
|
+
continue
|
|
270
|
+
seen_ids.add(evidence_id)
|
|
271
|
+
merged.append(item)
|
|
272
|
+
return evidence_keys[0], merged
|
|
273
|
+
return evidence_keys[0], value[evidence_keys[0]]
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _is_valid_code_evidence(item: Any) -> bool:
|
|
277
|
+
return (
|
|
278
|
+
isinstance(item, dict)
|
|
279
|
+
and isinstance(item.get("id"), str)
|
|
280
|
+
and bool(item["id"].strip())
|
|
281
|
+
and isinstance(item.get("code"), str)
|
|
282
|
+
and bool(item["code"].strip())
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
|
|
246
286
|
def bounded_code_evidence(value: Any) -> Any:
|
|
247
287
|
if not isinstance(value, list):
|
|
248
288
|
return value
|
|
249
289
|
bounded = []
|
|
250
|
-
for item in value
|
|
251
|
-
if not
|
|
252
|
-
bounded.append(item)
|
|
290
|
+
for item in value:
|
|
291
|
+
if not _is_valid_code_evidence(item):
|
|
253
292
|
continue
|
|
293
|
+
if len(bounded) >= FINDING_CODE_EVIDENCE_LIMIT:
|
|
294
|
+
break
|
|
254
295
|
evidence = dict(item)
|
|
296
|
+
for field in ("explanation", "label", "language", "path"):
|
|
297
|
+
if field in evidence and not isinstance(evidence[field], str):
|
|
298
|
+
evidence.pop(field)
|
|
299
|
+
if (
|
|
300
|
+
"role" in evidence
|
|
301
|
+
and evidence["role"] is not None
|
|
302
|
+
and not isinstance(evidence["role"], str)
|
|
303
|
+
):
|
|
304
|
+
evidence.pop("role")
|
|
305
|
+
start_line = evidence.get("startLine")
|
|
306
|
+
if "startLine" in evidence and (
|
|
307
|
+
not isinstance(start_line, int) or isinstance(start_line, bool) or start_line < 1
|
|
308
|
+
):
|
|
309
|
+
evidence.pop("startLine")
|
|
310
|
+
end_line = evidence.get("endLine")
|
|
311
|
+
if (
|
|
312
|
+
"endLine" in evidence
|
|
313
|
+
and end_line is not None
|
|
314
|
+
and (not isinstance(end_line, int) or isinstance(end_line, bool) or end_line < 1)
|
|
315
|
+
):
|
|
316
|
+
evidence.pop("endLine")
|
|
255
317
|
code = evidence.get("code")
|
|
256
318
|
if isinstance(code, str):
|
|
257
319
|
evidence["code"] = bounded_json_text(
|
|
@@ -47,6 +47,8 @@ def _escape_markdown_text(value: str) -> str:
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
def _strings(value: Any) -> list[str]:
|
|
50
|
+
if isinstance(value, str):
|
|
51
|
+
value = [value]
|
|
50
52
|
if not isinstance(value, list):
|
|
51
53
|
return []
|
|
52
54
|
normalized: list[str] = []
|
|
@@ -240,36 +242,46 @@ def _bullets(items: list[str], fallback: str) -> list[str]:
|
|
|
240
242
|
|
|
241
243
|
|
|
242
244
|
def _code_evidence_catalog(finding: dict[str, Any]) -> dict[str, dict[str, Any]]:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
for item in raw
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
245
|
+
catalog: dict[str, dict[str, Any]] = {}
|
|
246
|
+
for key in ("codeEvidence", "code_evidence"):
|
|
247
|
+
raw = finding.get(key, [])
|
|
248
|
+
if not isinstance(raw, list):
|
|
249
|
+
continue
|
|
250
|
+
for item in raw:
|
|
251
|
+
if (
|
|
252
|
+
isinstance(item, dict)
|
|
253
|
+
and isinstance(item.get("id"), str)
|
|
254
|
+
and isinstance(item.get("code"), str)
|
|
255
|
+
and item["code"].strip()
|
|
256
|
+
):
|
|
257
|
+
catalog.setdefault(item["id"], item)
|
|
258
|
+
return catalog
|
|
254
259
|
|
|
255
260
|
|
|
256
261
|
def _section_code_evidence(
|
|
257
|
-
finding: dict[str, Any],
|
|
262
|
+
finding: dict[str, Any], *sections: dict[str, Any]
|
|
258
263
|
) -> list[dict[str, Any]]:
|
|
259
264
|
catalog = _code_evidence_catalog(finding)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
resolved: list[dict[str, Any]] = []
|
|
266
|
+
for section in sections:
|
|
267
|
+
for key in ("evidenceRefs", "evidence_refs"):
|
|
268
|
+
refs = section.get(key, [])
|
|
269
|
+
if isinstance(refs, str):
|
|
270
|
+
refs = [refs]
|
|
271
|
+
if isinstance(refs, list):
|
|
272
|
+
resolved.extend(
|
|
273
|
+
catalog[ref] for ref in refs if isinstance(ref, str) and ref in catalog
|
|
274
|
+
)
|
|
275
|
+
for key in ("codeEvidence", "code_evidence"):
|
|
276
|
+
embedded = section.get(key, [])
|
|
277
|
+
if isinstance(embedded, list):
|
|
278
|
+
resolved.extend(
|
|
279
|
+
item
|
|
280
|
+
for item in embedded
|
|
281
|
+
if isinstance(item, dict)
|
|
282
|
+
and isinstance(item.get("code"), str)
|
|
283
|
+
and item["code"].strip()
|
|
284
|
+
)
|
|
273
285
|
unique: list[dict[str, Any]] = []
|
|
274
286
|
seen: set[tuple[str, str]] = set()
|
|
275
287
|
for item in resolved:
|
|
@@ -281,6 +293,102 @@ def _section_code_evidence(
|
|
|
281
293
|
return unique
|
|
282
294
|
|
|
283
295
|
|
|
296
|
+
def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
|
|
297
|
+
keys = [key for key in ("rootCause", "root_cause") if key in value]
|
|
298
|
+
if not keys:
|
|
299
|
+
return None, None
|
|
300
|
+
if len(keys) == 1:
|
|
301
|
+
detail = value[keys[0]]
|
|
302
|
+
return keys[0], detail if isinstance(detail, (str, dict)) else None
|
|
303
|
+
details: list[dict[str, Any]] = []
|
|
304
|
+
for key in keys:
|
|
305
|
+
detail = value[key]
|
|
306
|
+
if isinstance(detail, str):
|
|
307
|
+
details.append({"summary": detail})
|
|
308
|
+
elif isinstance(detail, dict):
|
|
309
|
+
details.append(detail)
|
|
310
|
+
elif detail is not None:
|
|
311
|
+
continue
|
|
312
|
+
if not details:
|
|
313
|
+
return keys[0], None
|
|
314
|
+
|
|
315
|
+
merged: dict[str, Any] = {}
|
|
316
|
+
text_fields = {
|
|
317
|
+
"cause",
|
|
318
|
+
"code",
|
|
319
|
+
"description",
|
|
320
|
+
"detail",
|
|
321
|
+
"explanation",
|
|
322
|
+
"rationale",
|
|
323
|
+
"summary",
|
|
324
|
+
"why",
|
|
325
|
+
}
|
|
326
|
+
for detail in details:
|
|
327
|
+
for field, item in detail.items():
|
|
328
|
+
if field in (
|
|
329
|
+
"evidenceRefs",
|
|
330
|
+
"evidence_refs",
|
|
331
|
+
"codeEvidence",
|
|
332
|
+
"code_evidence",
|
|
333
|
+
"language",
|
|
334
|
+
):
|
|
335
|
+
continue
|
|
336
|
+
if field in text_fields and (
|
|
337
|
+
not isinstance(item, str) or not item.strip()
|
|
338
|
+
):
|
|
339
|
+
continue
|
|
340
|
+
current = merged.get(field)
|
|
341
|
+
if field not in merged or current in (None, "", [], {}) or (
|
|
342
|
+
isinstance(current, str) and not current.strip()
|
|
343
|
+
):
|
|
344
|
+
merged[field] = item
|
|
345
|
+
|
|
346
|
+
evidence_values = [
|
|
347
|
+
detail[field]
|
|
348
|
+
for detail in details
|
|
349
|
+
for field in ("evidenceRefs", "evidence_refs")
|
|
350
|
+
if field in detail
|
|
351
|
+
]
|
|
352
|
+
if evidence_values:
|
|
353
|
+
merged["evidenceRefs"] = list(
|
|
354
|
+
dict.fromkeys(
|
|
355
|
+
item
|
|
356
|
+
for evidence in evidence_values
|
|
357
|
+
for item in (evidence if isinstance(evidence, list) else [evidence])
|
|
358
|
+
if isinstance(item, str)
|
|
359
|
+
)
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
embedded_evidence = [
|
|
363
|
+
item
|
|
364
|
+
for detail in details
|
|
365
|
+
for field in ("codeEvidence", "code_evidence")
|
|
366
|
+
for item in (
|
|
367
|
+
detail.get(field, []) if isinstance(detail.get(field), list) else []
|
|
368
|
+
)
|
|
369
|
+
]
|
|
370
|
+
if embedded_evidence:
|
|
371
|
+
merged["codeEvidence"] = embedded_evidence
|
|
372
|
+
|
|
373
|
+
code = merged.get("code")
|
|
374
|
+
matching_details = (
|
|
375
|
+
details
|
|
376
|
+
if not isinstance(code, str) or not code.strip()
|
|
377
|
+
else [detail for detail in details if detail.get("code") == code]
|
|
378
|
+
)
|
|
379
|
+
language = next(
|
|
380
|
+
(
|
|
381
|
+
detail["language"]
|
|
382
|
+
for detail in matching_details
|
|
383
|
+
if isinstance(detail.get("language"), str) and detail["language"].strip()
|
|
384
|
+
),
|
|
385
|
+
None,
|
|
386
|
+
)
|
|
387
|
+
if language is not None:
|
|
388
|
+
merged["language"] = language
|
|
389
|
+
return keys[0], merged
|
|
390
|
+
|
|
391
|
+
|
|
284
392
|
def _root_cause_code_evidence(
|
|
285
393
|
finding: dict[str, Any], root_cause: dict[str, Any]
|
|
286
394
|
) -> list[dict[str, Any]]:
|
|
@@ -419,34 +527,90 @@ def _surface_notes(surface: dict[str, Any]) -> str:
|
|
|
419
527
|
|
|
420
528
|
def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
421
529
|
validation = finding.get("validation") if isinstance(finding.get("validation"), dict) else {}
|
|
422
|
-
raw_root_cause = finding
|
|
530
|
+
_, raw_root_cause = merged_root_cause(finding)
|
|
423
531
|
root_cause = raw_root_cause if isinstance(raw_root_cause, dict) else {}
|
|
424
532
|
attack_path = finding.get("attackPath") if isinstance(finding.get("attackPath"), dict) else {}
|
|
425
|
-
|
|
533
|
+
dataflow_sections = [
|
|
534
|
+
{"summary": value} if isinstance(value, str) else value
|
|
535
|
+
for key in ("dataFlow", "dataflow", "data_flow")
|
|
536
|
+
if isinstance((value := attack_path.get(key)), (str, dict))
|
|
537
|
+
]
|
|
538
|
+
dataflow: dict[str, Any] = {}
|
|
539
|
+
for key in ("summary", "source", "sink", "outcome"):
|
|
540
|
+
value = next(
|
|
541
|
+
(
|
|
542
|
+
section[key]
|
|
543
|
+
for section in dataflow_sections
|
|
544
|
+
if key in section
|
|
545
|
+
and isinstance(section[key], str)
|
|
546
|
+
and section[key].strip()
|
|
547
|
+
),
|
|
548
|
+
None,
|
|
549
|
+
)
|
|
550
|
+
if value is not None:
|
|
551
|
+
dataflow[key] = value
|
|
552
|
+
transformations = list(
|
|
553
|
+
dict.fromkeys(
|
|
554
|
+
transformation
|
|
555
|
+
for section in dataflow_sections
|
|
556
|
+
for transformation in (
|
|
557
|
+
[section.get("transformations")]
|
|
558
|
+
if isinstance(section.get("transformations"), str)
|
|
559
|
+
else section.get("transformations")
|
|
560
|
+
if isinstance(section.get("transformations"), list)
|
|
561
|
+
else []
|
|
562
|
+
)
|
|
563
|
+
if isinstance(transformation, str) and transformation.strip()
|
|
564
|
+
)
|
|
565
|
+
)
|
|
566
|
+
if transformations:
|
|
567
|
+
dataflow["transformations"] = transformations
|
|
568
|
+
raw_reachability = attack_path.get("reachability")
|
|
426
569
|
reachability = (
|
|
427
|
-
|
|
570
|
+
{"summary": raw_reachability}
|
|
571
|
+
if isinstance(raw_reachability, str)
|
|
572
|
+
else raw_reachability
|
|
573
|
+
if isinstance(raw_reachability, dict)
|
|
574
|
+
else {}
|
|
428
575
|
)
|
|
429
576
|
severity = finding["severity"]
|
|
577
|
+
validation_outcomes = [
|
|
578
|
+
(label, text)
|
|
579
|
+
for label, key in (
|
|
580
|
+
("Status", "status"),
|
|
581
|
+
("Disposition", "disposition"),
|
|
582
|
+
("Result", "result"),
|
|
583
|
+
)
|
|
584
|
+
if (text := _text(validation.get(key), ""))
|
|
585
|
+
]
|
|
430
586
|
validation_summary = _text(
|
|
431
587
|
validation.get("summary"),
|
|
432
|
-
|
|
588
|
+
"Validation outcomes are recorded below."
|
|
589
|
+
if validation_outcomes
|
|
590
|
+
else f"{finding['confidence']['rationale']} Validation details were not recorded separately.",
|
|
433
591
|
)
|
|
434
592
|
validation_evidence = _strings(validation.get("evidence"))
|
|
593
|
+
validation_assertions = _strings(validation.get("assertions"))
|
|
435
594
|
validation_counterevidence = _strings(validation.get("counterEvidence"))
|
|
595
|
+
validation_limitations = _strings(validation.get("limitations"))
|
|
436
596
|
root_cause_summary = _text(
|
|
437
597
|
raw_root_cause if isinstance(raw_root_cause, str) else root_cause.get("summary"),
|
|
438
598
|
"",
|
|
439
599
|
)
|
|
440
600
|
root_cause_code_evidence = _root_cause_code_evidence(finding, root_cause)
|
|
441
601
|
validation_code_evidence = _section_code_evidence(finding, validation)
|
|
442
|
-
|
|
602
|
+
dataflow_code_evidence = _section_code_evidence(finding, attack_path, *dataflow_sections)
|
|
603
|
+
reachability_code_evidence = _section_code_evidence(finding, reachability)
|
|
443
604
|
dataflow_summary = _text(
|
|
444
605
|
dataflow.get("summary"),
|
|
445
606
|
f"The canonical finding records the affected path at {_locations(finding)}, but no expanded source-to-sink narrative was recorded.",
|
|
446
607
|
)
|
|
447
608
|
reachability_summary = _text(
|
|
448
609
|
reachability.get("summary"),
|
|
449
|
-
|
|
610
|
+
_text(
|
|
611
|
+
attack_path.get("summary"),
|
|
612
|
+
"Reachability was not recorded beyond the canonical finding summary and affected locations.",
|
|
613
|
+
),
|
|
450
614
|
)
|
|
451
615
|
severity_rationale = _text(
|
|
452
616
|
severity.get("rationale"),
|
|
@@ -458,6 +622,7 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
458
622
|
)
|
|
459
623
|
remediation_tests = _strings(finding.get("remediationTests"))
|
|
460
624
|
preventive_controls = _strings(finding.get("preventiveControls"))
|
|
625
|
+
attack_steps = _strings(attack_path.get("steps"))
|
|
461
626
|
cwes = ", ".join(finding["taxonomy"]["cwe"]) or "none"
|
|
462
627
|
title = _text(finding["title"], "Untitled finding")
|
|
463
628
|
lines = [
|
|
@@ -486,7 +651,13 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
486
651
|
lines.extend(["", "#### Validation", "", validation_summary])
|
|
487
652
|
if validation.get("method"):
|
|
488
653
|
lines.extend(["", f"Validation method: {_text(validation['method'], 'not recorded')}"])
|
|
654
|
+
if validation_outcomes:
|
|
655
|
+
lines.extend(
|
|
656
|
+
["", *(f"- **{label}:** {value}" for label, value in validation_outcomes)]
|
|
657
|
+
)
|
|
489
658
|
lines.extend(_code_evidence_lines(validation_code_evidence))
|
|
659
|
+
if validation_assertions:
|
|
660
|
+
lines.extend(["", "Assertions:", *_bullets(validation_assertions, "None recorded.")])
|
|
490
661
|
if validation_evidence:
|
|
491
662
|
lines.extend(["", "Evidence:", *_bullets(validation_evidence, "No evidence recorded.")])
|
|
492
663
|
if validation_counterevidence:
|
|
@@ -497,25 +668,48 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
497
668
|
*_bullets(validation_counterevidence, "None recorded."),
|
|
498
669
|
]
|
|
499
670
|
)
|
|
671
|
+
if validation_limitations:
|
|
672
|
+
lines.extend(["", "Limitations:", *_bullets(validation_limitations, "None recorded.")])
|
|
500
673
|
lines.extend(["", "#### Dataflow", "", dataflow_summary])
|
|
674
|
+
if attack_steps:
|
|
675
|
+
lines.extend(["", "Attack steps:", *_bullets(attack_steps, "None recorded.")])
|
|
501
676
|
for label, key in (("Source", "source"), ("Sink", "sink"), ("Outcome", "outcome")):
|
|
502
677
|
if dataflow.get(key):
|
|
503
678
|
lines.extend(["", f"- **{label}:** {_text(dataflow[key], 'not recorded')}"])
|
|
504
679
|
transformations = _strings(dataflow.get("transformations"))
|
|
505
680
|
if transformations:
|
|
506
681
|
lines.extend(["", "Transformations:", *_bullets(transformations, "None recorded.")])
|
|
507
|
-
lines.extend(_code_evidence_lines(
|
|
682
|
+
lines.extend(_code_evidence_lines(dataflow_code_evidence))
|
|
508
683
|
lines.extend(["", "#### Reachability", "", reachability_summary])
|
|
509
684
|
for label, key in (
|
|
510
685
|
("Attacker", "attacker"),
|
|
511
686
|
("Entry point", "entrypoint"),
|
|
687
|
+
("Source", "source"),
|
|
688
|
+
("Sink", "sink"),
|
|
512
689
|
("Outcome", "outcome"),
|
|
513
690
|
):
|
|
514
691
|
if reachability.get(key):
|
|
515
692
|
lines.extend(["", f"- **{label}:** {_text(reachability[key], 'not recorded')}"])
|
|
516
|
-
preconditions =
|
|
693
|
+
preconditions = list(
|
|
694
|
+
dict.fromkeys(
|
|
695
|
+
[
|
|
696
|
+
*_strings(attack_path.get("preconditions")),
|
|
697
|
+
*_strings(reachability.get("preconditions")),
|
|
698
|
+
]
|
|
699
|
+
)
|
|
700
|
+
)
|
|
517
701
|
if preconditions:
|
|
518
702
|
lines.extend(["", "Preconditions:", *_bullets(preconditions, "None recorded.")])
|
|
703
|
+
for label, key in (
|
|
704
|
+
("Assumptions", "assumptions"),
|
|
705
|
+
("Existing controls", "controls"),
|
|
706
|
+
("Blind spots", "blindspots"),
|
|
707
|
+
("Limitations", "limitations"),
|
|
708
|
+
):
|
|
709
|
+
values = _strings(attack_path.get(key))
|
|
710
|
+
if values:
|
|
711
|
+
lines.extend(["", f"{label}:", *_bullets(values, "None recorded.")])
|
|
712
|
+
lines.extend(_code_evidence_lines(reachability_code_evidence))
|
|
519
713
|
lines.extend(
|
|
520
714
|
[
|
|
521
715
|
"",
|
|
@@ -524,6 +718,32 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
|
|
|
524
718
|
f"**{severity['level'].capitalize()}** — {severity_rationale}",
|
|
525
719
|
"",
|
|
526
720
|
severity_change,
|
|
721
|
+
]
|
|
722
|
+
)
|
|
723
|
+
for label, key in (("Impact", "impact"), ("Likelihood", "likelihood")):
|
|
724
|
+
assessment = attack_path.get(key)
|
|
725
|
+
if isinstance(assessment, str):
|
|
726
|
+
rendered = _text(assessment, "")
|
|
727
|
+
if rendered:
|
|
728
|
+
lines.extend(["", f"**{label} assessment:** {rendered}"])
|
|
729
|
+
continue
|
|
730
|
+
if not isinstance(assessment, dict):
|
|
731
|
+
continue
|
|
732
|
+
details = [
|
|
733
|
+
(detail_label, text)
|
|
734
|
+
for detail_label, detail_key in (
|
|
735
|
+
("Level", "level"),
|
|
736
|
+
("Rationale", "rationale"),
|
|
737
|
+
("Why", "why"),
|
|
738
|
+
)
|
|
739
|
+
if (text := _text(assessment.get(detail_key), ""))
|
|
740
|
+
]
|
|
741
|
+
if details:
|
|
742
|
+
lines.extend(
|
|
743
|
+
["", f"{label} assessment:", *(f"- **{name}:** {value}" for name, value in details)]
|
|
744
|
+
)
|
|
745
|
+
lines.extend(
|
|
746
|
+
[
|
|
527
747
|
"",
|
|
528
748
|
"#### Remediation",
|
|
529
749
|
"",
|
|
@@ -59,11 +59,14 @@ def validate_contract(scan_dir: Path) -> dict[str, Any]:
|
|
|
59
59
|
coverage_ref: coverage_bytes,
|
|
60
60
|
},
|
|
61
61
|
)
|
|
62
|
-
FINALIZER.
|
|
62
|
+
findings_for_validation = FINALIZER._legacy_sealed_findings_for_validation(findings)
|
|
63
|
+
FINALIZER._validate_findings(manifest, findings_for_validation)
|
|
63
64
|
FINALIZER._validate_derived_finding_identities(manifest, findings)
|
|
64
65
|
FINALIZER._validate_coverage(manifest, coverage, scan_dir)
|
|
65
66
|
FINALIZER._validate_sealed_coverage_receipts(scan, coverage)
|
|
66
|
-
FINALIZER.validate_against_schema(
|
|
67
|
+
FINALIZER.validate_against_schema(
|
|
68
|
+
findings_for_validation, schema_dir / "findings.schema.json"
|
|
69
|
+
)
|
|
67
70
|
FINALIZER.validate_against_schema(coverage, schema_dir / "coverage.schema.json")
|
|
68
71
|
FINALIZER._require_scan_local_file(scan_dir, "report.md", "report.md")
|
|
69
72
|
return {
|
|
@@ -309,7 +309,13 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
309
309
|
publication.add_argument("--input-file", required=True)
|
|
310
310
|
|
|
311
311
|
subparsers.add_parser("database-info")
|
|
312
|
-
|
|
312
|
+
arguments = sys.argv[1:]
|
|
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)
|
|
313
319
|
|
|
314
320
|
|
|
315
321
|
def non_negative_int(value: str) -> int:
|
|
@@ -23,6 +23,8 @@ def remediation_claim_is_active(remediation: sqlite3.Row) -> bool:
|
|
|
23
23
|
if not isinstance(claimed_at, str):
|
|
24
24
|
return True
|
|
25
25
|
try:
|
|
26
|
+
if claimed_at.endswith(("Z", "z")):
|
|
27
|
+
claimed_at = claimed_at[:-1] + "+00:00"
|
|
26
28
|
parsed = datetime.fromisoformat(claimed_at)
|
|
27
29
|
if parsed.tzinfo is None:
|
|
28
30
|
return True
|
|
@@ -35,6 +35,10 @@ Do not repeat this guard after it passes, on later context loads, or after the s
|
|
|
35
35
|
|
|
36
36
|
After preserving any native continuation's scan context and applying its one-time concurrent-scan guard, read `../../references/scan-prologue.md` once. Deep scans do not run a capability helper, inspect runtime tools, request configuration remediation, or publish preflight checks. The coordinator validates its own ownership, target, scope, and sandbox and manages its workers independently of this thread's delegation runtime and subagent allowance.
|
|
37
37
|
|
|
38
|
+
## TAC Status Advisory
|
|
39
|
+
|
|
40
|
+
Immediately before the first `start_codex_security_deep_scan` call, the top-level parent uses the hosted Codex Security Access app [$codex-security-access](app://connector_openai_codex_security_access) to call `get_tac_status` once; workers never perform this advisory. Reuse an existing result when continuing the same scan. Report the exact `status` and TAC grant levels. If `status` is `not_granted`, prominently warn before scan-start progress that TAC access is not granted and protected outputs may not be displayable, and include the returned `enrollmentUrl` as a clickable application link, falling back to `https://chatgpt.com/cyber` when it is absent. If `status` is `unknown` or the app or action is unavailable, warn that access could not be verified and protected outputs may not be displayable. Then continue regardless: the advisory never authorizes, gates, or becomes a capability preflight for the scan. Do not poll or repeat it between phases; recheck only when the user explicitly requests a fresh result after an account or TAC access change.
|
|
41
|
+
|
|
38
42
|
## Run Independent Standard Scans
|
|
39
43
|
|
|
40
44
|
Use the same coordinator tool in every host:
|
|
@@ -21,11 +21,11 @@ Save context changes with `update_codex_security_scan_context`. Advance each sta
|
|
|
21
21
|
|
|
22
22
|
Read `../../references/config-preflight.md` before dispatching the `security_diff_scan` capability preflight. When the host explicitly identifies itself as the desktop app, also read `../../references/desktop-config-preflight.md` before running the helper. For a durable scan, use its authoritative scan context, ask before applying actionable remediation, and wait without creating a scan goal or calling `fail_codex_security_scan`. Do not fail automatically for declined or unavailable remediation, helper errors, or a non-ready rerun; preserve the running scan and retry or hand off while recovery may still be possible. Use `cancel_codex_security_scan` only when the user explicitly cancels; call `fail_codex_security_scan` only after documented recovery is exhausted and the blocker is confirmed unrecoverable. Do not treat a config value that differs from a suggested patch as a warning unless the capability requirement itself is unmet.
|
|
23
23
|
|
|
24
|
-
1. Run `$threat-model` once, or use the supplied model
|
|
24
|
+
1. Run `$threat-model` once, or use the supplied model, and retain the required copy at `<context_dir>/threat_model.md`. Preserve a supplied schema-valid canonical `threatModel` object unchanged. Otherwise retain the exact supplied text, or the completed generated Markdown, as `{ "summary": "<model text>" }` for the canonical draft. Model the repository unless the user requests a narrower scope.
|
|
25
25
|
2. Prepare the file list with `prepare_codex_security_review_items` and read all pages from `list_codex_security_review_items`. Inspect deleted files at the baseline revision and unchanged files only when needed to explain the change.
|
|
26
26
|
3. Run `$finding-discovery` in compact diff mode across the existing file inventory. Do not create ranked worklists, per-finding ledgers, or discovery reports. Divide large changes among available workers without overlap; review any unassigned files yourself. Keep independently reachable bugs separate and record all candidates once with `record_codex_security_discovery_candidates`.
|
|
27
27
|
4. If candidates exist, run `$validation` once, then `$attack-path-analysis` once for candidates marked `reportable` or `deferred`. Preserve exact locations, evidence, affected instances, and unresolved questions.
|
|
28
|
-
5. Record findings and
|
|
28
|
+
5. Record findings, coverage, and the retained canonical model with `record_codex_security_scan_draft({ scanId, handoffClaimToken?, scope?, threatModel, findings, coverage })`. Mark unresolved work as deferred. Request detailed write-ups or hardening plans only when the user asks.
|
|
29
29
|
6. Call `complete_codex_security_scan` once, then read `get_codex_security_completed_scan`. Finalization creates `report.md` and SARIF. Include measured token usage when available and identify incomplete coverage.
|
|
30
30
|
|
|
31
31
|
For terminal scans without a `scanId`, generate the changed-file list with:
|
|
@@ -17,7 +17,7 @@ After resolving the target and host-specific scan context, read `../../reference
|
|
|
17
17
|
|
|
18
18
|
For a running host-backed scan, persist user-requested context changes with `update_codex_security_scan_context` and the current handoff token when required. At each real forward phase transition, use `structuredContent.scan.userContext` from `update_codex_security_scan_progress` as the immutable context for that phase and its workers. Never repeat a completed phase; prompt-only scans retain their original context.
|
|
19
19
|
|
|
20
|
-
When an SDK or terminal host sets `CODEX_SECURITY_SCAN_ID`, emit its standalone `CODEX_SECURITY_SCAN_PROGRESS {"phase":"discovery","filesCompleted":3,"filesTotal":8}` marker at discovery start, meaningful completed-review batches, and real later phase transitions. Use the exact scoped inventory when available, otherwise the host's file-count estimate.
|
|
20
|
+
When an SDK or terminal host sets `CODEX_SECURITY_SCAN_ID`, emit its standalone `CODEX_SECURITY_SCAN_PROGRESS {"phase":"discovery","filesCompleted":3,"filesTotal":8}` marker at discovery start, meaningful completed-review batches, and real later phase transitions. Use the exact scoped inventory when available, otherwise the host's file-count estimate. Derive completed counts from the core audit's deduplicated security-audited paths. Never create inventories or receipt files only for progress.
|
|
21
21
|
|
|
22
22
|
## Workflow
|
|
23
23
|
|