@openai/codex-security 0.1.0 → 0.1.1
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 +43 -9
- package/dist/api.d.ts +4 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +58 -14
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +3 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +70 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -1
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,11 +86,36 @@ Check or remove the stored sign-in with `npx codex-security login status` and
|
|
|
86
86
|
sign-in. If Codex stores credentials in the system keyring, run
|
|
87
87
|
`npx codex-security login` once before scanning.
|
|
88
88
|
|
|
89
|
-
An environment API key takes precedence over a stored sign-in
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
An environment API key takes precedence over a stored sign-in by default.
|
|
90
|
+
When both a stored ChatGPT sign-in and an environment API key are available, an
|
|
91
|
+
interactive scan asks which credential to use. JSON output, dry runs, CI, and
|
|
92
|
+
other noninteractive scans never prompt and retain automatic API-key
|
|
93
|
+
precedence. Select the credential source explicitly with `--auth`:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx codex-security scan . --auth chatgpt
|
|
97
|
+
npx codex-security scan . --auth api-key
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`--auth chatgpt` uses the stored sign-in and ignores `OPENAI_API_KEY` and
|
|
101
|
+
`CODEX_API_KEY`. `--auth api-key` requires one of those environment variables.
|
|
102
|
+
Omit `--auth`, or pass `--auth auto`, to preserve automatic API-key precedence
|
|
103
|
+
for existing CI and unattended scans. The SDK accepts the same selection as
|
|
104
|
+
`security.run(repository, { auth: "chatgpt" })` and
|
|
105
|
+
`security.preflight(repository, { auth: "chatgpt" })`.
|
|
106
|
+
|
|
107
|
+
To make the stored ChatGPT sign-in the automatic default instead, unset any
|
|
108
|
+
configured API-key variables:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
unset OPENAI_API_KEY CODEX_API_KEY
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The interactive choice applies only to the current scan and is not persisted.
|
|
115
|
+
|
|
116
|
+
When an environment key is configured, ChatGPT login and
|
|
117
|
+
`codex-security login status` identify the effective scan credential source
|
|
118
|
+
without printing its value, including when no stored sign-in exists.
|
|
94
119
|
|
|
95
120
|
## CLI
|
|
96
121
|
|
|
@@ -216,6 +241,14 @@ Scan history uses the existing Codex Security workbench database at
|
|
|
216
241
|
`CODEX_SECURITY_STATE_DIR` to place the database elsewhere. Scan credentials
|
|
217
242
|
are never stored in the scan configuration.
|
|
218
243
|
|
|
244
|
+
The scan sandbox permits writes to the selected state directory so SQLite can
|
|
245
|
+
maintain its database and journal files. If the host itself cannot write to the
|
|
246
|
+
default directory, select a writable directory outside the scanned repository:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
export CODEX_SECURITY_STATE_DIR=/path/to/writable/codex-security-state
|
|
250
|
+
```
|
|
251
|
+
|
|
219
252
|
`scans rerun SCAN_ID` repeats the original configuration against the current
|
|
220
253
|
checkout so a fixed vulnerability can be checked again.
|
|
221
254
|
|
|
@@ -291,10 +324,11 @@ method and, for an environment API key, its variable name. Authentication and
|
|
|
291
324
|
model access remain unverified until a real scan starts.
|
|
292
325
|
|
|
293
326
|
Scan progress identifies the selected credential source before Codex starts.
|
|
294
|
-
|
|
295
|
-
API key overrides the stored sign-in.
|
|
296
|
-
|
|
297
|
-
|
|
327
|
+
Terminals and noninteractive CI logs also show how to retry with
|
|
328
|
+
`--auth chatgpt` when an environment API key overrides the stored sign-in.
|
|
329
|
+
Progress remains on stderr so JSON output stays machine readable. Network
|
|
330
|
+
failures and rate limits remain retryable; definitive authentication and model
|
|
331
|
+
authorization failures stop immediately.
|
|
298
332
|
|
|
299
333
|
## Documentation and security
|
|
300
334
|
|
package/dist/api.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface ScanEvent {
|
|
|
21
21
|
readonly [key: string]: unknown;
|
|
22
22
|
}
|
|
23
23
|
export interface ScanOptions {
|
|
24
|
+
auth?: ScanAuthMode;
|
|
24
25
|
target?: ScanTarget;
|
|
25
26
|
mode?: ScanMode;
|
|
26
27
|
knowledgeBasePaths?: string[];
|
|
@@ -40,6 +41,7 @@ export interface ScanOptions {
|
|
|
40
41
|
onObserverError?: (observer: ScanObserverName, error: unknown) => void;
|
|
41
42
|
signal?: AbortSignal;
|
|
42
43
|
}
|
|
44
|
+
export type ScanAuthMode = "auto" | "chatgpt" | "api-key";
|
|
43
45
|
export type ScanAuthentication = {
|
|
44
46
|
method: "api_key";
|
|
45
47
|
source: "OPENAI_API_KEY" | "CODEX_API_KEY";
|
|
@@ -103,9 +105,9 @@ interface ScanEventRunOptions {
|
|
|
103
105
|
onObserverError?: (observer: ScanObserverName, error: unknown) => void;
|
|
104
106
|
}
|
|
105
107
|
export declare function runScanEvents(options: ScanEventRunOptions): Promise<ScanResult>;
|
|
106
|
-
export declare function scanAuthentication(environment: ProcessEnvironment): ScanAuthentication;
|
|
108
|
+
export declare function scanAuthentication(environment: ProcessEnvironment, auth?: ScanAuthMode): ScanAuthentication;
|
|
107
109
|
export declare function classifyConnectionFailure(error: unknown): "rate_limited" | "unauthorized" | "forbidden" | "network_error" | "timeout" | "unknown";
|
|
108
|
-
export declare function scanRuntimeCodexConfig(config: JsonObject): JsonObject;
|
|
110
|
+
export declare function scanRuntimeCodexConfig(config: JsonObject, stateDirectory: string): JsonObject;
|
|
109
111
|
export declare function scanPreflightCodexConfig(config: JsonObject): JsonObject;
|
|
110
112
|
export declare function environmentValue(environment: ProcessEnvironment, requested: string): string | undefined;
|
|
111
113
|
export {};
|
package/dist/api.d.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CAcpB"}
|
package/dist/api.js
CHANGED
|
@@ -34,6 +34,7 @@ export class CodexSecurity {
|
|
|
34
34
|
#activeOperation = null;
|
|
35
35
|
#runtimePromise = null;
|
|
36
36
|
#runtime = null;
|
|
37
|
+
#runtimeCredentialSource = null;
|
|
37
38
|
#closed = false;
|
|
38
39
|
#closePromise = null;
|
|
39
40
|
constructor(config = {}, dependencies = DEFAULT_DEPENDENCIES) {
|
|
@@ -63,7 +64,7 @@ export class CodexSecurity {
|
|
|
63
64
|
: {}),
|
|
64
65
|
outputDir: inputs.outputDir,
|
|
65
66
|
...(archiveDir === null ? {} : { archiveDir }),
|
|
66
|
-
authentication: scanAuthentication(this.#dependencies.environment),
|
|
67
|
+
authentication: scanAuthentication(this.#dependencies.environment, options.auth),
|
|
67
68
|
...model,
|
|
68
69
|
...(options.maxCostUsd === undefined
|
|
69
70
|
? {}
|
|
@@ -108,7 +109,9 @@ export class CodexSecurity {
|
|
|
108
109
|
knowledgeBase = await prepareKnowledgeBase(options.knowledgeBasePaths, signal);
|
|
109
110
|
}
|
|
110
111
|
checkOpen();
|
|
111
|
-
const
|
|
112
|
+
const authentication = scanAuthentication(this.#dependencies.environment, options.auth);
|
|
113
|
+
const scanEnvironment = selectedScanEnvironment(this.#dependencies.environment, options.auth);
|
|
114
|
+
const runtime = await this.#ensureRuntime(signal, temporaryRoot, (path) => requireOutputOutsideRepository(protectedRoot, path, "runtime"), options.auth);
|
|
112
115
|
const runtimeHome = await realpath(runtime.codexHome);
|
|
113
116
|
requireOutputOutsideRepository(protectedRoot, runtimeHome, "runtime");
|
|
114
117
|
if (options.expectedPluginVersion !== undefined &&
|
|
@@ -116,7 +119,18 @@ export class CodexSecurity {
|
|
|
116
119
|
throw new CodexSecurityError(`The original scan used plugin version ${options.expectedPluginVersion}, but the installed version is ${runtime.plugin.version}.`);
|
|
117
120
|
}
|
|
118
121
|
checkOpen();
|
|
119
|
-
|
|
122
|
+
if (authentication.method === "stored_credentials" &&
|
|
123
|
+
this.#runtimeCredentialSource === "api_key") {
|
|
124
|
+
const ambientHome = environmentValue(this.#dependencies.environment, "CODEX_HOME") ??
|
|
125
|
+
join(homedir(), ".codex");
|
|
126
|
+
runtime.credentialsAvailable = await importAmbientAuth(ambientHome, runtime.codexHome);
|
|
127
|
+
this.#runtimeCredentialSource = runtime.credentialsAvailable
|
|
128
|
+
? "stored_credentials"
|
|
129
|
+
: null;
|
|
130
|
+
}
|
|
131
|
+
const apiKey = authentication.method === "api_key"
|
|
132
|
+
? environmentApiKey(this.#dependencies.environment)
|
|
133
|
+
: null;
|
|
120
134
|
if (apiKey !== null) {
|
|
121
135
|
const codexCommand = this.#codexCommand();
|
|
122
136
|
const login = await persistApiKey(codexCommand, runtime.environment, apiKey, signal);
|
|
@@ -124,16 +138,17 @@ export class CodexSecurity {
|
|
|
124
138
|
throw new CodexSecurityError(`Codex API-key login failed: ${login.stderr.trim() || login.stdout.trim() || "unknown error"}`);
|
|
125
139
|
}
|
|
126
140
|
runtime.credentialsAvailable = true;
|
|
141
|
+
this.#runtimeCredentialSource = "api_key";
|
|
127
142
|
}
|
|
128
143
|
if (!runtime.credentialsAvailable) {
|
|
129
144
|
throw new AuthenticationRequiredError("No credentials were found. Run 'codex-security login', use " +
|
|
130
145
|
"'codex-security login --device-auth' on a remote or headless machine, or set " +
|
|
131
146
|
"OPENAI_API_KEY or CODEX_API_KEY for CI.");
|
|
132
147
|
}
|
|
133
|
-
notifyObserver("onAuthentication", options.onAuthentication, options.onObserverError,
|
|
148
|
+
notifyObserver("onAuthentication", options.onAuthentication, options.onObserverError, authentication);
|
|
134
149
|
const python = await (this.#dependencies.resolvePluginPython ?? resolvePluginPython)({
|
|
135
150
|
configuredPath: this.config.pythonPath,
|
|
136
|
-
environment:
|
|
151
|
+
environment: scanEnvironment,
|
|
137
152
|
protectedRoot,
|
|
138
153
|
signal,
|
|
139
154
|
});
|
|
@@ -190,7 +205,7 @@ export class CodexSecurity {
|
|
|
190
205
|
python,
|
|
191
206
|
pluginRoot: runtime.plugin.pluginRoot,
|
|
192
207
|
environment: {
|
|
193
|
-
...runtime.environment,
|
|
208
|
+
...selectedScanEnvironment(runtime.environment, options.auth),
|
|
194
209
|
CODEX_SECURITY_STATE_DIR: stateDirectory,
|
|
195
210
|
},
|
|
196
211
|
signal,
|
|
@@ -242,7 +257,7 @@ export class CodexSecurity {
|
|
|
242
257
|
: { CODEX_SECURITY_TARGET_PATHS_FILE: targetPathsFile }),
|
|
243
258
|
};
|
|
244
259
|
const environment = {
|
|
245
|
-
...pluginExecutionEnvironment(python, withoutCodexHome(runtime.environment)),
|
|
260
|
+
...pluginExecutionEnvironment(python, withoutCodexHome(selectedScanEnvironment(runtime.environment, options.auth))),
|
|
246
261
|
CODEX_HOME: runtime.codexHome,
|
|
247
262
|
...runtimePaths,
|
|
248
263
|
};
|
|
@@ -356,12 +371,14 @@ export class CodexSecurity {
|
|
|
356
371
|
throw new CodexSecurityError(`Codex API-key login failed: ${result.stderr.trim() || result.stdout.trim() || "unknown error"}`);
|
|
357
372
|
}
|
|
358
373
|
runtime.credentialsAvailable = true;
|
|
374
|
+
this.#runtimeCredentialSource = "api_key";
|
|
359
375
|
}
|
|
360
376
|
async loginChatGPT() {
|
|
361
377
|
const runtime = await this.#ensureRuntime();
|
|
362
378
|
this.#requireOpen();
|
|
363
379
|
const handle = this.#trackLoginHandle(new CodexLoginHandle(this.#codexCommand(), ["login"], runtime.environment, () => {
|
|
364
380
|
runtime.credentialsAvailable = true;
|
|
381
|
+
this.#runtimeCredentialSource = "stored_credentials";
|
|
365
382
|
}));
|
|
366
383
|
await handle.waitForInstructions();
|
|
367
384
|
this.#requireOpen();
|
|
@@ -372,6 +389,7 @@ export class CodexSecurity {
|
|
|
372
389
|
this.#requireOpen();
|
|
373
390
|
const handle = this.#trackLoginHandle(new CodexLoginHandle(this.#codexCommand(), ["login", "--device-auth"], runtime.environment, () => {
|
|
374
391
|
runtime.credentialsAvailable = true;
|
|
392
|
+
this.#runtimeCredentialSource = "stored_credentials";
|
|
375
393
|
}));
|
|
376
394
|
await handle.waitForInstructions({ deviceCode: true });
|
|
377
395
|
this.#requireOpen();
|
|
@@ -395,6 +413,7 @@ export class CodexSecurity {
|
|
|
395
413
|
return preparedRuntime;
|
|
396
414
|
});
|
|
397
415
|
runtime.credentialsAvailable = false;
|
|
416
|
+
this.#runtimeCredentialSource = null;
|
|
398
417
|
}
|
|
399
418
|
async close() {
|
|
400
419
|
if (this.#closePromise !== null)
|
|
@@ -456,12 +475,12 @@ export class CodexSecurity {
|
|
|
456
475
|
}
|
|
457
476
|
}
|
|
458
477
|
}
|
|
459
|
-
async #ensureRuntime(signal, temporaryRoot, validateLocation) {
|
|
478
|
+
async #ensureRuntime(signal, temporaryRoot, validateLocation, auth = "auto") {
|
|
460
479
|
this.#requireOpen();
|
|
461
480
|
if (this.#runtime !== null)
|
|
462
481
|
return this.#runtime;
|
|
463
482
|
if (this.#runtimePromise === null) {
|
|
464
|
-
const runtimePromise = this.#prepareRuntime(signal ?? this.#abortController.signal, temporaryRoot, validateLocation);
|
|
483
|
+
const runtimePromise = this.#prepareRuntime(signal ?? this.#abortController.signal, temporaryRoot, validateLocation, auth);
|
|
465
484
|
this.#runtimePromise = runtimePromise;
|
|
466
485
|
void runtimePromise.catch(() => {
|
|
467
486
|
if (this.#runtimePromise === runtimePromise) {
|
|
@@ -472,6 +491,9 @@ export class CodexSecurity {
|
|
|
472
491
|
const runtime = await this.#runtimePromise;
|
|
473
492
|
this.#requireOpen();
|
|
474
493
|
this.#runtime = runtime;
|
|
494
|
+
this.#runtimeCredentialSource = runtime.credentialsAvailable
|
|
495
|
+
? "stored_credentials"
|
|
496
|
+
: null;
|
|
475
497
|
return this.#runtime;
|
|
476
498
|
}
|
|
477
499
|
#trackLoginHandle(handle) {
|
|
@@ -509,7 +531,7 @@ export class CodexSecurity {
|
|
|
509
531
|
protectedRoot,
|
|
510
532
|
};
|
|
511
533
|
}
|
|
512
|
-
async #prepareRuntime(signal, temporaryRoot, validateLocation) {
|
|
534
|
+
async #prepareRuntime(signal, temporaryRoot, validateLocation, auth = "auto") {
|
|
513
535
|
if (this.#dependencies.prepareRuntime !== undefined) {
|
|
514
536
|
return await this.#dependencies.prepareRuntime(this.config, signal);
|
|
515
537
|
}
|
|
@@ -519,12 +541,12 @@ export class CodexSecurity {
|
|
|
519
541
|
throwIfAborted(signal);
|
|
520
542
|
bootstrapWorkspace = await createIsolatedHome(dirname(codexHome), validateLocation);
|
|
521
543
|
const pluginRoot = await resolvePluginPath(this.config.pluginPath, bootstrapWorkspace, signal);
|
|
522
|
-
const processEnvironment = this.#dependencies.environment;
|
|
544
|
+
const processEnvironment = selectedScanEnvironment(this.#dependencies.environment, auth);
|
|
523
545
|
const nodeAmbientHome = join(homedir(), ".codex");
|
|
524
546
|
const configuredAmbientHome = environmentValue(processEnvironment, "CODEX_HOME");
|
|
525
547
|
const ambientHome = configuredAmbientHome ?? nodeAmbientHome;
|
|
526
548
|
const mergedConfig = await mergedCodexConfig(this.config);
|
|
527
|
-
const codexConfig = scanRuntimeCodexConfig(mergedConfig);
|
|
549
|
+
const codexConfig = scanRuntimeCodexConfig(mergedConfig, codexSecurityStateDirectory(processEnvironment));
|
|
528
550
|
await writeCodexConfig(join(codexHome, "config.toml"), codexConfig);
|
|
529
551
|
const configPath = join(bootstrapWorkspace, "config-preflight.toml");
|
|
530
552
|
await writeCodexConfig(configPath, scanPreflightCodexConfig(mergedConfig));
|
|
@@ -624,6 +646,11 @@ export async function runScanEvents(options) {
|
|
|
624
646
|
else if (event.type === "error" &&
|
|
625
647
|
typeof event["message"] === "string") {
|
|
626
648
|
const message = event["message"];
|
|
649
|
+
const classification = classifyConnectionFailure(message);
|
|
650
|
+
if (classification === "unauthorized" ||
|
|
651
|
+
classification === "forbidden") {
|
|
652
|
+
throw new CodexSecurityError(message);
|
|
653
|
+
}
|
|
627
654
|
const reconnect = reconnectAttempt(message);
|
|
628
655
|
if (reconnect === null)
|
|
629
656
|
throw new CodexSecurityError(message);
|
|
@@ -795,12 +822,25 @@ async function collectResult(turnResult, threadId, scanDir, pluginRoot, expectat
|
|
|
795
822
|
sarifPath,
|
|
796
823
|
});
|
|
797
824
|
}
|
|
798
|
-
export function scanAuthentication(environment) {
|
|
825
|
+
export function scanAuthentication(environment, auth = "auto") {
|
|
826
|
+
if (auth === "chatgpt") {
|
|
827
|
+
return { method: "stored_credentials", verified: false };
|
|
828
|
+
}
|
|
799
829
|
const key = environmentApiKeyEntry(environment);
|
|
830
|
+
if (auth === "api-key" && key === null) {
|
|
831
|
+
throw new AuthenticationRequiredError("API-key authentication requires OPENAI_API_KEY or CODEX_API_KEY. " +
|
|
832
|
+
"Set a valid API key or use '--auth chatgpt'.");
|
|
833
|
+
}
|
|
800
834
|
return key === null
|
|
801
835
|
? { method: "stored_credentials", verified: false }
|
|
802
836
|
: { method: "api_key", source: key.source, verified: false };
|
|
803
837
|
}
|
|
838
|
+
function selectedScanEnvironment(environment, auth = "auto") {
|
|
839
|
+
if (auth !== "chatgpt")
|
|
840
|
+
return environment;
|
|
841
|
+
return Object.fromEntries(Object.entries(environment).filter(([name]) => name.toUpperCase() !== "OPENAI_API_KEY" &&
|
|
842
|
+
name.toUpperCase() !== "CODEX_API_KEY"));
|
|
843
|
+
}
|
|
804
844
|
function notifyObserver(observerName, observer, onObserverError, ...args) {
|
|
805
845
|
void Promise.resolve()
|
|
806
846
|
.then(() => observer?.(...args))
|
|
@@ -857,6 +897,9 @@ function reconnectDetails(message) {
|
|
|
857
897
|
}
|
|
858
898
|
export function classifyConnectionFailure(error) {
|
|
859
899
|
const message = error instanceof Error ? error.message : String(error);
|
|
900
|
+
if (/\b(?:sqlite3?|database|workbench)\b/iu.test(message)) {
|
|
901
|
+
return "unknown";
|
|
902
|
+
}
|
|
860
903
|
if (/\brate[_ -]?limit(?:ed|[_ -]exceeded)?\b|\b429\b|\btoo many requests\b/iu.test(message)) {
|
|
861
904
|
return "rate_limited";
|
|
862
905
|
}
|
|
@@ -873,7 +916,7 @@ export function classifyConnectionFailure(error) {
|
|
|
873
916
|
return "timeout";
|
|
874
917
|
return "unknown";
|
|
875
918
|
}
|
|
876
|
-
export function scanRuntimeCodexConfig(config) {
|
|
919
|
+
export function scanRuntimeCodexConfig(config, stateDirectory) {
|
|
877
920
|
const hardened = structuredClone(config);
|
|
878
921
|
delete hardened["sandbox_mode"];
|
|
879
922
|
const configuredPermissions = isRecord(hardened["permissions"])
|
|
@@ -889,6 +932,7 @@ export function scanRuntimeCodexConfig(config) {
|
|
|
889
932
|
filesystem: {
|
|
890
933
|
":root": "read",
|
|
891
934
|
":workspace_roots": "write",
|
|
935
|
+
[stateDirectory]: "write",
|
|
892
936
|
},
|
|
893
937
|
},
|
|
894
938
|
},
|