@openai/codex-security 0.1.24 → 0.1.25

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 (105) hide show
  1. package/README.md +177 -19
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  5. package/_bundled_plugin/scripts/rank_preview.py +11 -1
  6. package/_bundled_plugin/scripts/workbench_cli.py +8 -1
  7. package/_bundled_plugin/scripts/workbench_db.py +44 -2
  8. package/_bundled_plugin/scripts/workbench_scan_history.py +374 -66
  9. package/_bundled_plugin/scripts/workbench_schema.py +15 -0
  10. package/_bundled_plugin/scripts/workbench_target.py +86 -12
  11. package/dist/api.d.ts +15 -2
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +330 -28
  14. package/dist/api.js.map +1 -1
  15. package/dist/auth.d.ts.map +1 -1
  16. package/dist/auth.js +35 -3
  17. package/dist/auth.js.map +1 -1
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.d.ts.map +1 -1
  20. package/dist/cli.js +86 -33
  21. package/dist/cli.js.map +1 -1
  22. package/dist/component-plan.d.ts.map +1 -1
  23. package/dist/component-plan.js +4 -2
  24. package/dist/component-plan.js.map +1 -1
  25. package/dist/component-scan.d.ts.map +1 -1
  26. package/dist/component-scan.js +21 -6
  27. package/dist/component-scan.js.map +1 -1
  28. package/dist/config.d.ts.map +1 -1
  29. package/dist/config.js +46 -2
  30. package/dist/config.js.map +1 -1
  31. package/dist/cost.d.ts +1 -0
  32. package/dist/cost.d.ts.map +1 -1
  33. package/dist/cost.js +23 -11
  34. package/dist/cost.js.map +1 -1
  35. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  36. package/dist/deduplication/checkpointed-review.js +2 -1
  37. package/dist/deduplication/checkpointed-review.js.map +1 -1
  38. package/dist/deduplication/codex-review.d.ts +3 -0
  39. package/dist/deduplication/codex-review.d.ts.map +1 -1
  40. package/dist/deduplication/codex-review.js +122 -36
  41. package/dist/deduplication/codex-review.js.map +1 -1
  42. package/dist/deduplication/deduplication-prompts.d.ts +4 -3
  43. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  44. package/dist/deduplication/deduplication-prompts.js +18 -9
  45. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  46. package/dist/deduplication/deduplication-reviewer.d.ts +2 -7
  47. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  48. package/dist/deduplication/deduplication-reviewer.js +46 -24
  49. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  50. package/dist/deduplication/deduplication.d.ts.map +1 -1
  51. package/dist/deduplication/deduplication.js +186 -23
  52. package/dist/deduplication/deduplication.js.map +1 -1
  53. package/dist/deduplication/scan.d.ts +9 -1
  54. package/dist/deduplication/scan.d.ts.map +1 -1
  55. package/dist/deduplication/scan.js +24 -7
  56. package/dist/deduplication/scan.js.map +1 -1
  57. package/dist/errors.d.ts +13 -0
  58. package/dist/errors.d.ts.map +1 -1
  59. package/dist/errors.js +7 -0
  60. package/dist/errors.js.map +1 -1
  61. package/dist/index.d.ts +5 -5
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +2 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/mock-scan.d.ts +4 -0
  66. package/dist/mock-scan.d.ts.map +1 -0
  67. package/dist/mock-scan.js +210 -0
  68. package/dist/mock-scan.js.map +1 -0
  69. package/dist/publish.d.ts.map +1 -1
  70. package/dist/publish.js +2 -2
  71. package/dist/publish.js.map +1 -1
  72. package/dist/runtime.d.ts +1 -0
  73. package/dist/runtime.d.ts.map +1 -1
  74. package/dist/runtime.js +49 -14
  75. package/dist/runtime.js.map +1 -1
  76. package/dist/scan-comparison.d.ts +11 -2
  77. package/dist/scan-comparison.d.ts.map +1 -1
  78. package/dist/scan-comparison.js +237 -39
  79. package/dist/scan-comparison.js.map +1 -1
  80. package/dist/scan-dashboard.d.ts +3 -1
  81. package/dist/scan-dashboard.d.ts.map +1 -1
  82. package/dist/scan-dashboard.js +70 -3
  83. package/dist/scan-dashboard.js.map +1 -1
  84. package/dist/scan-history-renderer.d.ts.map +1 -1
  85. package/dist/scan-history-renderer.js +21 -0
  86. package/dist/scan-history-renderer.js.map +1 -1
  87. package/dist/server/api.d.ts +6 -0
  88. package/dist/server/api.d.ts.map +1 -0
  89. package/dist/server/api.js +4 -0
  90. package/dist/server/api.js.map +1 -0
  91. package/dist/server/dashboard/app.css +1 -1
  92. package/dist/server/embeddings.d.ts +2 -1
  93. package/dist/server/embeddings.d.ts.map +1 -1
  94. package/dist/server/embeddings.js +8 -3
  95. package/dist/server/embeddings.js.map +1 -1
  96. package/dist/server/serve.d.ts.map +1 -1
  97. package/dist/server/serve.js +1 -1
  98. package/dist/server/serve.js.map +1 -1
  99. package/dist/targets.d.ts.map +1 -1
  100. package/dist/targets.js +3 -5
  101. package/dist/targets.js.map +1 -1
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +1 -1
  104. package/dist/version.js.map +1 -1
  105. package/package.json +9 -4
