Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

feat(sdk): surface trusted cyber access status in scans (#236)

mldangelo-oaif08c8ccd2fca
diff --git a/README.md b/README.md
index b6ea1de14..ff23b6029 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,9 @@
**See the [Codex Security documentation](https://learn.chatgpt.com/docs/security/cli)** for more details.
-> Note: for best results, we recommend that your account is verified for [Trusted Access](https://chatgpt.com/cyber).
+Some cybersecurity requests and protected findings require approval through
+Trusted Access for Cyber. To apply or check your access, visit
+[chatgpt.com/cyber](https://chatgpt.com/cyber).
## Quick start
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md
index 2804da1ec..9763b1f1c 100644
--- a/sdk/typescript/README.md
+++ b/sdk/typescript/README.md
@@ -85,10 +85,10 @@ Pass scan configuration to `security.run(repository, options)` or
| `signal` | Cancel a scan with an `AbortSignal`. |
Progress and lifecycle callbacks are `onAuthentication`, `onCost`,
-`onOutputArchived`, `onOutputDirReady`, `onScanStarted`, `onReconnect`,
-`onWorkerStatus`, `onWarning`, and `onObserverError`. Preflight does not start
-the runtime, authenticate, resolve Python, inspect the plugin, or run those
-scan-lifecycle callbacks.
+`onOutputArchived`, `onOutputDirReady`, `onScanStarted`,
+`onTrustedAccessStatus`, `onReconnect`, `onWorkerStatus`, `onWarning`, and
+`onObserverError`. Preflight does not start the runtime, authenticate, resolve
+Python, inspect the plugin, or run those scan-lifecycle callbacks.
## Authentication
@@ -183,6 +183,10 @@ When an environment key is configured, ChatGPT login and
`codex-security login status` identify the effective scan credential source
without printing its value, including when no stored sign-in exists.
+Some cybersecurity requests and protected findings require approval through
+Trusted Access for Cyber. To apply or check your access, visit
+[chatgpt.com/cyber](https://chatgpt.com/cyber).
+
## CLI
```bash
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index c63cbcb6c..8cabdbdfe 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -159,6 +159,7 @@ export interface ScanOptions extends DeepScanOptions {
onOutputArchived?: (archiveDir: string) => void;
onOutputDirReady?: (scanDir: string) => void;
onAuthentication?: (authentication: ScanAuthentication) => void;
+ onTrustedAccessStatus?: (status: ScanTrustedAccessStatus) => void;
onScanStarted?: () => void;
onReconnect?: (
attempt: number,
@@ -187,9 +188,12 @@ export type ScanAuthentication =
}
| {
method: "stored_credentials";
+ credentialType?: "api_key" | "chatgpt";
verified: false;
};
+export type ScanTrustedAccessStatus = "granted" | "not_granted" | "unknown";
+
export interface ScanReconnectDetails {
reason: "rate_limit" | "network" | "authentication" | "authorization";
retryAfterSeconds?: number;
@@ -205,6 +209,7 @@ type ScanObserverName =
| "onOutputArchived"
| "onOutputDirReady"
| "onScanStarted"
+ | "onTrustedAccessStatus"
| "onReconnect"
| "onActivity"
| "onProgress"
@@ -257,6 +262,9 @@ const DEFAULT_DEPENDENCIES: ClientDependencies = {
};
const SCAN_PERMISSION_PROFILE = "codex_security_scan";
+const PERSONAL_TRUSTED_ACCESS_URL = "https://chatgpt.com/cyber";
+const ORGANIZATIONAL_TRUSTED_ACCESS_URL =
+ "https://openai.com/form/enterprise-trusted-access-for-cyber/";
const DEEP_SCAN_SETTINGS = [
["workers", "workers", 1],
["subagents", "subagents", 0],
@@ -417,7 +425,7 @@ export class CodexSecurity {
const externalProvider = isExternalModelProvider(modelProvider)
? EXTERNAL_CODEX_PROVIDERS[modelProvider]
: null;
- const authentication = scanAuthentication(
+ let authentication = scanAuthentication(
this.#dependencies.environment,
options.auth,
modelProvider,
@@ -531,6 +539,12 @@ export class CodexSecurity {
"OPENAI_API_KEY or CODEX_API_KEY for CI.",
);
}
+ authentication = await runtimeScanAuthentication(
+ this.#dependencies.environment,
+ runtime.codexHome,
+ options.auth,
+ modelProvider,
+ );
notifyObserver(
"onAuthentication",
options.onAuthentication,
@@ -919,6 +933,7 @@ export class CodexSecurity {
scanDir,
pluginRoot: runtime.plugin.installedRoot,
expectation,
+ authentication,
workbenchValidated: true,
model,
onThreadStarted: (threadId) => tracker.start(threadId),
@@ -947,6 +962,7 @@ export class CodexSecurity {
return snapshot.usage;
},
onScanStarted: options.onScanStarted,
+ onTrustedAccessStatus: options.onTrustedAccessStatus,
onReconnect: options.onReconnect,
onActivity: options.onActivity,
onProgress: (progress) => {
@@ -962,6 +978,7 @@ export class CodexSecurity {
reportProgress(progress);
},
onWorkerStatus: options.onWorkerStatus,
+ onWarning: options.onWarning,
onObserverError: options.onObserverError,
});
checkOpen();
@@ -1631,12 +1648,14 @@ interface ScanEventRunOptions {
scanDir: string;
pluginRoot: string;
expectation: ScanExpectation;
+ authentication?: ScanAuthentication;
workbenchValidated?: boolean;
model?: string;
expectedFilesTotal?: number;
onFinalize?: (usage: unknown) => Promise<unknown>;
onThreadStarted?: (threadId: string) => void;
onScanStarted?: () => void;
+ onTrustedAccessStatus?: (status: ScanTrustedAccessStatus) => void;
onReconnect?: (
attempt: number,
maxAttempts: number,
@@ -1645,6 +1664,7 @@ interface ScanEventRunOptions {
onActivity?: (activity: ScanActivity) => void;
onProgress?: (progress: ScanProgress) => void;
onWorkerStatus?: (status: ScanWorkerStatus) => void;
+ onWarning?: (warning: string) => void;
onObserverError?: (observer: ScanObserverName, error: unknown) => void;
}
@@ -1657,8 +1677,29 @@ export async function runScanEvents(
let finalResponse = "";
let usage: unknown = null;
let lastStreamError: string | null = null;
+ let tacStatusReported = false;
try {
for await (const event of options.events) {
+ if (!tacStatusReported) {
+ const tacStatus = trustedAccessStatusFromEvent(event);
+ if (tacStatus !== null) {
+ tacStatusReported = true;
+ notifyObserver(
+ "onTrustedAccessStatus",
+ options.onTrustedAccessStatus,
+ options.onObserverError,
+ tacStatus,
+ );
+ if (tacStatus !== "granted") {
+ notifyObserver(
+ "onWarning",
+ options.onWarning,
+ options.onObserverError,
+ trustedAccessWarning(tacStatus, options.authentication),
+ );
+ }
+ }
+ }
for (const activity of scanActivitiesFromEvent(
event,
options.expectation.repository,
@@ -1799,6 +1840,90 @@ export async function runScanEvents(
}
}
+function trustedAccessStatusFromEvent(
+ event: ScanEvent,
+): ScanTrustedAccessStatus | null {
+ if (event.type !== "item.completed" || !isRecord(event["item"])) {
+ return null;
+ }
+
+ const item = event["item"];
+ if (
+ item["type"] !== "mcp_tool_call" ||
+ item["server"] !== "codex_apps" ||
+ item["tool"] !== "get_tac_status"
+ ) {
+ return null;
+ }
+
+ if (item["status"] !== "completed" || !isRecord(item["result"])) {
+ return "unknown";
+ }
+
+ const result = item["result"]["structured_content"];
+ if (
+ !isRecord(result) ||
+ result["schemaVersion"] !== 1 ||
+ !Array.isArray(result["grants"]) ||
+ typeof result["checkedAt"] !== "string" ||
+ Number.isNaN(Date.parse(result["checkedAt"])) ||
+ result["stale"] !== false
+ ) {
+ return "unknown";
+ }
+
+ const status = result["status"];
+ if (
+ status !== "granted" &&
+ status !== "not_granted" &&
+ status !== "unknown"
+ ) {
+ return "unknown";
+ }
+ if (
+ result["grants"].some((grant) => !isTrustedAccessGrant(grant)) ||
+ (status === "granted") !== result["grants"].length > 0
+ ) {
+ return "unknown";
+ }
+ return status;
+}
+
+function isTrustedAccessGrant(grant: unknown): boolean {
+ if (!isRecord(grant)) return false;
+ const level = grant["level"];
+ const source = grant["source"];
+ return (
+ (source === "user" && (level === "tac1" || level === "tac2")) ||
+ (source === "current_account" &&
+ (level === "tac1" || level === "tac3" || level === "government"))
+ );
+}
+
+function trustedAccessWarning(
+ status: Exclude<ScanTrustedAccessStatus, "granted">,
+ authentication?: ScanAuthentication,
+): string {
+ const apiOrganization =
+ (authentication?.method === "api_key" &&
+ (authentication.source === "OPENAI_API_KEY" ||
+ authentication.source === "CODEX_API_KEY")) ||
+ (authentication?.method === "stored_credentials" &&
+ authentication.credentialType === "api_key");
+ const applicationUrl = apiOrganization
+ ? ORGANIZATIONAL_TRUSTED_ACCESS_URL
+ : PERSONAL_TRUSTED_ACCESS_URL;
+ if (status === "not_granted") {
+ const account = apiOrganization ? "your API organization" : "your account";
+ return `Some cybersecurity requests or findings may be refused because ${account} does not have Trusted Access for Cyber. Apply at ${applicationUrl}.`;
+ }
+ const access = apiOrganization
+ ? "Trusted Access for Cyber for your API organization"
+ : "your Trusted Access for Cyber status";
+ const action = apiOrganization ? "your organization's access" : "your access";
+ return `Some cybersecurity requests or findings may be refused because ${access} could not be verified. Check ${action} or apply at ${applicationUrl}.`;
+}
+
async function scanPrompt(
pluginRoot: string,
target: NormalizedTarget,
@@ -2008,6 +2133,35 @@ export function scanAuthentication(
: { method: "api_key", source: key.source, verified: false };
}
+async function runtimeScanAuthentication(
+ environment: ProcessEnvironment,
+ codexHome: string,
+ auth: ScanAuthMode = "auto",
+ modelProvider?: unknown,
+): Promise<ScanAuthentication> {
+ const authentication = scanAuthentication(environment, auth, modelProvider);
+ if (authentication.method !== "stored_credentials") return authentication;
+
+ try {
+ const stored = JSON.parse(
+ await readFile(join(codexHome, "auth.json"), "utf8"),
+ ) as unknown;
+ if (!isRecord(stored)) return authentication;
+
+ const mode = stored["auth_mode"];
+ if (mode === "apikey" || mode === "api_key") {
+ return { ...authentication, credentialType: "api_key" };
+ }
+ if (mode === "chatgpt") {
+ return { ...authentication, credentialType: "chatgpt" };
+ }
+ } catch {
+ return authentication;
+ }
+
+ return authentication;
+}
+
function selectedScanEnvironment(
environment: ProcessEnvironment,
auth: ScanAuthMode = "auto",
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index e12459715..bf905ad9e 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -2964,6 +2964,13 @@ async function runScan(
}
progress?.startTimer("Preparing scan");
},
+ onTrustedAccessStatus: (status) => {
+ if (status === "granted") {
+ errorOutput.write(
+ "codex-security: ✓ Your account has Trusted Access for Cyber.\n",
+ );
+ }
+ },
onScanStarted: () => {
diagnostic("scan.started");
if (dashboard !== null) {
diff --git a/sdk/typescript/src/index.ts b/sdk/typescript/src/index.ts
index 21e4fd0d5..f1ef3a1e6 100644
--- a/sdk/typescript/src/index.ts
+++ b/sdk/typescript/src/index.ts
@@ -10,6 +10,7 @@ export type {
ScanOptions,
ScanPreflight,
ScanReconnectDetails,
+ ScanTrustedAccessStatus,
ScanWarningDetails,
} from "./api.js";
export type {
diff --git a/sdk/typescript/tests-ts/api-events.test.ts b/sdk/typescript/tests-ts/api-events.test.ts
index 189943657..6ff1fb656 100644
--- a/sdk/typescript/tests-ts/api-events.test.ts
+++ b/sdk/typescript/tests-ts/api-events.test.ts
@@ -1,16 +1,18 @@
import { mkdir, stat } from "node:fs/promises";
import { existsSync } from "node:fs";
import { join } from "node:path";
-import type { ThreadEvent } from "@openai/codex-sdk";
+import type { McpToolCallItem, ThreadEvent } from "@openai/codex-sdk";
import { afterEach, describe, expect, test } from "bun:test";
import { runScanEvents } from "../src/api.js";
import {
CodexSecurityError,
IncompleteScanError,
ScanInterruptedError,
+ type ScanAuthentication,
type ScanActivity,
type ScanProgress,
type ScanReconnectDetails,
+ type ScanTrustedAccessStatus,
type ScanWorkerStatus,
} from "../src/index.js";
import { PLUGIN_ROOT } from "./plugin-root.js";
@@ -26,6 +28,70 @@ const { cleanup, copyCompletedScan, temporaryDirectory } =
afterEach(cleanup);
+function tacToolCall(
+ status: "granted" | "not_granted" | "unknown",
+ overrides: Partial<McpToolCallItem> = {},
+): McpToolCallItem {
+ return {
+ id: "tac-status-1",
+ type: "mcp_tool_call",
+ server: "codex_apps",
+ tool: "get_tac_status",
+ arguments: {},
+ result: {
+ content: [],
+ structured_content: {
+ schemaVersion: 1,
+ status,
+ grants: status === "granted" ? [{ level: "tac1", source: "user" }] : [],
+ checkedAt: "2026-07-29T00:00:00.000Z",
+ stale: false,
+ },
+ },
+ status: "completed",
+ ...overrides,
+ };
+}
+
+async function* tacEvents(
+ items: readonly McpToolCallItem[],
+): AsyncGenerator<ThreadEvent> {
+ yield { type: "thread.started", thread_id: "thread-1" };
+ yield { type: "turn.started" };
+ for (const item of items) {
+ yield { type: "item.completed", item };
+ }
+ yield {
+ type: "item.completed",
+ item: { id: "message-1", type: "agent_message", text: "scan complete" },
+ };
+ yield {
+ type: "turn.completed",
+ usage: {
+ input_tokens: 10,
+ cached_input_tokens: 2,
+ output_tokens: 3,
+ reasoning_output_tokens: 1,
+ },
+ };
+}
+
+function runTacEvents(
+ scanDir: string,
+ items: readonly McpToolCallItem[],
+ onWarning: (warning: string) => void,
+ onObserverError?: (observer: ScanObserverName, error: unknown) => void,
+ onTrustedAccessStatus?: (status: ScanTrustedAccessStatus) => void,
+ authentication?: ScanAuthentication,
+): ReturnType<typeof runEvents> {
+ return runEvents(scanDir, tacEvents(items), {
+ authentication,
+ onObserverError,
+ onTrustedAccessStatus,
+ onWarning,
+ });
+}
+
describe("one-shot scan events", () => {
test("validates completed scan artifacts", async () => {
const scanDir = await copyCompletedScan(await temporaryDirectory());
@@ -47,6 +113,287 @@ describe("one-shot scan events", () => {
});
});
+ test("reports granted trusted cyber access once without a warning", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+ const statuses: ScanTrustedAccessStatus[] = [];
+ const item = tacToolCall("granted");
+
+ const result = await runTacEvents(
+ scanDir,
+ [item, item],
+ (warning) => warnings.push(warning),
+ undefined,
+ (status) => statuses.push(status),
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toEqual([]);
+ expect(statuses).toEqual(["granted"]);
+ });
+
+ test("warns once and continues when trusted cyber access is not granted", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+ const item = tacToolCall("not_granted");
+
+ const result = await runTacEvents(scanDir, [item, item], (warning) =>
+ warnings.push(warning),
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toBe(
+ "Some cybersecurity requests or findings may be refused because your account does not have Trusted Access for Cyber. Apply at https://chatgpt.com/cyber.",
+ );
+ });
+
+ test("warns once and continues when trusted cyber access is unknown", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [tacToolCall("unknown")],
+ (warning) => warnings.push(warning),
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toBe(
+ "Some cybersecurity requests or findings may be refused because your Trusted Access for Cyber status could not be verified. Check your access or apply at https://chatgpt.com/cyber.",
+ );
+ });
+
+ test("directs API-key scans to the organizational trusted cyber application", async () => {
+ for (const [authentication, status, expected] of [
+ [
+ {
+ method: "api_key",
+ source: "OPENAI_API_KEY",
+ verified: false,
+ },
+ "not_granted",
+ "Some cybersecurity requests or findings may be refused because your API organization does not have Trusted Access for Cyber. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",
+ ],
+ [
+ {
+ method: "api_key",
+ source: "CODEX_API_KEY",
+ verified: false,
+ },
+ "unknown",
+ "Some cybersecurity requests or findings may be refused because Trusted Access for Cyber for your API organization could not be verified. Check your organization's access or apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",
+ ],
+ [
+ {
+ method: "stored_credentials",
+ credentialType: "api_key",
+ verified: false,
+ },
+ "not_granted",
+ "Some cybersecurity requests or findings may be refused because your API organization does not have Trusted Access for Cyber. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",
+ ],
+ [
+ {
+ method: "stored_credentials",
+ credentialType: "api_key",
+ verified: false,
+ },
+ "unknown",
+ "Some cybersecurity requests or findings may be refused because Trusted Access for Cyber for your API organization could not be verified. Check your organization's access or apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",
+ ],
+ ] as const) {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [tacToolCall(status)],
+ (warning) => warnings.push(warning),
+ undefined,
+ undefined,
+ authentication,
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toEqual([expected]);
+ expect(warnings[0]).not.toContain("chatgpt.com/cyber");
+ }
+ });
+
+ test("does not mistake external-provider keys for OpenAI API organizations", async () => {
+ for (const source of ["OPENROUTER_API_KEY", "FIREWORKS_API_KEY"] as const) {
+ for (const status of ["not_granted", "unknown"] as const) {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [tacToolCall(status)],
+ (warning) => warnings.push(warning),
+ undefined,
+ undefined,
+ { method: "api_key", source, verified: false },
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toContain("https://chatgpt.com/cyber");
+ expect(warnings[0]).not.toContain("API organization");
+ expect(warnings[0]).not.toContain(
+ "enterprise-trusted-access-for-cyber",
+ );
+ }
+ }
+ });
+
+ test("treats failed trusted cyber access checks as an advisory without exposing provider errors", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [
+ tacToolCall("unknown", {
+ status: "failed",
+ result: undefined,
+ error: { message: "SYNTHETIC_PRIVATE_PROVIDER_ERROR" },
+ }),
+ ],
+ (warning) => warnings.push(warning),
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toContain("https://chatgpt.com/cyber");
+ expect(warnings[0]).not.toContain("SYNTHETIC_PRIVATE_PROVIDER_ERROR");
+ });
+
+ test("treats malformed or stale trusted cyber access results as unverified", async () => {
+ for (const structuredContent of [
+ null,
+ { schemaVersion: 1, status: "granted", grants: [] },
+ {
+ schemaVersion: 1,
+ status: "granted",
+ grants: [{ level: "tac1", source: "user" }],
+ stale: false,
+ },
+ {
+ schemaVersion: 1,
+ status: "granted",
+ grants: [],
+ checkedAt: "2026-07-29T00:00:00.000Z",
+ stale: false,
+ },
+ {
+ schemaVersion: 1,
+ status: "not_granted",
+ grants: [{ level: "tac1", source: "user" }],
+ checkedAt: "2026-07-29T00:00:00.000Z",
+ stale: false,
+ },
+ {
+ schemaVersion: 1,
+ status: "granted",
+ grants: [{ level: "tac3", source: "user" }],
+ checkedAt: "2026-07-29T00:00:00.000Z",
+ stale: false,
+ },
+ {
+ schemaVersion: 1,
+ status: "granted",
+ grants: [],
+ stale: true,
+ },
+ {
+ schemaVersion: 2,
+ status: "granted",
+ grants: [],
+ stale: false,
+ },
+ ]) {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [
+ tacToolCall("granted", {
+ result: { content: [], structured_content: structuredContent },
+ }),
+ ],
+ (warning) => warnings.push(warning),
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toContain("could not be verified");
+ }
+ });
+
+ test("does not trust similarly named tools from other MCP servers", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const warnings: string[] = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [
+ tacToolCall("not_granted", { server: "untrusted_server" }),
+ tacToolCall("not_granted", { tool: "unrelated_tool" }),
+ tacToolCall("granted"),
+ ],
+ (warning) => warnings.push(warning),
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(warnings).toEqual([]);
+ });
+
+ test("isolates trusted cyber access warning observer failures", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const observerErrors: Array<[ScanObserverName, string]> = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [tacToolCall("not_granted")],
+ () => {
+ throw new Error("TAC warning observer failed");
+ },
+ (observer, error) => {
+ observerErrors.push([observer, (error as Error).message]);
+ },
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(observerErrors).toEqual([
+ ["onWarning", "TAC warning observer failed"],
+ ]);
+ });
+
+ test("isolates trusted cyber access status observer failures", async () => {
+ const scanDir = await copyCompletedScan(await temporaryDirectory());
+ const observerErrors: Array<[ScanObserverName, string]> = [];
+
+ const result = await runTacEvents(
+ scanDir,
+ [tacToolCall("granted")],
+ () => {},
+ (observer, error) => {
+ observerErrors.push([observer, (error as Error).message]);
+ },
+ () => {
+ throw new Error("TAC status observer failed");
+ },
+ );
+
+ expect(result.turnResult.status).toBe("completed");
+ expect(observerErrors).toEqual([
+ ["onTrustedAccessStatus", "TAC status observer failed"],
+ ]);
+ });
+
test("accepts target identity validated by the workbench", async () => {
const scanDir = await copyCompletedScan(await temporaryDirectory());
const events = completedEvents();
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 9ec04ca66..996c6a2be 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -1264,6 +1264,88 @@ describe("CodexSecurity orchestration", () => {
await client.close();
});
+ test("identifies stored credential types without exposing stored secrets", async () => {
+ for (const [storedAuthentication, expected] of [
+ [
+ {
+ auth_mode: "apikey",
+ OPENAI_API_KEY: "sk-proj-SYNTHETIC_STORED_SECRET_123",
+ },
+ {
+ method: "stored_credentials",
+ credentialType: "api_key",
+ verified: false,
+ },
+ ],
+ [
+ {
+ auth_mode: "api_key",
+ OPENAI_API_KEY: "sk-proj-SYNTHETIC_STORED_SECRET_456",
+ },
+ {
+ method: "stored_credentials",
+ credentialType: "api_key",
+ verified: false,
+ },
+ ],
+ [
+ {
+ auth_mode: "chatgpt",
+ tokens: { access_token: "SYNTHETIC_STORED_ACCESS_TOKEN" },
+ },
+ {
+ method: "stored_credentials",
+ credentialType: "chatgpt",
+ verified: false,
+ },
+ ],
+ [
+ { auth_mode: "unknown", token: "SYNTHETIC_UNKNOWN_TOKEN" },
+ { method: "stored_credentials", verified: false },
+ ],
+ ] as const) {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ const codexHome = join(root, "codex-home");
+ await mkdir(repository);
+ await mkdir(codexHome);
+ await writeFile(
+ join(codexHome, "auth.json"),
+ JSON.stringify(storedAuthentication),
+ );
+ let selectedAuthentication: ScanAuthentication | undefined;
+ const client = new TestClient(
+ {},
+ {
+ environment: {},
+ prepareRuntime: async () => preparedRuntime(codexHome),
+ resolvePluginPython: async () => "/managed/python",
+ repositoryRevision: async () => null,
+ createCodex: () => ({
+ startThread: () => ({
+ id: null,
+ async runStreamed() {
+ throw new Error("scan did not start");
+ },
+ }),
+ }),
+ },
+ );
+
+ await expect(
+ client.run(repository, {
+ outputDir: join(root, "scan"),
+ onAuthentication: (authentication) => {
+ selectedAuthentication = authentication;
+ },
+ }),
+ ).rejects.toThrow("scan did not start");
+ expect(selectedAuthentication).toEqual(expected);
+ expect(JSON.stringify(selectedAuthentication)).not.toContain("SYNTHETIC");
+ await client.close();
+ }
+ });
+
test("previews an existing output archive without changing files", async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
@@ -4376,7 +4458,11 @@ if (process.argv.slice(2).join(" ") !== "login status") {
);
expect(authentications).toEqual([
{ method: "api_key", source: "OPENAI_API_KEY", verified: false },
- { method: "stored_credentials", verified: false },
+ {
+ method: "stored_credentials",
+ credentialType: "chatgpt",
+ verified: false,
+ },
]);
expect(selectedApiKeys).toEqual(["synthetic-openai-key", undefined]);
expect(
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index a7754072d..725e8b42f 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -288,6 +288,18 @@ describe("CLI", () => {
const readme = await readFile(new URL("../README.md", import.meta.url), {
encoding: "utf8",
});
+ const publicReadme = await readFile(
+ new URL("../../../README.md", import.meta.url),
+ { encoding: "utf8" },
+ );
+
+ for (const documentation of [readme, publicReadme]) {
+ expect(documentation).toContain(
+ "Some cybersecurity requests and protected findings require approval through\n" +
+ "Trusted Access for Cyber. To apply or check your access, visit\n" +
+ "[chatgpt.com/cyber](https://chatgpt.com/cyber).",
+ );
+ }
for (const setting of [
"OPENAI_API_KEY",
@@ -3944,6 +3956,107 @@ describe("CLI", () => {
expect(stderr.text()).not.toContain("SYNTHETIC_WARNING_SECRET");
});
+ test("prints granted trusted cyber access without warning or corrupting JSON scans", async () => {
+ const stdout = capture();
+ const stderr = capture();
+ const deps = dependencies();
+ deps.createSecurity = () => ({
+ run: async (_repository, options) => {
+ options?.onTrustedAccessStatus?.("granted");
+ return fakeResult();
+ },
+ close: async () => {},
+ preflight: async () => fakePreflight(),
+ });
+
+ expect(
+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),
+ ).toBe(0);
+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
+ expect(stderr.text()).toContain(
+ "codex-security: ✓ Your account has Trusted Access for Cyber.\n",
+ );
+ expect(stderr.text()).not.toContain("warning:");
+ });
+
+ test("prints trusted cyber access guidance without failing or corrupting JSON scans", async () => {
+ const stdout = capture();
+ const stderr = capture();
+ const deps = dependencies();
+ deps.createSecurity = () => ({
+ run: async (_repository, options) => {
+ options?.onWarning?.(
+ "Some cybersecurity requests or findings may be refused because your account does not have Trusted Access for Cyber. Apply at https://chatgpt.com/cyber.",
+ );
+ return fakeResult();
+ },
+ close: async () => {},
+ preflight: async () => fakePreflight(),
+ });
+
+ expect(
+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),
+ ).toBe(0);
+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
+ expect(stderr.text()).toContain(
+ "codex-security: warning: Some cybersecurity requests or findings may be refused because your account does not have Trusted Access for Cyber.",
+ );
+ expect(stderr.text()).toContain("Apply at https://chatgpt.com/cyber.");
+ });
+
+ test("prints unverified trusted cyber access guidance without corrupting JSON scans", async () => {
+ const stdout = capture();
+ const stderr = capture();
+ const deps = dependencies();
+ deps.createSecurity = () => ({
+ run: async (_repository, options) => {
+ options?.onWarning?.(
+ "Some cybersecurity requests or findings may be refused because your Trusted Access for Cyber status could not be verified. Check your access or apply at https://chatgpt.com/cyber.",
+ );
+ return fakeResult();
+ },
+ close: async () => {},
+ preflight: async () => fakePreflight(),
+ });
+
+ expect(
+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),
+ ).toBe(0);
+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
+ expect(stderr.text()).toContain(
+ "codex-security: warning: Some cybersecurity requests or findings may be refused because your Trusted Access for Cyber status could not be verified.",
+ );
+ expect(stderr.text()).toContain(
+ "Check your access or apply at https://chatgpt.com/cyber.",
+ );
+ });
+
+ test("prints organizational trusted cyber access guidance without corrupting JSON scans", async () => {
+ for (const warning of [
+ "Some cybersecurity requests or findings may be refused because your API organization does not have Trusted Access for Cyber. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",
+ "Some cybersecurity requests or findings may be refused because Trusted Access for Cyber for your API organization could not be verified. Check your organization's access or apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",
+ ]) {
+ const stdout = capture();
+ const stderr = capture();
+ const deps = dependencies();
+ deps.createSecurity = () => ({
+ run: async (_repository, options) => {
+ options?.onWarning?.(warning);
+ return fakeResult();
+ },
+ close: async () => {},
+ preflight: async () => fakePreflight(),
+ });
+
+ expect(
+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),
+ ).toBe(0);
+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
+ expect(stderr.text()).toContain(`codex-security: warning: ${warning}\n`);
+ expect(stderr.text()).not.toContain("chatgpt.com/cyber");
+ }
+ });
+
test("reports isolated observer failures without failing the scan", async () => {
const stdout = capture();
const stderr = capture();
diff --git a/sdk/typescript/tests-ts/support/api-events.ts b/sdk/typescript/tests-ts/support/api-events.ts
index c576d105d..9234de44e 100644
--- a/sdk/typescript/tests-ts/support/api-events.ts
+++ b/sdk/typescript/tests-ts/support/api-events.ts
@@ -12,12 +12,15 @@ export type ScanObserverName = Parameters<
type ScanEventOptions = Pick<
Parameters<typeof runScanEvents>[0],
+ | "authentication"
| "expectedFilesTotal"
| "onActivity"
| "onObserverError"
| "onProgress"
| "onReconnect"
| "onScanStarted"
+ | "onTrustedAccessStatus"
+ | "onWarning"
| "onWorkerStatus"
> & { abortController?: AbortController };