@openai/codex-security 0.1.4 → 0.1.5
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 +48 -5
- package/_bundled_plugin/examples/completed-scan/findings.json +6 -0
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
- package/_bundled_plugin/references/finding-detail-fields.md +10 -2
- package/_bundled_plugin/scripts/finalize_scan_contract.py +18 -0
- package/_bundled_plugin/scripts/workbench_db.py +54 -1
- package/_bundled_plugin/scripts/workbench_target.py +14 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +118 -22
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +262 -44
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +260 -113
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +14 -0
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +57 -14
- package/dist/cost.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +2 -7
- package/dist/multiscan.js.map +1 -1
- package/dist/runtime.d.ts +24 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +202 -21
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -380,7 +380,9 @@ including cached input and cache writes; fees and surcharges are not included.
|
|
|
380
380
|
|
|
381
381
|
Use `--max-cost USD` to stop a scan, including its delegated workers, when its
|
|
382
382
|
running cost exceeds the limit. Partial results are preserved. Requests
|
|
383
|
-
already in progress can finish above the limit.
|
|
383
|
+
already in progress can finish above the limit. Cost tracking accepts Codex
|
|
384
|
+
session events up to 1 MiB; an oversized event stops the scan because its
|
|
385
|
+
running cost can no longer be verified safely.
|
|
384
386
|
|
|
385
387
|
Run `npx @openai/codex-security scan --help` or `npx @openai/codex-security bulk-scan --help`
|
|
386
388
|
for the complete CLI references.
|
|
@@ -441,10 +443,10 @@ cause; `scans match --all` matches all completed scans of the current repository
|
|
|
441
443
|
including other worktrees and clones. Saved matches appear in `scans show` and
|
|
442
444
|
are reused unless `--force` is passed. Scans without sealed artifacts are skipped.
|
|
443
445
|
|
|
444
|
-
`scans compare BEFORE_SCAN_ID AFTER_SCAN_ID`
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
their original scope.
|
|
446
|
+
`scans compare BEFORE_SCAN_ID AFTER_SCAN_ID` automatically matches findings by
|
|
447
|
+
root cause, reuses saved matches, and reports findings as new, persisting,
|
|
448
|
+
reopened, resolved, or unknown. Missing findings are not treated as resolved when
|
|
449
|
+
the later scan is incomplete or does not cover their original scope.
|
|
448
450
|
|
|
449
451
|
The CLI uses [Incur](https://github.com/wevm/incur) for agent-friendly discovery
|
|
450
452
|
and structured output. Inspect the command manifest with `--llms`, inspect a
|
|
@@ -514,6 +516,47 @@ Progress remains on stderr so JSON output stays machine readable. Network
|
|
|
514
516
|
failures and rate limits remain retryable; definitive authentication and model
|
|
515
517
|
authorization failures stop immediately.
|
|
516
518
|
|
|
519
|
+
## Containerized bulk scans
|
|
520
|
+
|
|
521
|
+
Create `repositories.csv` with one full, immutable Git commit per repository:
|
|
522
|
+
|
|
523
|
+
```csv
|
|
524
|
+
id,repository,revision
|
|
525
|
+
payments,https://github.com/example/payments.git,0123456789abcdef0123456789abcdef01234567
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
Once the approved image has been published, prepare private results and
|
|
529
|
+
authentication directories, sign in, and run the Docker Compose configuration
|
|
530
|
+
from the root of the Codex Security repository:
|
|
531
|
+
|
|
532
|
+
```bash
|
|
533
|
+
mkdir -p results state
|
|
534
|
+
chmod 700 results state
|
|
535
|
+
export CODEX_SECURITY_USER="$(id -u):$(id -g)"
|
|
536
|
+
export CODEX_SECURITY_IMAGE=ghcr.io/openai/codex-security:0.1.4
|
|
537
|
+
docker compose pull codex-security
|
|
538
|
+
docker compose run --rm codex-security login --device-auth
|
|
539
|
+
docker compose run --rm codex-security
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
Reports and resumable scan results are written to `results/`; the reusable
|
|
543
|
+
device login remains in `state/`. For unattended scans, set `OPENAI_API_KEY`
|
|
544
|
+
or `CODEX_API_KEY` instead. Set `GH_TOKEN` or `GITHUB_TOKEN` for private
|
|
545
|
+
GitHub repositories.
|
|
546
|
+
|
|
547
|
+
On Ubuntu hosts that restrict unprivileged user namespaces, an administrator
|
|
548
|
+
can install the optional, narrowly scoped AppArmor profile once:
|
|
549
|
+
|
|
550
|
+
```bash
|
|
551
|
+
sudo install -m 0644 docker/codex-security.apparmor /etc/apparmor.d/codex-security-container
|
|
552
|
+
sudo apparmor_parser -r -W /etc/apparmor.d/codex-security-container
|
|
553
|
+
docker compose -f compose.yaml -f compose.apparmor.yaml run --rm codex-security
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
The override preserves the nonroot user, dropped capabilities,
|
|
557
|
+
no-new-privileges, and hardened seccomp policy. Other Docker hosts do not need
|
|
558
|
+
the profile or override.
|
|
559
|
+
|
|
517
560
|
## Local security model
|
|
518
561
|
|
|
519
562
|
Codex Security runs with your local operating-system permissions. Scan only
|
|
@@ -42,6 +42,12 @@
|
|
|
42
42
|
"remediation": "Normalize destinations and reject entries that escape the extraction root.",
|
|
43
43
|
"validation": null,
|
|
44
44
|
"attackPath": null,
|
|
45
|
+
"remediationTests": [
|
|
46
|
+
"Assert that extracting an archive entry named `../escape.txt` fails without writing outside the extraction root."
|
|
47
|
+
],
|
|
48
|
+
"preventiveControls": [
|
|
49
|
+
"Route all archive extraction through one helper that normalizes and validates destination paths."
|
|
50
|
+
],
|
|
45
51
|
"provenance": {
|
|
46
52
|
"source": "local_plugin"
|
|
47
53
|
},
|
|
@@ -23,7 +23,7 @@ The finding detail view is a decision-focused projection of the canonical findin
|
|
|
23
23
|
- dataflow source, meaningful transformations, dangerous sink, and concrete outcome;
|
|
24
24
|
- realistic attacker, entry point, access requirements, preconditions, and attacker outcome;
|
|
25
25
|
- severity rationale plus the specific evidence that would raise or lower the rating;
|
|
26
|
-
- the minimal remediation invariant
|
|
26
|
+
- the minimal remediation invariant (`remediation`, a single string), plus `remediationTests` and `preventiveControls`, each an array of short strings with one regression test or preventive control per entry.
|
|
27
27
|
|
|
28
28
|
Keep background exposition, alternate exploit research, full PoC instructions, representative command output, and long source walkthroughs in the detailed write-up. Do not copy them into canonical fields merely to make the workspace report longer. The workspace should stay self-contained enough to support triage while avoiding duplicated or speculative prose.
|
|
29
29
|
|
|
@@ -155,7 +155,15 @@ The following shape shows how to encode the `environment/add` reserved-environme
|
|
|
155
155
|
"limitations": [
|
|
156
156
|
"This overwrite does not directly execute code on the victim host."
|
|
157
157
|
]
|
|
158
|
-
}
|
|
158
|
+
},
|
|
159
|
+
"remediation": "Reuse the startup reserved-ID check inside `EnvironmentManager::upsert_environment()` so the runtime mutation path rejects the reserved `local` identifier.",
|
|
160
|
+
"remediationTests": [
|
|
161
|
+
"Assert that `environment/add` with `environmentId: \"local\"` returns a protocol error.",
|
|
162
|
+
"Assert that `default_environment()` still resolves the manager-owned local runtime after a rejected upsert."
|
|
163
|
+
],
|
|
164
|
+
"preventiveControls": [
|
|
165
|
+
"Centralize reserved-identifier validation so every environment mutation path shares one guard."
|
|
166
|
+
]
|
|
159
167
|
}
|
|
160
168
|
```
|
|
161
169
|
|
|
@@ -796,6 +796,12 @@ def _recover_unsealed_findings(
|
|
|
796
796
|
writeup_schema = _require_dict(
|
|
797
797
|
finding_properties, "writeup", "findings.schema.properties.findings.items.properties"
|
|
798
798
|
)
|
|
799
|
+
auxiliary_schemas = {
|
|
800
|
+
name: _require_dict(
|
|
801
|
+
finding_properties, name, "findings.schema.properties.findings.items.properties"
|
|
802
|
+
)
|
|
803
|
+
for name in ("remediationTests", "preventiveControls")
|
|
804
|
+
}
|
|
799
805
|
scan = _require_dict(manifest, "scan", "manifest")
|
|
800
806
|
scan_id = _require_str(scan, "id", "manifest.scan")
|
|
801
807
|
if findings.get("scanId") != scan_id:
|
|
@@ -854,6 +860,18 @@ def _recover_unsealed_findings(
|
|
|
854
860
|
except ContractError as exc:
|
|
855
861
|
finding.pop("writeup")
|
|
856
862
|
warnings.append(f"Skipped malformed writeup for finding {index + 1}: {exc}.")
|
|
863
|
+
for auxiliary, auxiliary_schema in auxiliary_schemas.items():
|
|
864
|
+
if auxiliary not in finding:
|
|
865
|
+
continue
|
|
866
|
+
try:
|
|
867
|
+
_validate_schema_node(
|
|
868
|
+
finding[auxiliary], auxiliary_schema, f"{context}.{auxiliary}"
|
|
869
|
+
)
|
|
870
|
+
except ContractError as exc:
|
|
871
|
+
finding.pop(auxiliary)
|
|
872
|
+
warnings.append(
|
|
873
|
+
f"Skipped malformed {auxiliary} for finding {index + 1}: {exc}."
|
|
874
|
+
)
|
|
857
875
|
_validate_schema_node(finding, finding_schema, context)
|
|
858
876
|
except ContractError as exc:
|
|
859
877
|
warning = f"Skipped malformed finding {index + 1}: {exc}."
|
|
@@ -1414,7 +1414,28 @@ def complete_scan_locked(
|
|
|
1414
1414
|
completion_timestamp = now()
|
|
1415
1415
|
completion_binding = workbench_completion_binding(scan, completion_timestamp)
|
|
1416
1416
|
if scan["recipe_json"] is not None:
|
|
1417
|
-
|
|
1417
|
+
draft_artifacts: dict[str, Path] = {}
|
|
1418
|
+
missing_drafts = []
|
|
1419
|
+
for file_name in (
|
|
1420
|
+
ARTIFACTS["manifest"],
|
|
1421
|
+
ARTIFACTS["findings"],
|
|
1422
|
+
ARTIFACTS["coverage"],
|
|
1423
|
+
):
|
|
1424
|
+
try:
|
|
1425
|
+
(scan_dir / file_name).lstat()
|
|
1426
|
+
except FileNotFoundError:
|
|
1427
|
+
missing_drafts.append(file_name)
|
|
1428
|
+
continue
|
|
1429
|
+
draft_path = artifact_path(scan_dir, file_name, required=True)
|
|
1430
|
+
if draft_path is not None:
|
|
1431
|
+
draft_artifacts[file_name] = draft_path
|
|
1432
|
+
if missing_drafts:
|
|
1433
|
+
raise SystemExit(
|
|
1434
|
+
"Scan agent did not create required draft artifacts: "
|
|
1435
|
+
f"{', '.join(missing_drafts)}. Check that the scan agent can run shell "
|
|
1436
|
+
"commands and write to the scan directory before retrying."
|
|
1437
|
+
)
|
|
1438
|
+
manifest = read_json_object(draft_artifacts[ARTIFACTS["manifest"]])
|
|
1418
1439
|
manifest_scan = manifest.get("scan")
|
|
1419
1440
|
if isinstance(manifest_scan, dict) and manifest_scan.get("sealedAt") is not None:
|
|
1420
1441
|
completion_binding["startedAt"] = manifest_scan.get("startedAt")
|
|
@@ -3469,6 +3490,38 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
|
3469
3490
|
scan_dir
|
|
3470
3491
|
):
|
|
3471
3492
|
raise SystemExit("Scan directory must be an existing canonical non-symlink directory.")
|
|
3493
|
+
# Re-check privacy on every resolution so a mid-scan rename/replace under a
|
|
3494
|
+
# shared parent cannot substitute another user's forged artifact tree.
|
|
3495
|
+
if os.name != "nt":
|
|
3496
|
+
if stat.S_IMODE(metadata.st_mode) & 0o077:
|
|
3497
|
+
raise SystemExit(
|
|
3498
|
+
"Scan directory must not be accessible to other users (chmod 700)."
|
|
3499
|
+
)
|
|
3500
|
+
geteuid = getattr(os, "geteuid", None)
|
|
3501
|
+
effective_uid = geteuid() if geteuid is not None else None
|
|
3502
|
+
if effective_uid is not None and metadata.st_uid != effective_uid:
|
|
3503
|
+
raise SystemExit("Scan directory must be owned by the current user.")
|
|
3504
|
+
for parent in scan_dir.parents:
|
|
3505
|
+
try:
|
|
3506
|
+
parent_metadata = parent.lstat()
|
|
3507
|
+
except OSError as exc:
|
|
3508
|
+
raise SystemExit("Scan output parent could not be inspected.") from exc
|
|
3509
|
+
if not stat.S_ISDIR(parent_metadata.st_mode) or stat.S_ISLNK(
|
|
3510
|
+
parent_metadata.st_mode
|
|
3511
|
+
):
|
|
3512
|
+
raise SystemExit("Scan output parent must be a non-symlink directory.")
|
|
3513
|
+
if effective_uid is not None and parent_metadata.st_uid not in {
|
|
3514
|
+
0,
|
|
3515
|
+
effective_uid,
|
|
3516
|
+
}:
|
|
3517
|
+
raise SystemExit("Scan output parent must have a trusted owner.")
|
|
3518
|
+
if (
|
|
3519
|
+
stat.S_IMODE(parent_metadata.st_mode) & 0o022
|
|
3520
|
+
and not parent_metadata.st_mode & stat.S_ISVTX
|
|
3521
|
+
):
|
|
3522
|
+
raise SystemExit(
|
|
3523
|
+
"Scan output parent must not be group- or world-writable without the sticky bit."
|
|
3524
|
+
)
|
|
3472
3525
|
return scan_dir
|
|
3473
3526
|
|
|
3474
3527
|
|
|
@@ -143,6 +143,13 @@ def worktree_content_digest_for_context(
|
|
|
143
143
|
b"untracked-content",
|
|
144
144
|
os.fsencode(os.readlink(path)),
|
|
145
145
|
)
|
|
146
|
+
elif stat.S_ISDIR(metadata.st_mode):
|
|
147
|
+
update_digest_field(digest, b"untracked-kind", b"directory")
|
|
148
|
+
update_digest_field(
|
|
149
|
+
digest,
|
|
150
|
+
b"untracked-content",
|
|
151
|
+
directory_content_digest(path.resolve()).encode(),
|
|
152
|
+
)
|
|
146
153
|
elif stat.S_ISREG(metadata.st_mode):
|
|
147
154
|
content_digest = hashlib.sha256()
|
|
148
155
|
content_size = 0
|
|
@@ -419,7 +426,13 @@ def copy_git_worktree_files(source: Path, destination: Path, excluded: tuple[Pat
|
|
|
419
426
|
destination_path.symlink_to(os.readlink(source_path))
|
|
420
427
|
elif stat.S_ISREG(metadata.st_mode):
|
|
421
428
|
shutil.copy2(source_path, destination_path, follow_symlinks=False)
|
|
422
|
-
elif
|
|
429
|
+
elif stat.S_ISDIR(metadata.st_mode):
|
|
430
|
+
nested_git_dir = git_output(source_path, "rev-parse", "--absolute-git-dir")
|
|
431
|
+
if nested_git_dir is None:
|
|
432
|
+
raise SystemExit(f"Could not inspect nested Git working tree: {relative}")
|
|
433
|
+
copy_git_worktree_files(source_path, destination_path, excluded)
|
|
434
|
+
(destination_path / ".git").write_text(f"gitdir: {nested_git_dir}\n")
|
|
435
|
+
else:
|
|
423
436
|
raise SystemExit(f"Unsupported Git working-tree file type: {relative}")
|
|
424
437
|
copied_target = destination if pathspec == "." else destination / pathspec
|
|
425
438
|
copied_target.mkdir(parents=True, exist_ok=True)
|
package/dist/api.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export declare function runScanEvents(options: ScanEventRunOptions): Promise<Sca
|
|
|
110
110
|
export declare function scanAuthentication(environment: ProcessEnvironment, auth?: ScanAuthMode): ScanAuthentication;
|
|
111
111
|
export declare function classifyConnectionFailure(error: unknown): "rate_limited" | "unauthorized" | "forbidden" | "network_error" | "timeout" | "unknown";
|
|
112
112
|
export declare function scanRuntimeCodexConfig(config: JsonObject, stateDirectory: string, protectedCredentialHome?: string): JsonObject;
|
|
113
|
-
export declare function scanPreflightCodexConfig(config: JsonObject): JsonObject;
|
|
113
|
+
export declare function scanPreflightCodexConfig(config: JsonObject, activeProjectPath?: string): JsonObject;
|
|
114
114
|
export declare function environmentValue(environment: ProcessEnvironment, requested: string): string | undefined;
|
|
115
115
|
export {};
|
|
116
116
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAOA,OAAO,EAEL,gBAAgB,EAGhB,KAAK,aAAa,EACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAqC,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;
|
|
1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CACxE;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,UAAU,CAAC,CA0HrB;AAgLD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,kBAAkB,EAC/B,IAAI,GAAE,YAAqB,GAC1B,kBAAkB,CAcpB;AAsGD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GAEZ,cAAc,GACd,cAAc,GACd,WAAW,GACX,eAAe,GACf,SAAS,GACT,SAAS,CAmCZ;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,UAAU,EAClB,cAAc,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,UAAU,CAwBZ;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,UAAU,EAClB,iBAAiB,CAAC,EAAE,MAAM,GACzB,UAAU,CA0JZ;AAmDD,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,kBAAkB,EAC/B,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAcpB"}
|
package/dist/api.js
CHANGED
|
@@ -8,7 +8,7 @@ import { accountStatus, CodexLoginHandle, loginApiKey as persistApiKey, logout a
|
|
|
8
8
|
import { mergedCodexConfig, scanModelConfiguration, writeCodexConfig, } from "./config.js";
|
|
9
9
|
import { estimateScanCost, ScanCostTracker } from "./cost.js";
|
|
10
10
|
import { loadContract, requireScanFile, } from "./contract.js";
|
|
11
|
-
import { AuthenticationRequiredError, CodexSecurityError, IncompleteScanError, OutputDirectoryError, OutputInsideProtectedRootError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
11
|
+
import { AuthenticationRequiredError, CodexSecurityError, IncompleteScanError, OutputDirectoryError, OutputInsideProtectedRootError, redactedErrorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
12
12
|
import { prepareKnowledgeBase, } from "./knowledge-base.js";
|
|
13
13
|
import { ScanResult } from "./result.js";
|
|
14
14
|
import { workerStatusFromEvent, } from "./worker-progress.js";
|
|
@@ -85,6 +85,7 @@ export class CodexSecurity {
|
|
|
85
85
|
let knowledgeBase = null;
|
|
86
86
|
let costTracker = null;
|
|
87
87
|
let releaseCredentialHome = null;
|
|
88
|
+
let scanFailure = false;
|
|
88
89
|
let completionCost = null;
|
|
89
90
|
let activeScan = null;
|
|
90
91
|
const workbench = this.#dependencies.runWorkbench ?? runWorkbench;
|
|
@@ -126,6 +127,10 @@ export class CodexSecurity {
|
|
|
126
127
|
this.#dependencies.prepareRuntime === undefined) {
|
|
127
128
|
await this.#refreshPersistentRuntime(runtime, scanEnvironment, signal);
|
|
128
129
|
}
|
|
130
|
+
const effectiveConfig = runtime.effectiveConfig ?? (await mergedCodexConfig(this.config));
|
|
131
|
+
if (runtime.configPath !== undefined) {
|
|
132
|
+
await writeCodexConfig(runtime.configPath, scanPreflightCodexConfig(effectiveConfig, repo));
|
|
133
|
+
}
|
|
129
134
|
const runtimeHome = await realpath(runtime.codexHome);
|
|
130
135
|
requireOutputOutsideRepository(protectedRoot, runtimeHome, "runtime");
|
|
131
136
|
if (options.expectedPluginVersion !== undefined &&
|
|
@@ -202,7 +207,6 @@ export class CodexSecurity {
|
|
|
202
207
|
mode,
|
|
203
208
|
pluginVersion: runtime.plugin.version,
|
|
204
209
|
};
|
|
205
|
-
const effectiveConfig = runtime.effectiveConfig ?? (await mergedCodexConfig(this.config));
|
|
206
210
|
const { model } = scanModelConfiguration(effectiveConfig);
|
|
207
211
|
validateScanCostLimit(options.maxCostUsd, model);
|
|
208
212
|
const tracker = new ScanCostTracker({
|
|
@@ -219,7 +223,7 @@ export class CodexSecurity {
|
|
|
219
223
|
onError: (error) => costAbortController.abort(error),
|
|
220
224
|
});
|
|
221
225
|
costTracker = tracker;
|
|
222
|
-
const recipe = scanRecipe(repo, normalized, mode, expectation.repositoryRevision, runtime.plugin.version, effectiveConfig, options.failureSeverity, knowledgeBase?.sources, options.maxCostUsd);
|
|
226
|
+
const recipe = scanRecipe(repo, protectedRoot, normalized, mode, expectation.repositoryRevision, runtime.plugin.version, effectiveConfig, options.failureSeverity, knowledgeBase?.sources, options.maxCostUsd);
|
|
223
227
|
const workbenchOptions = {
|
|
224
228
|
python,
|
|
225
229
|
pluginRoot: runtime.plugin.pluginRoot,
|
|
@@ -433,6 +437,9 @@ export class CodexSecurity {
|
|
|
433
437
|
return result;
|
|
434
438
|
}
|
|
435
439
|
catch (error) {
|
|
440
|
+
// Recorded first: everything below can throw a different error for this same failed
|
|
441
|
+
// scan, and cleanup must treat all of those as a failure it is not allowed to mask.
|
|
442
|
+
scanFailure = true;
|
|
436
443
|
const snapshot = await costTracker?.stop().catch(() => null);
|
|
437
444
|
const failure = signal.reason instanceof ScanCostLimitExceededError
|
|
438
445
|
? signal.reason
|
|
@@ -443,10 +450,10 @@ export class CodexSecurity {
|
|
|
443
450
|
"fail-scan",
|
|
444
451
|
"--scan-id",
|
|
445
452
|
activeScan.id,
|
|
453
|
+
// Redact before truncating: the stored message is read back by
|
|
454
|
+
// `scans show` and travels inside the results directory.
|
|
446
455
|
"--message",
|
|
447
|
-
(failure
|
|
448
|
-
? failure.message
|
|
449
|
-
: String(failure)).slice(0, 2400),
|
|
456
|
+
redactedErrorMessage(failure).slice(0, 2400),
|
|
450
457
|
...(snapshot?.cost
|
|
451
458
|
? ["--cost-json", JSON.stringify(snapshot.cost)]
|
|
452
459
|
: []),
|
|
@@ -462,14 +469,41 @@ export class CodexSecurity {
|
|
|
462
469
|
throw failure;
|
|
463
470
|
}
|
|
464
471
|
finally {
|
|
472
|
+
// Removing the temporary scan inputs is best effort. A throw here would replace the
|
|
473
|
+
// outcome the try and catch blocks already produced, so these failures are reported
|
|
474
|
+
// as warnings: a scan that failed has to say why it failed, not why its temporary
|
|
475
|
+
// files outlived it. The whole step is guarded so that a cleanup which rejects, or
|
|
476
|
+
// throws synchronously, still cannot skip the credential lock release below.
|
|
465
477
|
try {
|
|
466
|
-
await Promise.
|
|
478
|
+
for (const cleanup of await Promise.allSettled([
|
|
467
479
|
knowledgeBase?.cleanup(),
|
|
468
480
|
removeTargetPathsFile(targetPathsFile),
|
|
469
|
-
])
|
|
481
|
+
])) {
|
|
482
|
+
if (cleanup.status === "rejected") {
|
|
483
|
+
warnCleanupFailed(options, cleanup.reason);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
catch (error) {
|
|
488
|
+
warnCleanupFailed(options, error);
|
|
470
489
|
}
|
|
471
490
|
finally {
|
|
472
|
-
|
|
491
|
+
// Releasing the credential home lock is not best effort, so it keeps its own
|
|
492
|
+
// finally and runs even if reporting the failures above went wrong. The release
|
|
493
|
+
// only marks itself done once the lock directory is gone, so a failure leaves an
|
|
494
|
+
// owner.json naming this still-running process; recoverStaleCredentialHomeLock
|
|
495
|
+
// then refuses to reclaim it because that pid is alive, and later scans in this
|
|
496
|
+
// process wait on a lock nothing frees. Reporting success while leaving the client
|
|
497
|
+
// in that state is worse than failing, so the failure is only downgraded to a
|
|
498
|
+
// warning when the scan already failed and that error is the one worth keeping.
|
|
499
|
+
try {
|
|
500
|
+
await releaseCredentialHome?.();
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
if (!scanFailure)
|
|
504
|
+
throw error;
|
|
505
|
+
warnCleanupFailed(options, error);
|
|
506
|
+
}
|
|
473
507
|
}
|
|
474
508
|
}
|
|
475
509
|
}
|
|
@@ -750,6 +784,20 @@ export async function initialCredentialsAvailable(environment, ambientHome, isol
|
|
|
750
784
|
return true;
|
|
751
785
|
return await importer(ambientHome, isolatedHome);
|
|
752
786
|
}
|
|
787
|
+
// Reports a cleanup failure without letting it decide the result of the scan. Only the
|
|
788
|
+
// message is forwarded, and it reaches the onWarning observer alone: unlike the fail-scan
|
|
789
|
+
// path it is never written to the workbench, so it adds no persisted, unredacted text.
|
|
790
|
+
function warnCleanupFailed(options, reason) {
|
|
791
|
+
// This runs where a throw would replace the scan result, so every step is inside the
|
|
792
|
+
// guard: reading the reason, coercing it, and reading the observers off the options can
|
|
793
|
+
// each throw for a sufficiently hostile value, and none of them may become the outcome
|
|
794
|
+
// of the scan. Losing a warning is the correct trade against losing the result.
|
|
795
|
+
try {
|
|
796
|
+
const message = String(reason instanceof Error ? reason.message : reason);
|
|
797
|
+
notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not clean up after the Codex Security scan: ${message}`);
|
|
798
|
+
}
|
|
799
|
+
catch { }
|
|
800
|
+
}
|
|
753
801
|
async function removeTargetPathsFile(path) {
|
|
754
802
|
if (path === null)
|
|
755
803
|
return;
|
|
@@ -797,10 +845,8 @@ export async function runScanEvents(options) {
|
|
|
797
845
|
status = "completed";
|
|
798
846
|
usage = event["usage"];
|
|
799
847
|
}
|
|
800
|
-
else if (event.type === "turn.failed"
|
|
801
|
-
|
|
802
|
-
typeof event["error"]["message"] === "string") {
|
|
803
|
-
throw new CodexSecurityError(event["error"]["message"]);
|
|
848
|
+
else if (event.type === "turn.failed") {
|
|
849
|
+
throw new CodexSecurityError(turnFailureMessage(event["error"]));
|
|
804
850
|
}
|
|
805
851
|
else if (event.type === "error" &&
|
|
806
852
|
typeof event["message"] === "string") {
|
|
@@ -913,7 +959,7 @@ function targetInstruction(target) {
|
|
|
913
959
|
}
|
|
914
960
|
return `Scan target: staged and unstaged working-tree changes against ${target.base}.`;
|
|
915
961
|
}
|
|
916
|
-
function scanRecipe(repository, target, mode, repositoryRevision, pluginVersion, effectiveConfig, failOnSeverity, knowledgeBasePaths, maxCostUsd) {
|
|
962
|
+
function scanRecipe(repository, activeProjectPath, target, mode, repositoryRevision, pluginVersion, effectiveConfig, failOnSeverity, knowledgeBasePaths, maxCostUsd) {
|
|
917
963
|
return {
|
|
918
964
|
repository,
|
|
919
965
|
target: {
|
|
@@ -927,7 +973,7 @@ function scanRecipe(repository, target, mode, repositoryRevision, pluginVersion,
|
|
|
927
973
|
mode,
|
|
928
974
|
...(repositoryRevision === null ? {} : { repositoryRevision }),
|
|
929
975
|
pluginVersion,
|
|
930
|
-
config: scanPreflightCodexConfig(effectiveConfig),
|
|
976
|
+
config: scanPreflightCodexConfig(effectiveConfig, activeProjectPath),
|
|
931
977
|
...(failOnSeverity === undefined ? {} : { failOnSeverity }),
|
|
932
978
|
...(knowledgeBasePaths === undefined ? {} : { knowledgeBasePaths }),
|
|
933
979
|
...(maxCostUsd === undefined ? {} : { maxCostUsd }),
|
|
@@ -1058,6 +1104,21 @@ function reconnectDetails(message) {
|
|
|
1058
1104
|
: {}),
|
|
1059
1105
|
};
|
|
1060
1106
|
}
|
|
1107
|
+
// A failed turn must fail the scan whatever its error payload looks like.
|
|
1108
|
+
//
|
|
1109
|
+
// Only `error.message` is reused, because that is the single shape the previous
|
|
1110
|
+
// code already surfaced. No other shape is forwarded or stringified: this message
|
|
1111
|
+
// reaches `fail-scan --message` and is stored in `scans.failure_message` without
|
|
1112
|
+
// redaction, so widening what is copied out of the payload would add a new
|
|
1113
|
+
// credential-disclosure path to persistent scan history.
|
|
1114
|
+
function turnFailureMessage(error) {
|
|
1115
|
+
if (isRecord(error) && typeof error["message"] === "string") {
|
|
1116
|
+
const message = error["message"].trim();
|
|
1117
|
+
if (message.length > 0)
|
|
1118
|
+
return error["message"];
|
|
1119
|
+
}
|
|
1120
|
+
return "The Codex Security scan turn failed without a readable error message.";
|
|
1121
|
+
}
|
|
1061
1122
|
export function classifyConnectionFailure(error) {
|
|
1062
1123
|
const message = error instanceof Error ? error.message : String(error);
|
|
1063
1124
|
if (/\b(?:sqlite3?|database|workbench)\b/iu.test(message)) {
|
|
@@ -1104,7 +1165,7 @@ export function scanRuntimeCodexConfig(config, stateDirectory, protectedCredenti
|
|
|
1104
1165
|
},
|
|
1105
1166
|
};
|
|
1106
1167
|
}
|
|
1107
|
-
export function scanPreflightCodexConfig(config) {
|
|
1168
|
+
export function scanPreflightCodexConfig(config, activeProjectPath) {
|
|
1108
1169
|
const safeString = (value, maxLength) => typeof value === "string" &&
|
|
1109
1170
|
value.length > 0 &&
|
|
1110
1171
|
value.length <= maxLength &&
|
|
@@ -1176,19 +1237,37 @@ export function scanPreflightCodexConfig(config) {
|
|
|
1176
1237
|
}
|
|
1177
1238
|
return result;
|
|
1178
1239
|
};
|
|
1240
|
+
const prioritizedEntries = (value, priority) => {
|
|
1241
|
+
const entries = Object.entries(value);
|
|
1242
|
+
if (priority === undefined || !Object.hasOwn(value, priority)) {
|
|
1243
|
+
return entries;
|
|
1244
|
+
}
|
|
1245
|
+
return [
|
|
1246
|
+
[priority, value[priority]],
|
|
1247
|
+
...entries.filter(([key]) => key !== priority),
|
|
1248
|
+
];
|
|
1249
|
+
};
|
|
1179
1250
|
const result = executionConfig(config);
|
|
1180
|
-
|
|
1181
|
-
|
|
1251
|
+
const selectedProfile = safeProfileName(config["profile"])
|
|
1252
|
+
? config["profile"]
|
|
1253
|
+
: undefined;
|
|
1254
|
+
if (selectedProfile !== undefined) {
|
|
1255
|
+
result["profile"] = selectedProfile;
|
|
1182
1256
|
}
|
|
1183
1257
|
const profiles = config["profiles"];
|
|
1184
1258
|
if (isRecord(profiles)) {
|
|
1185
1259
|
const sanitized = {};
|
|
1186
|
-
|
|
1260
|
+
let accepted = 0;
|
|
1261
|
+
for (const [name, profile] of prioritizedEntries(profiles, selectedProfile)) {
|
|
1187
1262
|
if (!safeProfileName(name) || !isRecord(profile))
|
|
1188
1263
|
continue;
|
|
1189
1264
|
const projected = executionConfig(profile);
|
|
1190
|
-
if (Object.keys(projected).length
|
|
1191
|
-
|
|
1265
|
+
if (Object.keys(projected).length === 0)
|
|
1266
|
+
continue;
|
|
1267
|
+
sanitized[name] = projected;
|
|
1268
|
+
accepted += 1;
|
|
1269
|
+
if (accepted === 256)
|
|
1270
|
+
break;
|
|
1192
1271
|
}
|
|
1193
1272
|
if (Object.keys(sanitized).length > 0)
|
|
1194
1273
|
result["profiles"] = sanitized;
|
|
@@ -1202,7 +1281,21 @@ export function scanPreflightCodexConfig(config) {
|
|
|
1202
1281
|
const projects = config["projects"];
|
|
1203
1282
|
if (isRecord(projects)) {
|
|
1204
1283
|
const sanitized = {};
|
|
1205
|
-
|
|
1284
|
+
let accepted = 0;
|
|
1285
|
+
const activeProjectRoot = activeProjectPath === undefined
|
|
1286
|
+
? undefined
|
|
1287
|
+
: Object.keys(projects)
|
|
1288
|
+
.filter((path) => {
|
|
1289
|
+
if (!safeString(path, 4096) || !isAbsolute(path))
|
|
1290
|
+
return false;
|
|
1291
|
+
const remaining = relative(path, activeProjectPath);
|
|
1292
|
+
return (remaining === "" ||
|
|
1293
|
+
(remaining !== ".." &&
|
|
1294
|
+
!remaining.startsWith(`..${sep}`) &&
|
|
1295
|
+
!isAbsolute(remaining)));
|
|
1296
|
+
})
|
|
1297
|
+
.sort((left, right) => right.length - left.length)[0];
|
|
1298
|
+
for (const [path, project] of prioritizedEntries(projects, activeProjectRoot ?? activeProjectPath)) {
|
|
1206
1299
|
if (!safeString(path, 4096) || !isAbsolute(path) || !isRecord(project)) {
|
|
1207
1300
|
continue;
|
|
1208
1301
|
}
|
|
@@ -1210,6 +1303,9 @@ export function scanPreflightCodexConfig(config) {
|
|
|
1210
1303
|
if (trust !== "trusted" && trust !== "untrusted")
|
|
1211
1304
|
continue;
|
|
1212
1305
|
sanitized[path] = { trust_level: trust };
|
|
1306
|
+
accepted += 1;
|
|
1307
|
+
if (accepted === 256)
|
|
1308
|
+
break;
|
|
1213
1309
|
}
|
|
1214
1310
|
if (Object.keys(sanitized).length > 0)
|
|
1215
1311
|
result["projects"] = sanitized;
|