package/README.md CHANGED
@@ -186,6 +186,16 @@ Environment API keys apply to the current scan; only `login --with-api-key`
186
186
  saves them. Pass Codex access tokens on stdin to `login --with-access-token`.
187
187
  Access-token environment variables are not scan API keys.
188
188
 
189
+ SDK callers can select native command authentication through
190
+ `codexOverrides.model_providers.<id>.auth` and `model_provider` (including a
191
+ selected `profile`). Scans, comparisons, and deduplication reviews preserve
192
+ that selection without requiring an API key or replacing it with a stored
193
+ login. Codex executes the helper and renews its token. Helper paths and relative
194
+ `auth.cwd` values resolve from the supplied `CODEX_HOME` (default `~/.codex`),
195
+ not the source checkout; an absolute `auth.cwd` is preserved. Comparisons and
196
+ reviews also honor the selected command provider in that home's `config.toml`.
197
+ Configuration is passed to Codex for validation, including profile support.
198
+
189
199
  For other inference providers:
190
200
 
191
201
  ```bash
@@ -289,6 +299,41 @@ Scans are report-only by default. Set `--fail-on-severity high` to exit with
289
299
  `1` if a completed scan finds high or critical issues. Incomplete scans exit
290
300
  with `2`, writing available results to stdout and a coverage warning to stderr.
291
301
 
302
+ ### Generate mock scan results
303
+
304
+ Use `--mock` to populate a Standard scan with synthetic test data in seconds,
305
+ without Codex authentication or any LLM calls:
306
+
307
+ ```bash
308
+ codex-security scan /path/to/repository --mock
309
+ codex-security scan /path/to/repository --mock --output-dir /path/outside/repository/mock-results
310
+ ```
311
+
312
+ The SDK equivalent is `await security.run(repository, { mock: true })`.
313
+ Mock mode is off by default. It uses normal target validation, scan registration,
314
+ artifact finalization, reports, and local scan/finding history. Output directories,
315
+ archiving, JSON output, exports, and `--fail-on-severity` work as usual.
316
+ `--dry-run` only validates inputs; `--mock` saves a completed scan.
317
+
318
+ Each run contains 12 findings across all severity levels: eight stable findings
319
+ recur on subsequent scans of the same repository, and four have new identities
320
+ on every run. Two pairs describe the same root causes with different titles and
321
+ identities, providing inputs for deduplication testing. Mock scans skip automatic
322
+ LLM matching; existing identity-based history indexing still runs. Separate
323
+ comparison or deduplication commands retain their usual model behavior.
324
+
325
+ Titles, provenance, artifact metadata, and reports identify the results as
326
+ synthetic. Paths and code snippets are fictional and are never written into the
327
+ repository. Completion means fixture generation finished, not that the repository
328
+ was audited. Results enter the selected local state just like other scans; set
329
+ `CODEX_SECURITY_STATE_DIR` to a separate directory when creating disposable data.
330
+ Token usage is zero. `scans rerun` preserves mock mode.
331
+
332
+ Mock mode supports repository, path, and diff targets in Standard mode. It cannot
333
+ be combined with `--dry-run`, `--patch`, Deep mode, custom validation, or post-scan
334
+ prompts. Scan prompts and knowledge-base inputs do not change the fixtures, and
335
+ mock scans do not offer interactive patching.
336
+
292
337
  ### Attribute scans to end users
293
338
 
294
339
  When scanning on behalf of users, pass each user's stable hashed ID:
@@ -356,13 +401,22 @@ original IDs. Uncertain matches stay separate. `summary.json` records coverage
356
401
  and matching status; `report.md` links to component reports. Export and publish
357
402
  from the individual scan folders, not the combined summary.
358
403
 
404
+ Large comparisons use bounded batches that cover every earlier/later finding
405
+ pair. Overlapping confirmed groups are joined in code. Finding text is not
406
+ truncated; pairs above Codex's input limit leave matching incomplete.
407
+
359
408
  Use an empty output directory outside the project. Failed components don't
360
409
  stop others, but failures, incomplete coverage, or failed matching exit with
361
410
  `2`. Retry failed or incomplete components with
362
411
  `--components-file retry-components.json` and a new output directory.
412
+ The retry report covers only those components; it does not update the original
413
+ combined report.
363
414
 
364
415
  `--max-cost` applies per component, excluding planning and matching.
365
416
  `--model` and `--effort` also apply to matching; `--auth` applies throughout.
417
+ Planning and matching reject an ambient command provider that conflicts with
418
+ explicit `--auth chatgpt` or `--auth api-key`. A command provider explicitly
419
+ selected through SDK `codexOverrides` retains its authentication configuration.
366
420
  Use `--knowledge-base`, `--scan-prompt-file`, and `--post-scan-prompt-file` as for
367
421
  bulk scans.
368
422
 
@@ -472,6 +526,7 @@ restrictions.
472
526
  | Variable | Effect |
473
527
  | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
474
528
  | `OPENAI_API_KEY`, `CODEX_API_KEY` | Scan credentials; `OPENAI_API_KEY` wins if both are set. |
529
+ | `CODEX_SECURITY_EMBEDDINGS_URL` | Findings service endpoint; see [Embeddings and storage](#embeddings-and-storage). |
475
530
  | `CODEX_SECURITY_LINEAR_TEAM`, `CODEX_SECURITY_LINEAR_PROJECT` | Default team and project for completed-scan publication. |
476
531
  | `CODEX_SECURITY_LINEAR_API_KEY` | Personal API key for Linear patching and direct publication. |
477
532
  | `CODEX_SECURITY_LOG_LEVEL` | CLI-only; `debug` enables verbose diagnostics. |
@@ -513,6 +568,27 @@ discovery has finished, the scan returns a sealed partial report without more
513
568
  model calls and lists unvalidated candidates as follow-up work. Bulk scans
514
569
  apply the limit per repository attempt.
515
570
 
571
+ For a single scan in the interactive dashboard, reaching 80% of the limit
572
+ offers a higher **total** USD limit. Enter a larger amount to approve it, or
573
+ press Enter with an empty input or Escape to keep the current limit. The scan
574
+ continues running while you decide, and the existing limit remains enforced
575
+ until the increase is saved. Increases keep the same scan and accumulated cost;
576
+ they do not restart work or extend time or discovery limits. CI, JSON/JSONL,
577
+ `--headless`, and `--verbose` scans do not offer budget increases. If usage crosses the limit
578
+ before an increase is approved, the scan still stops.
579
+
580
+ SDK callers can supply `onBudgetApproaching({ maxCostUsd, cost, signal })` and
581
+ return a higher total limit, or `undefined` to keep the current limit. The
582
+ callback runs once per limit at 80% usage without blocking tracking or
583
+ execution. Its signal aborts when the scan stops or finishes model work; late
584
+ answers are ignored. Invalid increases or failures to save them leave the
585
+ existing limit in place and report a warning. `onCost(cost, maxCostUsd)` reports
586
+ the current limit, including after an approved increase.
587
+
588
+ These amounts estimate API-equivalent model usage, not ChatGPT subscription
589
+ allowance. Post-scan prompts run after scan cost tracking ends and are outside
590
+ this limit.
591
+
516
592
  ### Bulk scans
517
593
 
518
594
  Run `gh auth login`, then `npx @openai/codex-security bulk-scan` to select
@@ -1134,6 +1210,22 @@ const result = await deduplicateScan("scan_example_001", {
1134
1210
  console.log(result.duplicateGroups);
1135
1211
  ```
