@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.
Files changed (314) hide show
  1. package/README.md +295 -32
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  14. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  15. package/_bundled_plugin/references/artifact-storage.md +4 -4
  16. package/_bundled_plugin/references/config-preflight.md +1 -1
  17. package/_bundled_plugin/references/core-scan.md +14 -2
  18. package/_bundled_plugin/references/final-report.md +4 -2
  19. package/_bundled_plugin/references/scan-artifacts.md +2 -2
  20. package/_bundled_plugin/references/scan-contract.md +2 -2
  21. package/_bundled_plugin/references/threat-model.md +2 -2
  22. package/_bundled_plugin/schemas/coverage.schema.json +22 -0
  23. package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
  24. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
  25. package/_bundled_plugin/scripts/config_preflight.py +4 -8
  26. package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
  27. package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
  28. package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
  29. package/_bundled_plugin/scripts/finding_preview.py +42 -82
  30. package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
  31. package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
  32. package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
  33. package/_bundled_plugin/scripts/rank_preview.py +85 -68
  34. package/_bundled_plugin/scripts/report_projection.py +37 -58
  35. package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
  36. package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
  37. package/_bundled_plugin/scripts/workbench/storage.py +11 -0
  38. package/_bundled_plugin/scripts/workbench_cli.py +11 -17
  39. package/_bundled_plugin/scripts/workbench_constants.py +6 -14
  40. package/_bundled_plugin/scripts/workbench_db.py +116 -228
  41. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
  42. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
  43. package/_bundled_plugin/scripts/workbench_progress.py +12 -34
  44. package/_bundled_plugin/scripts/workbench_publication.py +47 -62
  45. package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
  46. package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
  47. package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
  48. package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
  49. package/_bundled_plugin/scripts/workbench_schema.py +86 -271
  50. package/_bundled_plugin/scripts/workbench_severity.py +3 -0
  51. package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
  52. package/_bundled_plugin/scripts/workbench_target.py +98 -10
  53. package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
  54. package/_bundled_plugin/scripts/workbench_validation.py +6 -20
  55. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
  56. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
  57. package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
  58. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  59. package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
  60. package/dist/api.d.ts +3 -5
  61. package/dist/api.d.ts.map +1 -1
  62. package/dist/api.js +201 -207
  63. package/dist/api.js.map +1 -1
  64. package/dist/artifact-export.d.ts +70 -0
  65. package/dist/artifact-export.d.ts.map +1 -0
  66. package/dist/artifact-export.js +277 -0
  67. package/dist/artifact-export.js.map +1 -0
  68. package/dist/auth.d.ts.map +1 -1
  69. package/dist/auth.js +8 -3
  70. package/dist/auth.js.map +1 -1
  71. package/dist/bulk-scan-discovery.d.ts +1 -0
  72. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  73. package/dist/bulk-scan-discovery.js +8 -9
  74. package/dist/bulk-scan-discovery.js.map +1 -1
  75. package/dist/classify-scan-severity.d.ts.map +1 -1
  76. package/dist/classify-scan-severity.js +2 -5
  77. package/dist/classify-scan-severity.js.map +1 -1
  78. package/dist/classify-severity.d.ts +2 -8
  79. package/dist/classify-severity.d.ts.map +1 -1
  80. package/dist/classify-severity.js +3 -5
  81. package/dist/classify-severity.js.map +1 -1
  82. package/dist/cli-help.d.ts +3 -0
  83. package/dist/cli-help.d.ts.map +1 -0
  84. package/dist/cli-help.js +281 -0
  85. package/dist/cli-help.js.map +1 -0
  86. package/dist/cli.d.ts +19 -22
  87. package/dist/cli.d.ts.map +1 -1
  88. package/dist/cli.js +631 -714
  89. package/dist/cli.js.map +1 -1
  90. package/dist/cloud-publish.d.ts.map +1 -1
  91. package/dist/cloud-publish.js +1 -8
  92. package/dist/cloud-publish.js.map +1 -1
  93. package/dist/codex-prompt.d.ts.map +1 -1
  94. package/dist/codex-prompt.js +1 -2
  95. package/dist/codex-prompt.js.map +1 -1
  96. package/dist/codex-sdk-environment.d.ts +2 -0
  97. package/dist/codex-sdk-environment.d.ts.map +1 -0
  98. package/dist/codex-sdk-environment.js +30 -0
  99. package/dist/codex-sdk-environment.js.map +1 -0
  100. package/dist/component-plan.d.ts.map +1 -1
  101. package/dist/component-plan.js +2 -6
  102. package/dist/component-plan.js.map +1 -1
  103. package/dist/component-scan.d.ts +1 -0
  104. package/dist/component-scan.d.ts.map +1 -1
  105. package/dist/component-scan.js +31 -9
  106. package/dist/component-scan.js.map +1 -1
  107. package/dist/config.d.ts.map +1 -1
  108. package/dist/config.js +32 -33
  109. package/dist/config.js.map +1 -1
  110. package/dist/contract.d.ts +2 -1
  111. package/dist/contract.d.ts.map +1 -1
  112. package/dist/contract.js +63 -122
  113. package/dist/contract.js.map +1 -1
  114. package/dist/cost-model.d.ts.map +1 -1
  115. package/dist/cost-model.js +65 -34
  116. package/dist/cost-model.js.map +1 -1
  117. package/dist/cost.d.ts.map +1 -1
  118. package/dist/cost.js +15 -31
  119. package/dist/cost.js.map +1 -1
  120. package/dist/custom-validation-prompt.js +4 -4
  121. package/dist/custom-validation-prompt.js.map +1 -1
  122. package/dist/custom-validation.d.ts.map +1 -1
  123. package/dist/custom-validation.js +17 -16
  124. package/dist/custom-validation.js.map +1 -1
  125. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  126. package/dist/deduplication/checkpointed-review.js +10 -11
  127. package/dist/deduplication/checkpointed-review.js.map +1 -1
  128. package/dist/deduplication/codex-review.d.ts +2 -0
  129. package/dist/deduplication/codex-review.d.ts.map +1 -1
  130. package/dist/deduplication/codex-review.js +3 -3
  131. package/dist/deduplication/codex-review.js.map +1 -1
  132. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  133. package/dist/deduplication/deduplication-reviewer.js +2 -0
  134. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  135. package/dist/deduplication/deduplication.js +40 -62
  136. package/dist/deduplication/deduplication.js.map +1 -1
  137. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  138. package/dist/deduplication/records-protocol.js +1 -4
  139. package/dist/deduplication/records-protocol.js.map +1 -1
  140. package/dist/deduplication/records.d.ts +2 -1
  141. package/dist/deduplication/records.d.ts.map +1 -1
  142. package/dist/deduplication/records.js +24 -6
  143. package/dist/deduplication/records.js.map +1 -1
  144. package/dist/deduplication/review.d.ts +7 -0
  145. package/dist/deduplication/review.d.ts.map +1 -1
  146. package/dist/deduplication/review.js.map +1 -1
  147. package/dist/deduplication/scan.js +3 -7
  148. package/dist/deduplication/scan.js.map +1 -1
  149. package/dist/deep-config.d.ts.map +1 -1
  150. package/dist/deep-config.js +3 -19
  151. package/dist/deep-config.js.map +1 -1
  152. package/dist/deep-progress.d.ts +0 -1
  153. package/dist/deep-progress.d.ts.map +1 -1
  154. package/dist/deep-progress.js +22 -40
  155. package/dist/deep-progress.js.map +1 -1
  156. package/dist/errors.d.ts +3 -2
  157. package/dist/errors.d.ts.map +1 -1
  158. package/dist/errors.js +5 -7
  159. package/dist/errors.js.map +1 -1
  160. package/dist/finding-catalogue.d.ts.map +1 -1
  161. package/dist/finding-catalogue.js +22 -22
  162. package/dist/finding-catalogue.js.map +1 -1
  163. package/dist/finding-workflow.d.ts.map +1 -1
  164. package/dist/finding-workflow.js +4 -7
  165. package/dist/finding-workflow.js.map +1 -1
  166. package/dist/findings-import.d.ts.map +1 -1
  167. package/dist/findings-import.js +7 -17
  168. package/dist/findings-import.js.map +1 -1
  169. package/dist/github.d.ts.map +1 -1
  170. package/dist/github.js +2 -3
  171. package/dist/github.js.map +1 -1
  172. package/dist/import-scan.js +2 -2
  173. package/dist/import-scan.js.map +1 -1
  174. package/dist/index.d.ts +4 -2
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js +2 -1
  177. package/dist/index.js.map +1 -1
  178. package/dist/knowledge-base.js +2 -2
  179. package/dist/knowledge-base.js.map +1 -1
  180. package/dist/linear.d.ts.map +1 -1
  181. package/dist/linear.js +2 -3
  182. package/dist/linear.js.map +1 -1
  183. package/dist/models.d.ts +24 -0
  184. package/dist/models.d.ts.map +1 -1
  185. package/dist/models.js.map +1 -1
  186. package/dist/multiscan.d.ts.map +1 -1
  187. package/dist/multiscan.js +36 -31
  188. package/dist/multiscan.js.map +1 -1
  189. package/dist/owner-evidence.d.ts.map +1 -1
  190. package/dist/owner-evidence.js +2 -6
  191. package/dist/owner-evidence.js.map +1 -1
  192. package/dist/patch-tui.d.ts.map +1 -1
  193. package/dist/patch-tui.js +2 -4
  194. package/dist/patch-tui.js.map +1 -1
  195. package/dist/project-config-schema.d.ts +10 -0
  196. package/dist/project-config-schema.d.ts.map +1 -1
  197. package/dist/project-config-schema.js +1 -0
  198. package/dist/project-config-schema.js.map +1 -1
  199. package/dist/project-config.d.ts +1 -0
  200. package/dist/project-config.d.ts.map +1 -1
  201. package/dist/project-config.js +2 -0
  202. package/dist/project-config.js.map +1 -1
  203. package/dist/prompt-files.d.ts +0 -1
  204. package/dist/prompt-files.d.ts.map +1 -1
  205. package/dist/prompt-files.js +2 -4
  206. package/dist/prompt-files.js.map +1 -1
  207. package/dist/publication-events.d.ts.map +1 -1
  208. package/dist/publication-events.js +15 -29
  209. package/dist/publication-events.js.map +1 -1
  210. package/dist/publication-store.d.ts.map +1 -1
  211. package/dist/publication-store.js +9 -13
  212. package/dist/publication-store.js.map +1 -1
  213. package/dist/publication.d.ts.map +1 -1
  214. package/dist/publication.js +11 -14
  215. package/dist/publication.js.map +1 -1
  216. package/dist/publish.d.ts.map +1 -1
  217. package/dist/publish.js +31 -41
  218. package/dist/publish.js.map +1 -1
  219. package/dist/record.d.ts +2 -0
  220. package/dist/record.d.ts.map +1 -0
  221. package/dist/record.js +4 -0
  222. package/dist/record.js.map +1 -0
  223. package/dist/result.d.ts +4 -1
  224. package/dist/result.d.ts.map +1 -1
  225. package/dist/result.js +7 -0
  226. package/dist/result.js.map +1 -1
  227. package/dist/runtime.d.ts +10 -13
  228. package/dist/runtime.d.ts.map +1 -1
  229. package/dist/runtime.js +203 -131
  230. package/dist/runtime.js.map +1 -1
  231. package/dist/saved-scan.d.ts.map +1 -1
  232. package/dist/saved-scan.js +10 -20
  233. package/dist/saved-scan.js.map +1 -1
  234. package/dist/scan-activity.d.ts.map +1 -1
  235. package/dist/scan-activity.js +8 -22
  236. package/dist/scan-activity.js.map +1 -1
  237. package/dist/scan-comparison.d.ts +3 -3
  238. package/dist/scan-comparison.d.ts.map +1 -1
  239. package/dist/scan-comparison.js +38 -73
  240. package/dist/scan-comparison.js.map +1 -1
  241. package/dist/scan-dashboard.d.ts +0 -1
  242. package/dist/scan-dashboard.d.ts.map +1 -1
  243. package/dist/scan-dashboard.js +10 -19
  244. package/dist/scan-dashboard.js.map +1 -1
  245. package/dist/scan-history-renderer.d.ts.map +1 -1
  246. package/dist/scan-history-renderer.js +1 -2
  247. package/dist/scan-history-renderer.js.map +1 -1
  248. package/dist/scan-logs.d.ts.map +1 -1
  249. package/dist/scan-logs.js +2 -6
  250. package/dist/scan-logs.js.map +1 -1
  251. package/dist/scan-sessions.d.ts.map +1 -1
  252. package/dist/scan-sessions.js +1 -3
  253. package/dist/scan-sessions.js.map +1 -1
  254. package/dist/scan-settings.d.ts +5 -0
  255. package/dist/scan-settings.d.ts.map +1 -1
  256. package/dist/scan-settings.js +4 -0
  257. package/dist/scan-settings.js.map +1 -1
  258. package/dist/security-policy-cli.d.ts.map +1 -1
  259. package/dist/security-policy-cli.js +8 -6
  260. package/dist/security-policy-cli.js.map +1 -1
  261. package/dist/security-policy.d.ts +8 -4
  262. package/dist/security-policy.d.ts.map +1 -1
  263. package/dist/security-policy.js +98 -84
  264. package/dist/security-policy.js.map +1 -1
  265. package/dist/server/dashboard/app.js +5 -5
  266. package/dist/server/embeddings.d.ts.map +1 -1
  267. package/dist/server/embeddings.js +1 -0
  268. package/dist/server/embeddings.js.map +1 -1
  269. package/dist/server/routes.d.ts +3 -2
  270. package/dist/server/routes.d.ts.map +1 -1
  271. package/dist/server/routes.js +19 -7
  272. package/dist/server/routes.js.map +1 -1
  273. package/dist/server/server.d.ts.map +1 -1
  274. package/dist/server/server.js +2 -3
  275. package/dist/server/server.js.map +1 -1
  276. package/dist/server/sqlite-store.d.ts.map +1 -1
  277. package/dist/server/sqlite-store.js +4 -14
  278. package/dist/server/sqlite-store.js.map +1 -1
  279. package/dist/severity-store.js +8 -15
  280. package/dist/severity-store.js.map +1 -1
  281. package/dist/suggest-owners.d.ts +2 -3
  282. package/dist/suggest-owners.d.ts.map +1 -1
  283. package/dist/suggest-owners.js +4 -5
  284. package/dist/suggest-owners.js.map +1 -1
  285. package/dist/targets.d.ts +1 -0
  286. package/dist/targets.d.ts.map +1 -1
  287. package/dist/targets.js +24 -21
  288. package/dist/targets.js.map +1 -1
  289. package/dist/trusted-executable.d.ts +5 -0
  290. package/dist/trusted-executable.d.ts.map +1 -1
  291. package/dist/trusted-executable.js +22 -5
  292. package/dist/trusted-executable.js.map +1 -1
  293. package/dist/value.d.ts +2 -0
  294. package/dist/value.d.ts.map +1 -0
  295. package/dist/value.js +20 -0
  296. package/dist/value.js.map +1 -0
  297. package/dist/version.d.ts.map +1 -1
  298. package/dist/version.js +3 -6
  299. package/dist/version.js.map +1 -1
  300. package/dist/windows-path.d.ts.map +1 -1
  301. package/dist/windows-path.js +1 -2
  302. package/dist/windows-path.js.map +1 -1
  303. package/dist/worker-progress.d.ts +1 -0
  304. package/dist/worker-progress.d.ts.map +1 -1
  305. package/dist/worker-progress.js +13 -34
  306. package/dist/worker-progress.js.map +1 -1
  307. package/docs/dedupe-records.md +24 -0
  308. package/package.json +11 -10
  309. package/schemas/project-config.schema.json +5 -0
  310. package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
  311. package/dist/server/findings-service.d.ts +0 -20
  312. package/dist/server/findings-service.d.ts.map +0 -1
  313. package/dist/server/findings-service.js +0 -31
  314. package/dist/server/findings-service.js.map +0 -1
package/dist/contract.js CHANGED
@@ -1,10 +1,13 @@
1
- import { createHash } from "node:crypto";
1
+ import { createHash, hash } from "node:crypto";
2
+ import { isNonEmptyString } from "./value.js";
2
3
  import { constants } from "node:fs";
3
4
  import { lstat, open, readFile, realpath, } from "node:fs/promises";
4
- import { isAbsolute, join, posix, relative, resolve, sep } from "node:path";
5
+ import { isAbsolute, join, posix, resolve } from "node:path";
5
6
  import Ajv2020 from "ajv/dist/2020.js";
6
- import { ContractValidationError } from "./errors.js";
7
+ import { ContractValidationError, abortReason } from "./errors.js";
8
+ import { isRecord } from "./record.js";
7
9
  import { requirePrivateOutputDirectory, requireSecureOutputAncestry, } from "./runtime.js";
10
+ import { isWithin as isContained } from "./trusted-executable.js";
8
11
  import { isWindowsUnsafePathComponent } from "./windows-path.js";
9
12
  const DOCUMENTS = {
10
13
  "scan-manifest.json": "scan-manifest.schema.json",
@@ -41,29 +44,25 @@ export async function loadContractWithScanDirectory(scanDirectory, options) {
41
44
  for (const [filename, schemaName] of Object.entries(DOCUMENTS)) {
42
45
  const schema = await readJson(join(options.pluginRoot, "schemas", schemaName), options.signal);
43
46
  let validate;
44
- try {
45
- validate = ajv.compile(schema);
46
- }
47
- catch {
48
- throw new ContractValidationError(`${schemaName}: invalid JSON Schema.`);
49
- }
50
- let payload = filename === "findings.json"
51
- ? findingsPayload
52
- : payloads[filename];
47
+ let payload;
53
48
  let valid;
54
49
  try {
55
- const result = validate(payload);
56
- if (typeof result !== "boolean") {
57
- throw new Error("asynchronous JSON Schema validation is unsupported");
58
- }
59
- valid = result;
60
- if (!valid && filename === "findings.json") {
61
- payload = legacySealedFindingsForValidation(payload);
62
- const compatibleResult = validate(payload);
63
- if (typeof compatibleResult !== "boolean") {
50
+ validate = ajv.compile(schema);
51
+ payload =
52
+ filename === "findings.json"
53
+ ? findingsPayload
54
+ : payloads[filename];
55
+ const validatePayload = (payload) => {
56
+ const result = validate(payload);
57
+ if (typeof result !== "boolean") {
64
58
  throw new Error("asynchronous JSON Schema validation is unsupported");
65
59
  }
66
- valid = compatibleResult;
60
+ return result;
61
+ };
62
+ valid = validatePayload(payload);
63
+ if (!valid && filename === "findings.json") {
64
+ payload = normalizePersistedFindings(payload);
65
+ valid = validatePayload(payload);
67
66
  }
68
67
  }
69
68
  catch {
@@ -104,29 +103,24 @@ export async function loadContractWithScanDirectory(scanDirectory, options) {
104
103
  scanDirectory: scanRoot.path,
105
104
  };
106
105
  }
107
- export async function requireCanonicalScanDirectory(scanDirectory, signal) {
108
- return (await requireScanRoot(scanDirectory, signal)).path;
109
- }
110
- function legacySealedFindingsForValidation(payload) {
106
+ /** Normalize optional legacy details on a copy, without changing saved artifacts. */
107
+ export function normalizePersistedFindings(payload) {
111
108
  const compatible = structuredClone(payload);
112
- if (!isJsonRecord(compatible) || !Array.isArray(compatible["findings"])) {
109
+ if (!isRecord(compatible) || !Array.isArray(compatible["findings"])) {
113
110
  return compatible;
114
111
  }
115
112
  for (const finding of compatible["findings"]) {
116
- if (!isJsonRecord(finding))
113
+ if (!isRecord(finding))
117
114
  continue;
118
115
  const legacyEvidence = finding["code_evidence"];
119
116
  if (Array.isArray(legacyEvidence)) {
120
117
  const compatibleEvidence = [];
121
118
  for (const evidence of legacyEvidence) {
122
- if (!isJsonRecord(evidence))
119
+ if (!isRecord(evidence))
123
120
  continue;
124
121
  const id = evidence["id"];
125
122
  const code = evidence["code"];
126
- if (typeof id !== "string" ||
127
- id.length === 0 ||
128
- typeof code !== "string" ||
129
- code.length === 0) {
123
+ if (!isNonEmptyString(id) || !isNonEmptyString(code)) {
130
124
  continue;
131
125
  }
132
126
  compatibleEvidence.push(evidence);
@@ -163,12 +157,12 @@ function legacySealedFindingsForValidation(payload) {
163
157
  ],
164
158
  ]) {
165
159
  const section = finding[sectionName];
166
- if (!isJsonRecord(section))
160
+ if (!isRecord(section))
167
161
  continue;
168
162
  normalizeLegacyStringLists(section, listFields);
169
163
  }
170
164
  const legacyRootCause = finding["root_cause"];
171
- if (isJsonRecord(legacyRootCause)) {
165
+ if (isRecord(legacyRootCause)) {
172
166
  removeUnsupportedLegacyStrings(legacyRootCause, [
173
167
  "summary",
174
168
  "code",
@@ -181,17 +175,16 @@ function legacySealedFindingsForValidation(payload) {
181
175
  delete finding["root_cause"];
182
176
  }
183
177
  const validation = finding["validation"];
184
- if (isJsonRecord(validation)) {
185
- normalizeLegacyStringOrList(validation, "evidence");
178
+ if (isRecord(validation)) {
179
+ if (typeof validation["evidence"] !== "string" ||
180
+ validation["evidence"].length === 0) {
181
+ normalizeLegacyStringLists(validation, ["evidence"]);
182
+ }
186
183
  removeUnsupportedLegacyStrings(validation, ["method", "summary"]);
187
- removeUnsupportedLegacyNullableStrings(validation, [
188
- "status",
189
- "disposition",
190
- "result",
191
- ]);
184
+ removeUnsupportedLegacyStrings(validation, ["status", "disposition", "result"].filter((field) => validation[field] !== null));
192
185
  }
193
186
  const attackPath = finding["attackPath"];
194
- if (!isJsonRecord(attackPath))
187
+ if (!isRecord(attackPath))
195
188
  continue;
196
189
  removeUnsupportedLegacyStrings(attackPath, ["summary"]);
197
190
  for (const field of ["dataFlow", "data_flow", "dataflow", "reachability"]) {
@@ -205,7 +198,7 @@ function legacySealedFindingsForValidation(payload) {
205
198
  delete attackPath[field];
206
199
  continue;
207
200
  }
208
- if (!isJsonRecord(detail)) {
201
+ if (!isRecord(detail)) {
209
202
  if (field in attackPath)
210
203
  delete attackPath[field];
211
204
  continue;
@@ -226,30 +219,27 @@ function legacySealedFindingsForValidation(payload) {
226
219
  }
227
220
  for (const field of ["impact", "likelihood"]) {
228
221
  const detail = attackPath[field];
229
- if (isJsonRecord(detail)) {
222
+ if (isRecord(detail)) {
230
223
  removeUnsupportedLegacyStrings(detail, ["level", "rationale", "why"]);
231
224
  }
232
225
  else if (detail !== undefined &&
233
226
  detail !== null &&
234
- (typeof detail !== "string" || detail.length === 0)) {
227
+ !isNonEmptyString(detail)) {
235
228
  delete attackPath[field];
236
229
  }
237
230
  }
238
231
  }
239
232
  return compatible;
240
233
  }
241
- function isJsonRecord(value) {
242
- return typeof value === "object" && value !== null && !Array.isArray(value);
243
- }
244
234
  function normalizeLegacyStringLists(section, fields) {
245
235
  for (const field of fields) {
246
236
  if (!(field in section))
247
237
  continue;
248
238
  const value = section[field];
249
239
  if (Array.isArray(value)) {
250
- section[field] = value.filter((item) => typeof item === "string" && item.length > 0);
240
+ section[field] = value.filter(isNonEmptyString);
251
241
  }
252
- else if (typeof value === "string" && value.length > 0) {
242
+ else if (isNonEmptyString(value)) {
253
243
  section[field] = [value];
254
244
  }
255
245
  else {
@@ -257,22 +247,6 @@ function normalizeLegacyStringLists(section, fields) {
257
247
  }
258
248
  }
259
249
  }
260
- function normalizeLegacyStringOrList(section, field) {
261
- if (!(field in section))
262
- return;
263
- const value = section[field];
264
- if (typeof value === "string") {
265
- if (value.length === 0)
266
- delete section[field];
267
- return;
268
- }
269
- if (!Array.isArray(value)) {
270
- delete section[field];
271
- return;
272
- }
273
- const normalized = value.filter((item) => typeof item === "string" && item.length > 0);
274
- section[field] = normalized;
275
- }
276
250
  function removeUnsupportedLegacyStrings(section, fields) {
277
251
  for (const field of fields) {
278
252
  if (field in section &&
@@ -281,15 +255,6 @@ function removeUnsupportedLegacyStrings(section, fields) {
281
255
  }
282
256
  }
283
257
  }
284
- function removeUnsupportedLegacyNullableStrings(section, fields) {
285
- for (const field of fields) {
286
- if (field in section &&
287
- section[field] !== null &&
288
- (typeof section[field] !== "string" || section[field].length === 0)) {
289
- delete section[field];
290
- }
291
- }
292
- }
293
258
  function validateCanonicalContract(manifest, findings) {
294
259
  const remote = manifest.scan.target.remote;
295
260
  if (remote !== undefined) {
@@ -338,15 +303,15 @@ function validateCanonicalContract(manifest, findings) {
338
303
  throw new ContractValidationError(`${locationContext}.path: expected a safe repository-relative POSIX path.`, { cause: error });
339
304
  }
340
305
  }
341
- const fingerprint = `codex-security/v1:sha256:${sha256Text([
306
+ const fingerprint = `codex-security/v1:sha256:${hash("sha256", [
342
307
  "codex-security/v1",
343
308
  manifest.scan.target.targetId,
344
309
  finding.ruleId,
345
310
  finding.identity.anchor,
346
311
  finding.identity.instance ?? "",
347
312
  ].join("\0"))}`;
348
- const findingId = `csf_${sha256Text(fingerprint).slice(0, 24)}`;
349
- const occurrenceId = `occ_${sha256Text([manifest.scan.id, fingerprint].join("\0")).slice(0, 24)}`;
313
+ const findingId = `csf_${hash("sha256", fingerprint).slice(0, 24)}`;
314
+ const occurrenceId = `occ_${hash("sha256", [manifest.scan.id, fingerprint].join("\0")).slice(0, 24)}`;
350
315
  if (finding.findingId !== findingId) {
351
316
  throw new ContractValidationError(`${context}.findingId: does not match derived fingerprint identity.`);
352
317
  }
@@ -358,9 +323,6 @@ function validateCanonicalContract(manifest, findings) {
358
323
  }
359
324
  }
360
325
  }
361
- function sha256Text(value) {
362
- return createHash("sha256").update(value, "utf8").digest("hex");
363
- }
364
326
  export async function requireScanFile(scanDirectory, relativePath, context, signal) {
365
327
  return (await requireCheckedScanFile(scanDirectory, relativePath, context, signal)).path;
366
328
  }
@@ -390,15 +352,11 @@ async function requireCheckedScanFile(scanDirectory, relativePath, context, sign
390
352
  }
391
353
  const parents = [{ path: scanDir, metadata: rootMetadata }];
392
354
  throwIfAborted(signal);
393
- if (!parents[0].metadata.isDirectory() ||
394
- parents[0].metadata.isSymbolicLink()) {
395
- throw new Error("unsafe scan directory");
396
- }
397
355
  for (const part of parts.slice(0, -1)) {
398
356
  current = join(current, part);
399
357
  const metadata = await lstat(current);
400
358
  throwIfAborted(signal);
401
- if (metadata.isSymbolicLink() || !metadata.isDirectory()) {
359
+ if (!metadata.isDirectory()) {
402
360
  throw new Error("unsafe parent");
403
361
  }
404
362
  parents.push({ path: current, metadata });
@@ -406,7 +364,7 @@ async function requireCheckedScanFile(scanDirectory, relativePath, context, sign
406
364
  const path = join(scanDir, ...parts);
407
365
  const metadata = await lstat(path);
408
366
  throwIfAborted(signal);
409
- if (metadata.isSymbolicLink() || !metadata.isFile()) {
367
+ if (!metadata.isFile()) {
410
368
  throw new ContractValidationError(`${context}: expected a regular non-symlink file.`);
411
369
  }
412
370
  const canonical = await realpath(path);
@@ -510,11 +468,14 @@ function validateExpectation(manifest, coverage, expectation, workbenchValidated
510
468
  }
511
469
  }
512
470
  if (requested.kind === "paths") {
513
- const actual = scan.scope.includePaths.map(safeScopePath);
514
- if (actual.length !== new Set(actual).size ||
515
- !sameSet(new Set(actual), new Set(requested.paths))) {
516
- throw new ContractValidationError("Manifest include paths do not match the requested path target.");
471
+ const actualPaths = scan.scope.includePaths.map(safeScopePath);
472
+ const actual = new Set(actualPaths);
473
+ if (actualPaths.length === actual.size) {
474
+ const expected = new Set(requested.paths);
475
+ if (actual.size === expected.size && actual.isSubsetOf(expected))
476
+ return;
517
477
  }
478
+ throw new ContractValidationError("Manifest include paths do not match the requested path target.");
518
479
  }
519
480
  }
520
481
  function expectedCoverageMode(target, mode) {
@@ -539,13 +500,10 @@ async function requireScanRoot(scanDirectory, signal) {
539
500
  const returned = await lstat(canonical);
540
501
  throwIfAborted(signal);
541
502
  if (!metadata.isDirectory() ||
542
- metadata.isSymbolicLink() ||
543
503
  !current.isDirectory() ||
544
- current.isSymbolicLink() ||
545
504
  metadata.dev !== current.dev ||
546
505
  metadata.ino !== current.ino ||
547
506
  !returned.isDirectory() ||
548
- returned.isSymbolicLink() ||
549
507
  metadata.dev !== returned.dev ||
550
508
  metadata.ino !== returned.ino) {
551
509
  throw new Error("not a directory");
@@ -573,7 +531,6 @@ async function verifyScanRoot(root, signal) {
573
531
  const current = await lstat(root.path);
574
532
  throwIfAborted(signal);
575
533
  if (!current.isDirectory() ||
576
- current.isSymbolicLink() ||
577
534
  current.dev !== root.metadata.dev ||
578
535
  current.ino !== root.metadata.ino) {
579
536
  throw new Error("scan directory changed while reading");
@@ -589,7 +546,7 @@ async function verifyScanRoot(root, signal) {
589
546
  function safeRelativePath(value, context) {
590
547
  const parts = value.split("/");
591
548
  if (value.trim().length === 0 ||
592
- !isWellFormedUnicode(value) ||
549
+ Buffer.from(value, "utf8").toString("utf8") !== value ||
593
550
  value === "." ||
594
551
  value.startsWith("/") ||
595
552
  /^[A-Za-z]:/.test(value) ||
@@ -622,7 +579,7 @@ async function readScanJson(scanDir, relativePath, documentDigests, signal, expe
622
579
  const file = await openCheckedScanFile(scanDir, relativePath, relativePath, signal, expectedRoot);
623
580
  try {
624
581
  const bytes = await file.readFile({ signal });
625
- documentDigests.set(relativePath, createHash("sha256").update(bytes).digest("hex"));
582
+ documentDigests.set(relativePath, hash("sha256", bytes));
626
583
  return parseJson(join(scanDir, relativePath), bytes);
627
584
  }
628
585
  catch (error) {
@@ -685,7 +642,7 @@ function validateParsedJson(value, context) {
685
642
  return;
686
643
  }
687
644
  if (typeof value === "string") {
688
- if (!isWellFormedUnicode(value)) {
645
+ if (!value.isWellFormed()) {
689
646
  throw new ContractValidationError(`${context}: expected well-formed Unicode JSON strings.`);
690
647
  }
691
648
  return;
@@ -698,16 +655,13 @@ function validateParsedJson(value, context) {
698
655
  }
699
656
  if (isRecord(value)) {
700
657
  for (const [key, item] of Object.entries(value)) {
701
- if (!isWellFormedUnicode(key)) {
658
+ if (!key.isWellFormed()) {
702
659
  throw new ContractValidationError(`${context}: expected well-formed Unicode JSON keys.`);
703
660
  }
704
661
  validateParsedJson(item, `${context}.<property>`);
705
662
  }
706
663
  }
707
664
  }
708
- function isWellFormedUnicode(value) {
709
- return Buffer.from(value, "utf8").toString("utf8") === value;
710
- }
711
665
  function createValidator() {
712
666
  // The plugin schemas are the immutable v0 contract. They are valid Draft
713
667
  // 2020-12 but intentionally omit redundant local `type` keywords that Ajv's
@@ -755,7 +709,6 @@ async function openCheckedScanFile(scanDir, relativePath, context, signal, expec
755
709
  const current = await lstat(parent.path);
756
710
  throwIfAborted(signal);
757
711
  if (!current.isDirectory() ||
758
- current.isSymbolicLink() ||
759
712
  current.dev !== parent.metadata.dev ||
760
713
  current.ino !== parent.metadata.ino) {
761
714
  throw new ContractValidationError(`${context}: checked parent changed before opening the file.`);
@@ -764,7 +717,6 @@ async function openCheckedScanFile(scanDir, relativePath, context, signal, expec
764
717
  const current = await lstat(checked.path);
765
718
  throwIfAborted(signal);
766
719
  if (!current.isFile() ||
767
- current.isSymbolicLink() ||
768
720
  current.dev !== checked.metadata.dev ||
769
721
  current.ino !== checked.metadata.ino) {
770
722
  throw new ContractValidationError(`${context}: checked file changed before reading.`);
@@ -792,7 +744,6 @@ export async function sameCheckedFileDevice(file, checked, opened, platform = pr
792
744
  ]);
793
745
  if (!openedIdentity.isFile() ||
794
746
  !checkedIdentity.isFile() ||
795
- checkedIdentity.isSymbolicLink() ||
796
747
  openedIdentity.ino !== checkedIdentity.ino) {
797
748
  return false;
798
749
  }
@@ -810,8 +761,7 @@ export async function sameCheckedFileDevice(file, checked, opened, platform = pr
810
761
  function throwIfAborted(signal) {
811
762
  if (!signal?.aborted)
812
763
  return;
813
- throw (signal.reason ??
814
- new DOMException("The operation was aborted.", "AbortError"));
764
+ throw abortReason(signal);
815
765
  }
816
766
  function validRfc3339DateTime(value) {
817
767
  const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-](\d{2}):(\d{2}))$/i.exec(value);
@@ -869,28 +819,19 @@ function schemaError(filename, errors) {
869
819
  .join(".");
870
820
  const keyword = first?.keyword ?? "unknown";
871
821
  const count = errors.length;
872
- const format = first?.params["format"];
873
- const detail = keyword === "format" && format === "date-time" ? "; date-time" : "";
874
- return new ContractValidationError(`${filename}:${location}: schema validation failed (${keyword}${detail}; ${count} ${count === 1 ? "error" : "errors"}).`);
822
+ return new ContractValidationError(`${filename}:${location}: schema validation failed (${keyword}${keyword === "format" && first?.params["format"] === "date-time" ? "; date-time" : ""}; ${count} ${count === 1 ? "error" : "errors"}).`);
875
823
  }
876
824
  function sameArray(left, right) {
877
825
  return (left.length === right.length &&
878
826
  left.every((value, index) => value === right[index]));
879
827
  }
880
- function sameSet(left, right) {
881
- return (left.size === right.size && [...left].every((value) => right.has(value)));
882
- }
883
- function isContained(root, candidate) {
884
- const child = relative(root, candidate);
885
- return (child === "" ||
886
- (child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child)));
887
- }
888
- function isRecord(value) {
889
- return typeof value === "object" && value !== null && !Array.isArray(value);
890
- }
891
828
  function nodeErrorCode(error) {
892
829
  return typeof error === "object" && error !== null && "code" in error
893
830
  ? String(error.code)
894
831
  : undefined;
895
832
  }
833
+ /** @internal */
834
+ export function sha256Text(value) {
835
+ return hash("sha256", value);
836
+ }
896
837
  //# sourceMappingURL=contract.js.map