1136
1212
 
1213
+ For a complete, sealed scan directory that is not registered in local scan
1214
+ history, provide the repository checkout separately:
1215
+
1216
+ ```typescript
1217
+ import { deduplicateScanDirectory } from "@openai/codex-security";
1218
+
1219
+ const result = await deduplicateScanDirectory("/path/to/completed-scan", {
1220
+ repository: "/path/to/repository",
1221
+ findingsUrl: "http://127.0.0.1:3000",
1222
+ // expectedScanId: "scan_example_001",
1223
+ // allRepositories: true,
1224
+ // signal: controller.signal,
1225
+ });
1226
+ console.log(result.duplicateGroups);
1227
+ ```
1228
+
1137
1229
  The CLI and SDK return the same result:
1138
1230
 
1139
1231
  ```json
@@ -1231,11 +1323,16 @@ reviews or group writes. A publication whose acknowledgement was lost is retried
1231
1323
  using the service's existing idempotent upsert.
1232
1324
 
1233
1325
  Each validated screening and pair review is checkpointed locally,
1234
- including DISTINCT decisions. Every SAME checkpoint retains its required
1235
- `canonicalFindingId` and generated `mergedFinding`. The merged record must satisfy
1236
- the Finding schema and preserve the canonical finding ID. Validation still happens
1237
- through `review_validator.submit_decisions`; invalid submissions are corrected in
1238
- the same review conversation, and invalid or unfinished reviews are not cached.
1326
+ including DISTINCT decisions. Screening checkpoints retain pair recommendations
1327
+ and rationales under host-assigned pair slots bound to the original records.
1328
+ Every SAME pair-review checkpoint retains its
1329
+ required `canonicalFindingId` and generated `mergedFinding`; the merged record
1330
+ must satisfy the Finding schema and preserve the canonical finding ID. Validation
1331
+ still happens through `review_validator.submit_decisions`; invalid submissions
1332
+ are corrected in the same review conversation. A completed turn without an
1333
+ accepted submission receives one corrective turn in that same conversation.
1334
+ Transport, model, cancellation, and accepted `submit_error` failures are terminal.
1335
+ Invalid or unfinished reviews are not cached.
1239
1336
 
1240
1337
  Checkpoints bind to the exact original records and ordering, approved source path,
1241
1338
  Git revision and current file contents (including ignored files), repository scope,
@@ -1265,10 +1362,10 @@ use another workflow ID for a fresh review rather than changing that saved resul
1265
1362
  neighbors are rejected.
1266
1363
  3. Independently review each nominated pair once with `gpt-5.6-sol` at `xhigh`
1267
1364
  reasoning effort. Only accepted pairs contribute to duplicate groups.
1268
- 4. Group connected findings deterministically, treating accepted duplicate
1269
- pairs as transitive: if A matches B and B matches C, all three belong to one
1270
- group. There is no additional whole-group review. A mistaken accepted pair
1271
- can therefore join otherwise distinct findings.
1365
+ 4. Group accepted duplicate pairs transitively unless a Luna or Sol `DISTINCT`
1366
+ decision contradicts the resulting component. Contradicted components are
1367
+ split deterministically, preferring legal subgroups that preserve more
1368
+ accepted-pair support. There is no additional whole-group review.
1272
1369
  5. Post all accepted groups to `/v1/dedupe-groups`. Return a completed result
1273
1370
  only after the service accepts the write. An empty result requires no write.
1274
1371
 
@@ -1283,14 +1380,50 @@ and Codex state. Screening denies approval requests; final reviews use Codex's
1283
1380
  automatic approval reviewer. Web, plugins, and inherited MCP servers are disabled.
1284
1381
  Finding content never authorizes access to another target.
1285
1382
 
1383
+ Pair reviews cover exactly the two supplied findings. Linked parent tickets,
1384
+ duplicate targets, and related-ticket records are metadata, not additional
1385
+ findings to fetch or prerequisites for a verdict. An unsupplied duplicate target
1386
+ is neither automatically canonical nor an error; source-code investigation for
1387
+ the supplied pair remains allowed.
1388
+
1389
+ Incomplete supplied finding content can produce `DISTINCT` with the limitation
1390
+ explained. An execution, tool, or source-access blocker that prevents a required
1391
+ check instead uses `review_validator.submit_error` with a nonempty `reason`.
1392
+ That submission fails the review without a verdict or review checkpoint, so it
1393
+ cannot become a `DISTINCT` veto or a completed duplicate-group result. A failed
1394
+ optional lookup does not force failure or `DISTINCT` when other evidence suffices.
1395
+
1286
1396
  Decisions must arrive through the direct `review_validator.submit_decisions`
1287
1397
  tool; invalid submissions can be corrected in the same session. A final text
1288
- answer alone is insufficient. Every `SAME` decision, including screening
1289
- nominations, requires an assigned `canonicalFindingId` and a generated,
1290
- inclusive `mergedFinding`; missing or null values are rejected. Screening
1291
- canonicals must belong to the nominated pair. Sol reviews use only the complete
1292
- originals, never earlier merged findings. These review fields do not change
1293
- the command's ID-only result or stored findings.
1398
+ answer alone is insufficient. Luna screening returns a `SAME` or `DISTINCT`
1399
+ decision and rationale under each required host-assigned slot (`pair-1`,
1400
+ `pair-2`, and so on). The host binds each slot to its corresponding
1401
+ anchor-neighbor pair, so the model does not submit finding IDs. Luna does not
1402
+ select a canonical or generate a merged finding. Every
1403
+ Sol `SAME` decision requires an assigned `canonicalFindingId` and
1404
+ a generated, inclusive `mergedFinding`; missing or null values are rejected.
1405
+ Sol reviews use only the complete originals, never earlier model rationales or
1406
+ merged findings. These review fields do not change the command's ID-only result
1407
+ or stored findings.
1408
+
1409
+ Non-cancellation review failures throw `DeduplicationReviewError`. Its `metadata`
1410
+ contains only the review stage, model, failure category, attempt count, and a
1411
+ sanitized reason for diagnostics or an external support bundle; it does not
1412
+ contain findings, prompts, paths, thread IDs, or credentials.
1413
+
1414
+ If a completed turn has no accepted submission, whether it ended with text only
1415
+ or after rejected submissions, the runner sends one corrective instruction in
1416
+ the same conversation. This preserves the original assignment, source work, and
1417
+ tool feedback. Reviews are limited to two turns; `metadata.attempts` counts
1418
+ those turns (or the initial attempt if setup fails). Accepted results are not
1419
+ replayed. Cancellation, accepted `submit_error` reports, and model or transport
1420
+ failures remain terminal.
1421
+
1422
+ The SDK does not retain private review transcripts, subprocess stderr, or full
1423
+ provider/RPC error payloads, and ephemeral review state is removed after the
1424
+ session. The public metadata is a limited diagnostic summary, not a complete
1425
+ troubleshooting trace; it intentionally omits the original error cause. Private
1426
+ diagnostic retention is not currently implemented.
1294
1427
 
1295
1428
  Model calls run sequentially on the SDK/CLI host using its Codex sign-in or
1296
1429
  `OPENAI_API_KEY`/`CODEX_API_KEY`, with access to the configured models. Model
@@ -1350,6 +1483,18 @@ precedence over `CODEX_API_KEY`; remove the `OPENAI_API_KEY` entry if using
1350
1483
  `CODEX_API_KEY` instead. Listing and empty imports do not require a key.
1351
1484
  A Codex ChatGPT login is not an embedding API credential.
1352
1485
 
1486
+ Set `CODEX_SECURITY_EMBEDDINGS_URL` to override the full embeddings endpoint URL,
1487
+ including its path and any query parameters. Unset or empty values use
1488
+ `https://api.openai.com/v1/embeddings`. Export it before `codex-security serve`,
1489
+ or set it in `.env` for Docker Compose, which passes it to the service. For example:
1490
+
1491
+ ```bash
1492
+ CODEX_SECURITY_EMBEDDINGS_URL=https://embeddings.example.com/v1/embeddings codex-security serve
1493
+ ```
1494
+
1495
+ The configured endpoint receives the finding inputs and the API key as a bearer
1496
+ token and must support the same OpenAI embeddings request and response format.
1497
+
1353
1498
  The service calls the OpenAI embeddings API with `text-embedding-3-large` and
1354
1499
  1,536 dimensions. The complete finding JSON is tokenized using `js-tiktoken`'s
1355
1500
  bundled `cl100k_base` encoding. Long inputs are split without truncation;
@@ -1379,8 +1524,8 @@ The findings Compose configuration sets `HOST=0.0.0.0`, `PORT=3000`, and
1379
1524
  `CODEX_SECURITY_STATE_DIR=/state`. Keep port and volume mappings aligned if
1380
1525
  changing these settings. Compose binds only to host loopback; the API has no
1381
1526
  authentication. Use an authenticated TLS proxy before sharing access. Finding
1382
- JSON is sent to `api.openai.com` over HTTPS for embeddings; the database and
1383
- generated embeddings stay in the local volume.
1527
+ JSON is sent to the configured embeddings endpoint (`api.openai.com` over HTTPS
1528
+ by default); the database and generated embeddings stay in the local volume.
1384
1529
 
1385
1530
  ### Upgrades and backups
1386
1531
 
@@ -1423,7 +1568,7 @@ From a source checkout's `sdk/typescript` directory:
1423
1568
 
1424
1569
  ```bash
1425
1570
  pnpm install --frozen-lockfile
1426
- npm ci --prefix ../../plugins/codex-security/mcp-app
1571
+ pnpm --dir ../../plugins/codex-security/mcp-app install --frozen-lockfile
1427
1572
  pnpm run build:plugin
1428
1573
  pnpm run build
1429
1574
  node bin/codex-security.mjs serve --port 3000
@@ -1450,11 +1595,24 @@ migration that also imports known associations from stored scan occurrences.
1450
1595
  New scan findings retain their target associations when indexed locally.
1451
1596
  The server entrypoint selects the concrete
1452
1597
  embedder and store, so either can be replaced independently.
1598
+
1599
+ For renewable embeddings credentials, import `OpenAiFindingEmbedder`,
1600
+ `SqliteFindingsStore`, and `startFindingsServer` from
1601
+ `@openai/codex-security/server`. The embedder's first argument accepts a static
1602
+ key or `() => string | Promise<string>`. It calls the callback before every
1603
+ HTTP batch, including subsequent calls to `embed`; callers own token acquisition.
1604
+ Pass `fetch` as the second argument and
1605
+ `process.env.CODEX_SECURITY_EMBEDDINGS_URL || undefined` as the third to use
1606
+ the same full endpoint URL and default as `codex-security serve`. Importing the
1607
+ server API does not start a listener.
1608
+
1453
1609
  The local workflow lives under `src/deduplication/`. `FindingDeduplicator`
1454
1610
  receives a candidate API client and a `DeduplicationReviewer`, keeping grouping
1455
1611
  separate from HTTP and model transport. `CodexDeduplicationReviewer` owns prompts
1456
1612
  and result validation; `CodexReviewRunner` owns app-server sessions and cleanup.
1457
- `deduplicateScan` validates saved scan artifacts before running the workflow.
1613
+ `deduplicateScan` validates saved scan artifacts before running the workflow;
1614
+ `deduplicateScanDirectory` performs the same validation for an explicit sealed
1615
+ scan directory without consulting local scan history.
1458
1616
  The SDK reuses the existing Codex runtime and credentials without additional
1459
1617
  runtime dependencies.
1460
1618
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-security",
3
- "version": "0.1.79",
3
+ "version": "0.1.94",
4
4
  "description": "Codex Security workflows for security scans, analysis, and investigation.",
5
5
  "author": {
6
6
  "name": "OpenAI"
@@ -11,6 +11,7 @@ from pathlib import Path
11
11
  DEFAULT_PREVIEW_BYTES = 1024
12
12
  PREVIEW_HEAD_LINES = 12
13
13
  PREVIEW_SAMPLE_LINES = 10
14
+ _UTF16_BOMS = (b"\xff\xfe", b"\xfe\xff")
14
15
 
15
16
  TEXT_CODE_EXTENSIONS = {
16
17
  ".c",
@@ -43,6 +44,8 @@ TEXT_CODE_EXTENSIONS = {
43
44
  ".php",
44
45
  ".proto",
45
46
  ".ps1",
47
+ ".psd1",
48
+ ".psm1",
46
49
  ".py",
47
50
  ".rb",
48
51
  ".rs",
@@ -79,7 +82,14 @@ RUST_LIFETIME_RE = re.compile(r"'[A-Za-z_][A-Za-z0-9_]*")
79
82
  PHP_HEREDOC_RE = re.compile(r"<<<\s*['\"]?([A-Za-z_]\w*)['\"]?")
80
83
 
81
84
 
85
+ def _decode_source(data: bytes) -> str:
86
+ encoding = "utf-16" if data.startswith(_UTF16_BOMS) else "utf-8"
87
+ return data.decode(encoding, errors="ignore")
88
+
89
+
82
90
  def is_binary_sample(data: bytes) -> bool:
91
+ if data.startswith(_UTF16_BOMS):
92
+ return "\0" in _decode_source(data)
83
93
  return b"\0" in data
84
94
 
85
95
 
@@ -956,7 +966,7 @@ def preview_for(
956
966
  def preview_for_bytes(path: Path, data: bytes, preview_bytes: int) -> tuple[str, bool]:
957
967
  if is_binary_sample(data):
958
968
  return "", True
959
- text = data.decode("utf-8", errors="ignore")
969
+ text = _decode_source(data)
960
970
  outline = structural_outline(path, text)
961
971
  preview_lines = select_preview_lines(outline or text.splitlines())
962
972
  return fit_preview_lines(preview_lines, preview_bytes), False
@@ -160,6 +160,10 @@ def parse_args(description: str) -> argparse.Namespace:
160
160
  set_scan_thread.add_argument("--scan-id", required=True)
161
161
  set_scan_thread.add_argument("--thread-id", required=True)
162
162
 
163
+ set_scan_cost_limit = subparsers.add_parser("set-scan-cost-limit")
164
+ set_scan_cost_limit.add_argument("--scan-id", required=True)
165
+ set_scan_cost_limit.add_argument("--max-cost-usd", required=True, type=float)
166
+
163
167
  get_scan_recipe = subparsers.add_parser("get-scan-recipe")
164
168
  get_scan_recipe.add_argument("--scan-id", required=True)
165
169
 
@@ -169,7 +173,10 @@ def parse_args(description: str) -> argparse.Namespace:
169
173
  compare_scans.add_argument("--include-matching-inputs", action="store_true")
170
174
  compare_scans.add_argument("--require-matches", action="store_true")
171
175
 
172
- save_scan_comparison = subparsers.add_parser("save-scan-comparison")
176
+ save_scan_comparison = subparsers.add_parser(
177
+ "save-scan-comparison",
178
+ description="Comparison payload supports related findings.",
179
+ )
173
180
  save_scan_comparison.add_argument("--before-scan-id", required=True)
174
181
  save_scan_comparison.add_argument("--after-scan-id", required=True)
175
182
  matches = save_scan_comparison.add_mutually_exclusive_group(required=True)
@@ -7,6 +7,7 @@ import argparse
7
7
  import errno
8
8
  import hashlib
9
9
  import json
10
+ import math
10
11
  import os
11
12
  import re
12
13
  import sqlite3
@@ -1789,6 +1790,31 @@ def set_scan_thread(connection: sqlite3.Connection, args: argparse.Namespace) ->
1789
1790
  return {"scanId": scan["id"], "threadId": args.thread_id}
1790
1791
 
1791
1792
 
1793
+ def set_scan_cost_limit(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
1794
+ scan_id = require_uuid(args.scan_id, "scan-id")
1795
+ limit = args.max_cost_usd
1796
+ if not math.isfinite(limit) or limit <= 0:
1797
+ raise SystemExit("The scan cost limit must be a positive finite USD amount.")
1798
+ with scan_completion_lock(scan_id), connection:
1799
+ scan = require_scan(connection, scan_id)
1800
+ if scan["status"] != "running" or scan["recipe_json"] is None:
1801
+ raise SystemExit("Only a running CLI scan can increase its cost limit.")
1802
+ recipe = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
1803
+ previous = recipe.get("maxCostUsd")
1804
+ if (
1805
+ not isinstance(previous, (int, float))
1806
+ or isinstance(previous, bool)
1807
+ or limit <= previous
1808
+ ):
1809
+ raise SystemExit("The new cost limit must exceed the current limit.")
1810
+ recipe["maxCostUsd"] = limit
1811
+ connection.execute(
1812
+ "UPDATE scans SET recipe_json = ?, updated_at = ? WHERE id = ?",
1813
+ (json.dumps(recipe, allow_nan=False), now(), scan["id"]),
1814
+ )
1815
+ return {"scanId": scan["id"], "maxCostUsd": limit}
1816
+
1817
+
1792
1818
  def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
1793
1819
  if len(value.encode("utf-8")) > SCAN_RECIPE_MAX_BYTES:
1794
1820
  raise SystemExit("Scan launch recipe must be no larger than 256 KiB.")
@@ -2722,9 +2748,13 @@ def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> d
2722
2748
  values,
2723
2749
  ).fetchone()[0]
2724
2750
  next_offset = args.offset + len(rows)
2751
+ relations = scan_history.finding_relations(connection, scan["id"], (row["id"] for row in rows))
2725
2752
  return {
2726
2753
  "findingsPage": {
2727
- "findings": [finding_result(connection, scan, row) for row in rows],
2754
+ "findings": [
2755
+ finding_result(connection, scan, row, related=relations.get(row["id"], []))
2756
+ for row in rows
2757
+ ],
2728
2758
  "limit": limit,
2729
2759
  "nextOffset": next_offset if next_offset < total else None,
2730
2760
  "offset": args.offset,
@@ -2817,6 +2847,9 @@ def scan_result(
2817
2847
  "maximum": independent_reviews["maximum"],
2818
2848
  "consolidating": independent_reviews["consolidating"],
2819
2849
  }
2850
+ relations = scan_history.finding_relations(
2851
+ connection, scan["id"], (row["id"] for row in occurrence_rows)
2852
+ )
2820
2853
  return {
2821
2854
  "artifacts": artifacts,
2822
2855
  "canceledAt": scan["canceled_at"],
@@ -2824,7 +2857,10 @@ def scan_result(
2824
2857
  "contract": scan_contract(scan),
2825
2858
  "continuationThreadId": scan["continuation_thread_id"],
2826
2859
  "failureMessage": scan["failure_message"],
2827
- "findings": [finding_result(connection, scan, row) for row in occurrence_rows],
2860
+ "findings": [
2861
+ finding_result(connection, scan, row, related=relations.get(row["id"], []))
2862
+ for row in occurrence_rows
2863
+ ],
2828
2864
  "findingCount": finding_count,
2829
2865
  "findingsTruncated": finding_count > len(occurrence_rows),
2830
2866
  "severityCounts": severity_counts,
@@ -2974,6 +3010,8 @@ def finding_result(
2974
3010
  connection: sqlite3.Connection,
2975
3011
  scan: sqlite3.Row,
2976
3012
  occurrence: sqlite3.Row,
3013
+ *,
3014
+ related: list[dict[str, Any]],
2977
3015
  ) -> dict[str, Any]:
2978
3016
  details = bounded_finding_details(read_finding_details(occurrence["details_json"]))
2979
3017
  confidence = details.get("confidence")
@@ -3038,6 +3076,8 @@ def finding_result(
3038
3076
  result["matches"] = matches
3039
3077
  result["knownSince"] = known_since
3040
3078
  result["knownScanIds"] = known_scan_ids
3079
+ if related:
3080
+ result["related"] = related
3041
3081
  result.pop("artifactPaths", None)
3042
3082
  source_excerpt = finding_source_excerpt(scan, target, locations)
3043
3083
  if source_excerpt:
@@ -3468,6 +3508,8 @@ def main() -> None:
3468
3508
  result = register_cli_scan(connection, args)
3469
3509
  elif args.command == "set-scan-thread":
3470
3510
  result = set_scan_thread(connection, args)
3511
+ elif args.command == "set-scan-cost-limit":
3512
+ result = set_scan_cost_limit(connection, args)
3471
3513
  elif args.command == "get-scan-recipe":
3472
3514
  result = get_scan_recipe(connection, args)
3473
3515
  elif args.command == "compare-scans":