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

fix: support Amazon Bedrock authentication in Codex Security scans (#282)

Kyle Brownfb37bc996777
diff --git a/README.md b/README.md
index ff23b6029..fa71e84bd 100644
--- a/README.md
+++ b/README.md
@@ -33,8 +33,15 @@ npx @openai/codex-security scan . --provider openrouter --model anthropic/claude
export FIREWORKS_API_KEY="<your-fireworks-api-key>"
npx @openai/codex-security scan . --provider fireworks --model accounts/fireworks/models/qwen3-235b-a22b
+
+export AWS_BEARER_TOKEN_BEDROCK="<your-bedrock-api-key>"
+export AWS_REGION="us-east-2"
+npx @openai/codex-security scan . --provider amazon-bedrock --model openai.gpt-5.6-luna
```
+Amazon Bedrock also supports standard AWS access keys, profiles, web identity,
+container credentials, and the default AWS credential chain.
+
Local sign-in honors Codex's configured credential backend, including a system
keyring required by a managed device. Codex Security keeps login and scan
credentials in the same private, persistent state directory.
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md
index 9763b1f1c..f14e237dc 100644
--- a/sdk/typescript/README.md
+++ b/sdk/typescript/README.md
@@ -128,6 +128,10 @@ npx @openai/codex-security scan . --provider openrouter --model anthropic/claude
export FIREWORKS_API_KEY="<your-fireworks-api-key>"
npx @openai/codex-security scan . --provider fireworks --model accounts/fireworks/models/qwen3-235b-a22b
+
+export AWS_BEARER_TOKEN_BEDROCK="<your-bedrock-api-key>"
+export AWS_REGION="us-east-2"
+npx @openai/codex-security scan . --provider amazon-bedrock --model openai.gpt-5.6-luna
```
On Windows, set the API key in PowerShell:
@@ -429,6 +433,12 @@ Use `--provider openrouter` to send inference through OpenRouter. Set
Use `--provider fireworks` to send inference through Fireworks AI. Set
`FIREWORKS_API_KEY` and specify a supported model with `--model`.
+Use `--provider amazon-bedrock` to send inference through Amazon Bedrock. Set
+`AWS_REGION` and authenticate with `AWS_BEARER_TOKEN_BEDROCK`, standard AWS
+access keys, an AWS profile, web identity, container credentials, or the
+default AWS credential chain. Specify a supported Bedrock model with `--model`;
+OpenAI Bedrock models such as `openai.gpt-5.6-luna` support `--max-cost`.
+
Scan progress identifies the requested paths and reports actual ranking,
file-review, validation, and attack-path phases as they become available.
Interactive terminals show a full-screen view; CI, redirected output, and
diff --git a/sdk/typescript/_bundled_plugin/.mcp.json b/sdk/typescript/_bundled_plugin/.mcp.json
index d519616e8..41647750f 100644
--- a/sdk/typescript/_bundled_plugin/.mcp.json
+++ b/sdk/typescript/_bundled_plugin/.mcp.json
@@ -9,6 +9,22 @@
"CODEX_SQLITE_HOME",
"CODEX_API_KEY",
"CODEX_CLI_PATH",
+ "AWS_BEARER_TOKEN_BEDROCK",
+ "AWS_ACCESS_KEY_ID",
+ "AWS_SECRET_ACCESS_KEY",
+ "AWS_SESSION_TOKEN",
+ "AWS_PROFILE",
+ "AWS_REGION",
+ "AWS_DEFAULT_REGION",
+ "AWS_CONFIG_FILE",
+ "AWS_SHARED_CREDENTIALS_FILE",
+ "AWS_ROLE_ARN",
+ "AWS_ROLE_SESSION_NAME",
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
+ "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
+ "AWS_CONTAINER_CREDENTIALS_FULL_URI",
+ "AWS_CONTAINER_AUTHORIZATION_TOKEN",
+ "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",
"PYTHON",
"CODEX_SECURITY_KNOWLEDGE_BASE",
"CODEX_SECURITY_SCAN_ROOT",
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 8cabdbdfe..9754159eb 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -30,6 +30,7 @@ import {
isExternalModelProvider,
mergedCodexConfig,
scanModelConfiguration,
+ scanModelProvider,
type CodexSecurityConfig,
type JsonObject,
writeCodexConfig,
@@ -190,6 +191,18 @@ export type ScanAuthentication =
method: "stored_credentials";
credentialType?: "api_key" | "chatgpt";
verified: false;
+ }
+ | {
+ method: "aws_credentials";
+ source:
+ | "AWS_BEARER_TOKEN_BEDROCK"
+ | "AWS_ACCESS_KEY_ID"
+ | "AWS_PROFILE"
+ | "AWS_WEB_IDENTITY_TOKEN_FILE"
+ | "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
+ | "AWS_CONTAINER_CREDENTIALS_FULL_URI"
+ | "default_credential_chain";
+ verified: false;
};
export type ScanTrustedAccessStatus = "granted" | "not_granted" | "unknown";
@@ -324,6 +337,7 @@ export class CodexSecurity {
);
const configuration = await mergedCodexConfig(this.config);
const model = scanModelConfiguration(configuration);
+ const modelProvider = scanModelProvider(configuration);
validateScanCostLimit(options.maxCostUsd, model.model);
const archiveDir =
options.archiveExisting === true
@@ -343,12 +357,10 @@ export class CodexSecurity {
authentication: scanAuthentication(
this.#dependencies.environment,
options.auth,
- configuration["model_provider"],
+ modelProvider,
),
...model,
- ...(typeof configuration["model_provider"] === "string"
- ? { modelProvider: configuration["model_provider"] }
- : {}),
+ ...(typeof modelProvider === "string" ? { modelProvider } : {}),
...(options.maxCostUsd === undefined
? {}
: { maxCostUsd: options.maxCostUsd }),
@@ -421,7 +433,7 @@ export class CodexSecurity {
checkOpen();
const requestedConfig = await mergedCodexConfig(this.config);
- const modelProvider = requestedConfig["model_provider"];
+ const modelProvider = scanModelProvider(requestedConfig);
const externalProvider = isExternalModelProvider(modelProvider)
? EXTERNAL_CODEX_PROVIDERS[modelProvider]
: null;
@@ -532,7 +544,11 @@ export class CodexSecurity {
? "stored_credentials"
: null;
}
- if (!runtime.credentialsAvailable && apiKey === null) {
+ if (
+ !runtime.credentialsAvailable &&
+ apiKey === null &&
+ authentication.method !== "aws_credentials"
+ ) {
throw new AuthenticationRequiredError(
"No credentials were found. Run 'codex-security login', use " +
"'codex-security login --device-auth' on a remote or headless machine, or set " +
@@ -1476,13 +1492,15 @@ export class CodexSecurity {
environment: withoutCodexHome(processEnvironment),
signal,
});
- const credentialsAvailable = isExternalModelProvider(modelProvider)
- ? false
- : await initialCredentialsAvailable(
- processEnvironment,
- ambientHome,
- codexHome,
- );
+ const credentialsAvailable =
+ isExternalModelProvider(modelProvider) ||
+ modelProvider === "amazon-bedrock"
+ ? false
+ : await initialCredentialsAvailable(
+ processEnvironment,
+ ambientHome,
+ codexHome,
+ );
return {
codexHome,
persistentCredentialHome,
@@ -2114,6 +2132,22 @@ export function scanAuthentication(
auth: ScanAuthMode = "auto",
modelProvider?: unknown,
): ScanAuthentication {
+ if (modelProvider === "amazon-bedrock") {
+ const sources = [
+ "AWS_BEARER_TOKEN_BEDROCK",
+ "AWS_ACCESS_KEY_ID",
+ "AWS_PROFILE",
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
+ "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
+ "AWS_CONTAINER_CREDENTIALS_FULL_URI",
+ ] as const;
+ const source = sources.find((name) => environmentValue(environment, name));
+ return {
+ method: "aws_credentials",
+ source: source ?? "default_credential_chain",
+ verified: false,
+ };
+ }
if (auth === "chatgpt" && !isExternalModelProvider(modelProvider)) {
return { method: "stored_credentials", verified: false };
}
@@ -2170,14 +2204,19 @@ function selectedScanEnvironment(
const selectedProviderKey = isExternalModelProvider(modelProvider)
? EXTERNAL_CODEX_PROVIDERS[modelProvider].env_key
: null;
- if (auth !== "chatgpt" && selectedProviderKey === null) return environment;
+ const bedrockProvider = modelProvider === "amazon-bedrock";
+ if (auth !== "chatgpt" && selectedProviderKey === null && !bedrockProvider) {
+ return environment;
+ }
return Object.fromEntries(
Object.entries(environment).filter(([name]) => {
const key = name.toUpperCase();
if (key === "OPENAI_API_KEY" || key === "CODEX_API_KEY") return false;
- if (selectedProviderKey === null) return true;
if (key === "OPENROUTER_API_KEY" || key === "FIREWORKS_API_KEY") {
- return key === selectedProviderKey;
+ return (
+ !bedrockProvider &&
+ (selectedProviderKey === null || key === selectedProviderKey)
+ );
}
return true;
}),
@@ -2442,12 +2481,6 @@ export function scanPreflightCodexConfig(
};
const result = executionConfig(config);
- const modelProvider = result["model_provider"];
- if (isExternalModelProvider(modelProvider)) {
- result["model_providers"] = {
- [modelProvider]: { ...EXTERNAL_CODEX_PROVIDERS[modelProvider] },
- };
- }
const selectedProfile = safeProfileName(config["profile"])
? config["profile"]
: undefined;
@@ -2471,6 +2504,28 @@ export function scanPreflightCodexConfig(
}
if (Object.keys(sanitized).length > 0) result["profiles"] = sanitized;
}
+ const modelProvider = scanModelProvider(result);
+ if (isExternalModelProvider(modelProvider)) {
+ result["model_providers"] = {
+ [modelProvider]: { ...EXTERNAL_CODEX_PROVIDERS[modelProvider] },
+ };
+ } else if (modelProvider === "amazon-bedrock") {
+ const providers = config["model_providers"];
+ const provider = isRecord(providers) ? providers[modelProvider] : undefined;
+ const aws = isRecord(provider) ? provider["aws"] : undefined;
+ if (isRecord(aws)) {
+ const sanitized: JsonObject = {};
+ for (const key of ["region", "profile"]) {
+ const value = aws[key];
+ if (safeString(value, 512)) sanitized[key] = value;
+ }
+ if (Object.keys(sanitized).length > 0) {
+ result["model_providers"] = {
+ [modelProvider]: { aws: sanitized },
+ };
+ }
+ }
+ }
const rootMarkers = config["project_root_markers"];
if (Array.isArray(rootMarkers)) {
result["project_root_markers"] = rootMarkers
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index bf905ad9e..eac5b514d 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -51,6 +51,7 @@ import {
isExternalModelProvider,
mergedCodexConfig,
scanModelConfiguration,
+ scanModelProvider,
type CodexSecurityConfig,
type ExternalModelProvider,
type JsonObject,
@@ -200,7 +201,7 @@ const VALUE_OPTIONS = new Set([
"--reason",
]);
const PROVIDER_OPTION = z
- .enum(["openai", "openrouter", "fireworks"])
+ .enum(["openai", "openrouter", "fireworks", "amazon-bedrock"])
.default("openai")
.describe("Inference provider for scans.");
@@ -259,7 +260,7 @@ interface ScanArguments extends DeepScanOptions {
mode: ScanMode;
model?: string;
effort?: ModelReasoningEffort;
- provider?: "openai" | ExternalModelProvider;
+ provider?: "openai" | "amazon-bedrock" | ExternalModelProvider;
outputDir?: string;
archiveExisting: boolean;
pluginPath?: string;
@@ -2729,13 +2730,14 @@ async function runScan(
),
};
const selectedProfileName = config.codexOverrides?.["profile"];
+ const effectiveConfiguration = {
+ ...DEFAULT_CODEX_CONFIG,
+ ...config.codexOverrides,
+ };
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
- scanModelConfiguration({
- ...DEFAULT_CODEX_CONFIG,
- ...config.codexOverrides,
- }));
+ scanModelConfiguration(effectiveConfiguration));
let auth = arguments_.auth;
- const provider = config.codexOverrides?.["model_provider"];
+ const provider = scanModelProvider(effectiveConfiguration);
selectedAuthentication = scanAuthentication(
dependencies.environment,
auth,
@@ -2938,7 +2940,7 @@ async function runScan(
requested: auth ?? "auto",
method: authentication.method,
source:
- authentication.method === "api_key"
+ authentication.method !== "stored_credentials"
? authentication.source
: undefined,
verified: authentication.verified,
@@ -2947,7 +2949,9 @@ async function runScan(
dashboard.note(
authentication.method === "api_key"
? `Using API key from ${authentication.source}`
- : "Using stored Codex credentials",
+ : authentication.method === "aws_credentials"
+ ? `Using AWS credentials from ${authentication.source}`
+ : "Using stored Codex credentials",
);
return;
}
@@ -2959,6 +2963,10 @@ async function runScan(
progress?.stage(
"To use your ChatGPT sign-in, retry with --auth chatgpt.",
);
+ } else if (authentication.method === "aws_credentials") {
+ progress?.stage(
+ `Authentication: AWS credentials from ${authentication.source}.`,
+ );
} else {
progress?.stage("Authentication: stored Codex credentials.");
}
@@ -3179,7 +3187,7 @@ async function runScan(
reasoning_effort: effectivePreflight.reasoningEffort,
method: effectivePreflight.authentication.method,
source:
- effectivePreflight.authentication.method === "api_key"
+ effectivePreflight.authentication.method !== "stored_credentials"
? effectivePreflight.authentication.source
: undefined,
verified: effectivePreflight.authentication.verified,
@@ -3302,6 +3310,12 @@ function scanFailureMessage(
if (isLocalScanFailure(error)) return sanitizeDiagnosticValue(error);
switch (classifyConnectionFailure(error)) {
case "unauthorized":
+ if (authentication?.method === "aws_credentials") {
+ return (
+ `Authentication failed using AWS credentials from ${authentication.source}. ` +
+ "Check your Amazon Bedrock bearer token or AWS credential chain."
+ );
+ }
return authentication?.method === "api_key"
? `Authentication failed using ${authentication.source}. ` +
"Your ChatGPT sign-in was not used. " +
@@ -3309,6 +3323,12 @@ function scanFailureMessage(
: "Authentication failed using stored ChatGPT credentials. " +
"Sign in again with 'codex-security login' or provide a valid API key.";
case "forbidden":
+ if (authentication?.method === "aws_credentials") {
+ return (
+ `The AWS credentials from ${authentication.source} cannot access the configured Amazon Bedrock model. ` +
+ "Check your AWS identity and Bedrock model permissions."
+ );
+ }
return authentication?.method === "api_key"
? `The API key from ${authentication.source} cannot access the configured model. ` +
"Retry with '--auth chatgpt' or use an API key with model access."
@@ -3532,7 +3552,7 @@ export function parseCodexOverrides(
values: readonly string[],
model?: string,
effort?: ModelReasoningEffort,
- provider?: "openai" | ExternalModelProvider,
+ provider?: "openai" | "amazon-bedrock" | ExternalModelProvider,
): JsonObject {
const result = Object.create(null) as JsonObject;
if (model !== undefined) result["model"] = model;
@@ -3542,6 +3562,8 @@ export function parseCodexOverrides(
result["model_providers"] = {
[provider]: { ...EXTERNAL_CODEX_PROVIDERS[provider] },
};
+ } else if (provider === "amazon-bedrock") {
+ result["model_provider"] = provider;
}
for (const value of values) {
const separator = value.indexOf("=");
@@ -3598,7 +3620,10 @@ export function parseCodexOverrides(
"--effort conflicts with --codex model_reasoning_effort",
);
}
- if (isExternalModelProvider(provider) && key === "model_provider") {
+ if (
+ (isExternalModelProvider(provider) || provider === "amazon-bedrock") &&
+ key === "model_provider"
+ ) {
throw new CodexSecurityError(
"--provider conflicts with --codex model_provider",
);
@@ -3607,7 +3632,10 @@ export function parseCodexOverrides(
}
cursor[final] = parsed;
}
- if (isExternalModelProvider(provider) && !("model" in result)) {
+ if (
+ (isExternalModelProvider(provider) || provider === "amazon-bedrock") &&
+ !("model" in result)
+ ) {
throw new CodexSecurityError(
`--model is required when using --provider ${provider}`,
);
diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.ts
index 378d58ac3..0e6d5a730 100644
--- a/sdk/typescript/src/config.ts
+++ b/sdk/typescript/src/config.ts
@@ -76,17 +76,7 @@ deepFreezeJson(DEFAULT_CODEX_CONFIG);
export function scanModelConfiguration(
config: Readonly<JsonObject>,
): ScanModelConfiguration {
- const profileName = config["profile"];
- const profiles = config["profiles"];
- const configuredProfile =
- typeof profileName === "string" &&
- isObject(profiles) &&
- Object.hasOwn(profiles, profileName)
- ? profiles[profileName]
- : undefined;
- const selectedProfile = isObject(configuredProfile)
- ? configuredProfile
- : undefined;
+ const selectedProfile = selectedScanProfile(config);
const model =
selectedProfile !== undefined && Object.hasOwn(selectedProfile, "model")
? selectedProfile["model"]
@@ -112,6 +102,28 @@ export function scanModelConfiguration(
return { model, reasoningEffort };
}
+export function scanModelProvider(config: Readonly<JsonObject>): unknown {
+ const selectedProfile = selectedScanProfile(config);
+ return selectedProfile !== undefined &&
+ Object.hasOwn(selectedProfile, "model_provider")
+ ? selectedProfile["model_provider"]
+ : config["model_provider"];
+}
+
+function selectedScanProfile(
+ config: Readonly<JsonObject>,
+): Record<string, JsonValue> | undefined {
+ const profileName = config["profile"];
+ const profiles = config["profiles"];
+ const configuredProfile =
+ typeof profileName === "string" &&
+ isObject(profiles) &&
+ Object.hasOwn(profiles, profileName)
+ ? profiles[profileName]
+ : undefined;
+ return isObject(configuredProfile) ? configuredProfile : undefined;
+}
+
export async function mergedCodexConfig(
config: CodexSecurityConfig,
): Promise<JsonObject> {
diff --git a/sdk/typescript/src/cost.ts b/sdk/typescript/src/cost.ts
index fdead4656..fb94137f1 100644
--- a/sdk/typescript/src/cost.ts
+++ b/sdk/typescript/src/cost.ts
@@ -794,7 +794,10 @@ export function estimateScanCost(
usage: unknown,
): ScanCost | null {
if (model === undefined) return null;
- const pricing = MODEL_PRICING_NANODOLLARS[model];
+ const pricingModel = model.startsWith("openai.")
+ ? model.slice("openai.".length)
+ : model;
+ const pricing = MODEL_PRICING_NANODOLLARS[pricingModel];
const normalized = tokenUsage(usage);
if (pricing === undefined || normalized === null) return null;
const [inputRate, cachedInputRate, cacheWriteInputRate, outputRate] = pricing;
diff --git a/sdk/typescript/tests-ts/api-preflight-config.test.ts b/sdk/typescript/tests-ts/api-preflight-config.test.ts
new file mode 100644
index 000000000..72e90aea5
--- /dev/null
+++ b/sdk/typescript/tests-ts/api-preflight-config.test.ts
@@ -0,0 +1,492 @@
+import { execFileSync } from "node:child_process";
+import { mkdir, mkdtemp, readFile, realpath, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, describe, expect, test } from "bun:test";
+import {
+ scanPreflightCodexConfig,
+ scanRuntimeCodexConfig,
+} from "../src/api.js";
+import {
+ FIREWORKS_CODEX_PROVIDER,
+ OPENROUTER_CODEX_PROVIDER,
+ scanModelProvider,
+ writeCodexConfig,
+ type JsonObject,
+} from "../src/config.js";
+import { PLUGIN_ROOT } from "./plugin-root.js";
+
+const temporaryDirectories: string[] = [];
+const EXTERNAL_PROVIDER_CASES = [
+ [
+ "OpenRouter",
+ "openrouter",
+ "OPENROUTER_API_KEY",
+ "anthropic/claude-sonnet-4.5",
+ OPENROUTER_CODEX_PROVIDER,
+ ],
+ [
+ "Fireworks AI",
+ "fireworks",
+ "FIREWORKS_API_KEY",
+ "accounts/fireworks/models/qwen3-235b-a22b",
+ FIREWORKS_CODEX_PROVIDER,
+ ],
+] as const;
+
+afterEach(async () => {
+ await Promise.all(
+ temporaryDirectories
+ .splice(0)
+ .map((path) => rm(path, { recursive: true, force: true })),
+ );
+});
+
+async function temporaryDirectory(): Promise<string> {
+ const path = await realpath(
+ await mkdtemp(join(tmpdir(), "codex-security-preflight-")),
+ );
+ temporaryDirectories.push(path);
+ return path;
+}
+
+describe("CodexSecurity preflight configuration", () => {
+ test("uses a root-read filesystem profile with writable workspace and workbench state", () => {
+ const stateDirectory = join(tmpdir(), "codex-security-persistent-state");
+ const original = {
+ sandbox_mode: "workspace-write",
+ allow_login_shell: true,
+ default_permissions: "unsafe",
+ permissions: {
+ existing: { filesystem: { ":root": "read" } },
+ codex_security_scan: {
+ extends: ":workspace",
+ filesystem: { ":tmpdir": "write" },
+ },
+ },
+ };
+
+ expect(scanRuntimeCodexConfig(original, stateDirectory)).toEqual({
+ allow_login_shell: false,
+ default_permissions: "codex_security_scan",
+ permissions: {
+ existing: { filesystem: { ":root": "read" } },
+ codex_security_scan: {
+ filesystem: {
+ ":root": "read",
+ ":workspace_roots": "write",
+ [stateDirectory]: "write",
+ },
+ },
+ },
+ });
+ expect(original).toMatchObject({
+ sandbox_mode: "workspace-write",
+ allow_login_shell: true,
+ default_permissions: "unsafe",
+ });
+ });
+
+ test("keeps persistent credentials read-only within writable scan state", () => {
+ const stateDirectory = join(tmpdir(), "codex-security-persistent-state");
+ const credentialHome = join(stateDirectory, "codex-home");
+ const config = scanRuntimeCodexConfig({}, stateDirectory, credentialHome);
+
+ expect(config).toMatchObject({
+ permissions: {
+ codex_security_scan: {
+ filesystem: {
+ ":root": "read",
+ ":workspace_roots": "write",
+ [stateDirectory]: "write",
+ [credentialHome]: "read",
+ },
+ },
+ },
+ });
+ });
+
+ test("projects only capability and trust metadata into the readable preflight config", async () => {
+ const root = await temporaryDirectory();
+ const configPath = join(root, "config-preflight.toml");
+ const repository = join(root, "repository");
+ const ordinaryProject = join(
+ root,
+ "settings-service-development-monkey-dataset",
+ );
+ await mkdir(repository);
+ const sanitized = scanPreflightCodexConfig({
+ model: "gpt-5.6-sol",
+ model_reasoning_effort: "high",
+ features: {
+ plugins: true,
+ goals: true,
+ multi_agent_v2: { enabled: false, secret: "FEATURE_SECRET" },
+ api_key: "FEATURE_KEY",
+ },
+ agents: { max_threads: 12, max_depth: 2, token: "AGENT_TOKEN" },
+ profile: "review",
+ profiles: {
+ review: {
+ model: "profile-model",
+ features: { goals: true, secret: "PROFILE_SECRET" },
+ agents: { max_threads: 4, token: "PROFILE_AGENT_TOKEN" },
+ shell_environment_policy: { set: { SECRET: "PROFILE_ENV_SECRET" } },
+ },
+ secret_profile: { features: { goals: false } },
+ "credential-prod": { features: { goals: false } },
+ development: { features: { goals: true } },
+ ["a".repeat(129)]: { features: { goals: false } },
+ },
+ project_root_markers: [
+ ".git",
+ ".workspace",
+ ".env",
+ "PASSWORD_VALUE",
+ "settings.gradle",
+ "a".repeat(257),
+ ],
+ projects: {
+ [repository]: { trust_level: "trusted", token: "PROJECT_TOKEN" },
+ [join(root, "secret-project")]: { trust_level: "trusted" },
+ [join(root, "bearer-PRIVATE")]: { trust_level: "trusted" },
+ [ordinaryProject]: { trust_level: "untrusted" },
+ relative: { trust_level: "trusted" },
+ [join(root, "bad-trust")]: { trust_level: "PROJECT_SECRET" },
+ },
+ mcp_servers: { private: { bearer_token: "MCP_TOKEN" } },
+ shell_environment_policy: { set: { SECRET: "SHELL_SECRET" } },
+ });
+ expect(sanitized).toEqual({
+ model: "gpt-5.6-sol",
+ model_reasoning_effort: "high",
+ features: { goals: true, multi_agent_v2: { enabled: false } },
+ agents: { max_threads: 12, max_depth: 2 },
+ profile: "review",
+ profiles: {
+ review: {
+ model: "profile-model",
+ features: { goals: true },
+ agents: { max_threads: 4 },
+ },
+ development: { features: { goals: true } },
+ },
+ project_root_markers: [".git", ".workspace", "settings.gradle"],
+ projects: {
+ [repository]: { trust_level: "trusted" },
+ [ordinaryProject]: { trust_level: "untrusted" },
+ },
+ });
+ await writeCodexConfig(configPath, sanitized);
+ const serialized = await readFile(configPath, "utf8");
+ for (const secret of [
+ "FEATURE_SECRET",
+ "FEATURE_KEY",
+ "AGENT_TOKEN",
+ "PROFILE_SECRET",
+ "PROFILE_AGENT_TOKEN",
+ "PROFILE_ENV_SECRET",
+ "PROJECT_TOKEN",
+ "MCP_TOKEN",
+ "SHELL_SECRET",
+ ]) {
+ expect(serialized).not.toContain(secret);
+ }
+ const interpreter =
+ Bun.which("python3") ?? Bun.which("python") ?? Bun.which("py");
+ expect(interpreter).not.toBeNull();
+ const output = execFileSync(
+ interpreter!,
+ [
+ join(PLUGIN_ROOT, "scripts", "config_preflight.py"),
+ "--skill",
+ "security-scan",
+ "--config",
+ configPath,
+ "--cwd",
+ repository,
+ "--multi-agent-runtime-owner",
+ "native",
+ "--multi-agent-runtime-version",
+ "v1",
+ "--multi-agent-runtime-provenance",
+ "tool-surface",
+ "--runtime-check",
+ "delegation_available=true",
+ "--runtime-check",
+ "goal_tools_available=true",
+ "--effective-config",
+ "features.goals=true",
+ ],
+ {
+ env: { PATH: process.env["PATH"], CODEX_HOME: join(root, "denied") },
+ encoding: "utf8",
+ },
+ );
+ const preflight = JSON.parse(output) as Record<string, unknown>;
+ expect(preflight["status"]).toBe("ready");
+ expect(preflight["config_resolution"]).toBe("manual-layers");
+ expect(preflight["config_paths"]).toEqual([configPath]);
+ expect(preflight["config_profile"]).toBe("review");
+ expect(JSON.stringify(preflight)).toContain("max_threads");
+ expect(JSON.stringify(preflight)).toContain("12");
+
+ const bridgeConfigPath = join(root, "bridge-preflight.toml");
+ const bridge = scanPreflightCodexConfig({
+ features: { goals: true },
+ multiagent_config: {
+ max_concurrency: 12,
+ token: "BRIDGE_TOKEN",
+ },
+ mcp_servers: { private: { bearer_token: "BRIDGE_MCP_TOKEN" } },
+ });
+ expect(bridge).toEqual({
+ features: { goals: true },
+ multiagent_config: { max_concurrency: 12 },
+ });
+ await writeCodexConfig(bridgeConfigPath, bridge);
+ const bridgeSerialized = await readFile(bridgeConfigPath, "utf8");
+ expect(bridgeSerialized).not.toContain("BRIDGE_TOKEN");
+ expect(bridgeSerialized).not.toContain("BRIDGE_MCP_TOKEN");
+ const bridgeOutput = execFileSync(
+ interpreter!,
+ [
+ join(PLUGIN_ROOT, "scripts", "config_preflight.py"),
+ "--skill",
+ "security-scan",
+ "--config",
+ bridgeConfigPath,
+ "--cwd",
+ repository,
+ "--multi-agent-runtime-owner",
+ "codex-bridge",
+ "--multi-agent-runtime-version",
+ "v2",
+ "--multi-agent-runtime-provenance",
+ "verified-bridge",
+ "--runtime-check",
+ "delegation_available=true",
+ "--runtime-check",
+ "goal_tools_available=true",
+ "--effective-config",
+ "features.goals=true",
+ ],
+ {
+ env: { PATH: process.env["PATH"], CODEX_HOME: join(root, "denied") },
+ encoding: "utf8",
+ },
+ );
+ const bridgePreflight = JSON.parse(bridgeOutput) as Record<string, unknown>;
+ expect(bridgePreflight["status"]).toBe("ready");
+ expect(bridgePreflight["config_resolution"]).toBe("manual-layers");
+ expect(bridgePreflight["config_paths"]).toEqual([bridgeConfigPath]);
+ expect(bridgePreflight["multi_agent_mode"]).toBe("bridge-v2");
+ expect(JSON.stringify(bridgePreflight)).toContain(
+ "multiagent_config.max_concurrency",
+ );
+ expect(JSON.stringify(bridgePreflight)).toContain("12");
+ expect(() =>
+ scanPreflightCodexConfig({
+ projects: Object.fromEntries(
+ Array.from({ length: 256 }, (_, index) => [
+ `/workspace/${index}/${"界".repeat(1300)}`,
+ { trust_level: "trusted" },
+ ]),
+ ),
+ }),
+ ).toThrow(
+ "sanitized Codex Security preflight config exceeds the size limit",
+ );
+ const emptyV2 = scanPreflightCodexConfig({
+ features: {
+ multi_agent_v2: {
+ unknown: true,
+ max_concurrent_threads_per_session: 1_000_001,
+ },
+ },
+ });
+ expect(emptyV2).toEqual({});
+ await expect(
+ writeCodexConfig(join(root, "empty-v2.toml"), emptyV2),
+ ).resolves.toBeUndefined();
+ });
+
+ test("prioritizes the selected profile and active project before projection limits", () => {
+ const activeProject = "/workspace/active";
+ const profiles = Object.fromEntries([
+ ...Array.from({ length: 256 }, (_, index) => [
+ `profile_${index}`,
+ { features: { goals: index % 2 === 0 } },
+ ]),
+ ["selected", { agents: { max_threads: 17 } }],
+ ]);
+ const projects = Object.fromEntries([
+ ...Array.from({ length: 256 }, (_, index) => [
+ `/workspace/project-${index}`,
+ { trust_level: "untrusted" },
+ ]),
+ [activeProject, { trust_level: "trusted" }],
+ ]);
+
+ const prioritized = scanPreflightCodexConfig(
+ {
+ profile: "selected",
+ profiles,
+ projects,
+ },
+ join(activeProject, "packages", "service"),
+ );
+
+ expect(prioritized["profile"]).toBe("selected");
+ expect(Object.keys(prioritized["profiles"] as JsonObject)).toHaveLength(
+ 256,
+ );
+ expect(prioritized["profiles"]).toMatchObject({
+ selected: { agents: { max_threads: 17 } },
+ });
+ expect(Object.keys(prioritized["projects"] as JsonObject)).toHaveLength(
+ 256,
+ );
+ expect(prioritized["projects"]).toMatchObject({
+ [activeProject]: { trust_level: "trusted" },
+ });
+
+ const validProfiles = Object.fromEntries(
+ Array.from({ length: 256 }, (_, index) => [
+ `valid_${index}`,
+ { features: { goals: true } },
+ ]),
+ );
+ const validProjects = Object.fromEntries(
+ Array.from({ length: 256 }, (_, index) => [
+ `/valid/project-${index}`,
+ { trust_level: "trusted" },
+ ]),
+ );
+ const afterInvalid = scanPreflightCodexConfig({
+ profiles: {
+ ...Object.fromEntries(
+ Array.from({ length: 256 }, (_, index) => [
+ `invalid.profile.${index}`,
+ { features: { goals: false } },
+ ]),
+ ),
+ ...validProfiles,
+ },
+ projects: {
+ ...Object.fromEntries(
+ Array.from({ length: 256 }, (_, index) => [
+ `relative-${index}`,
+ { trust_level: "trusted" },
+ ]),
+ ),
+ ...validProjects,
+ },
+ });
+
+ expect(Object.keys(afterInvalid["profiles"] as JsonObject)).toHaveLength(
+ 256,
+ );
+ expect(afterInvalid["profiles"]).toMatchObject({
+ valid_255: { features: { goals: true } },
+ });
+ expect(Object.keys(afterInvalid["projects"] as JsonObject)).toHaveLength(
+ 256,
+ );
+ expect(afterInvalid["projects"]).toMatchObject({
+ "/valid/project-255": { trust_level: "trusted" },
+ });
+ });
+
+ test.each(EXTERNAL_PROVIDER_CASES)(
+ "keeps the %s provider in sanitized scan configuration",
+ (_name, provider, _apiKey, model, providerConfig) => {
+ expect(
+ scanPreflightCodexConfig({
+ model,
+ model_provider: provider,
+ model_providers: {
+ [provider]: providerConfig,
+ private: { api_key: "synthetic-secret" },
+ },
+ }),
+ ).toEqual({
+ model,
+ model_provider: provider,
+ model_providers: { [provider]: providerConfig },
+ });
+ },
+ );
+
+ test.each(EXTERNAL_PROVIDER_CASES)(
+ "preserves the selected %s profile provider in saved scan recipes",
+ (_name, provider, _apiKey, model, providerConfig) => {
+ const config = scanPreflightCodexConfig({
+ model_provider: "openai",
+ profile: "selected",
+ profiles: { selected: { model, model_provider: provider } },
+ model_providers: {
+ [provider]: {
+ ...providerConfig,
+ api_key: "synthetic-provider-secret",
+ },
+ private: { bearer_token: "synthetic-unrelated-secret" },
+ },
+ });
+
+ expect(config).toEqual({
+ model_provider: "openai",
+ profile: "selected",
+ profiles: { selected: { model, model_provider: provider } },
+ model_providers: { [provider]: providerConfig },
+ });
+ expect(scanModelProvider(config)).toBe(provider);
+ expect(JSON.stringify(config)).not.toContain("synthetic-");
+ },
+ );
+
+ test("preserves safe Bedrock provider settings in profile-selected scan recipes", () => {
+ const config = scanPreflightCodexConfig({
+ model_provider: "openai",
+ profile: "bedrock",
+ profiles: {
+ bedrock: {
+ model: "openai.gpt-5.6-luna",
+ model_provider: "amazon-bedrock",
+ },
+ },
+ model_providers: {
+ "amazon-bedrock": {
+ aws: {
+ region: "us-east-2",
+ profile: "security-prod",
+ access_key_id: "synthetic-aws-access-key",
+ secret_access_key: "synthetic-aws-secret-key",
+ session_token: "synthetic-aws-session-token",
+ bearer_token: "synthetic-bedrock-bearer",
+ },
+ api_key: "synthetic-provider-key",
+ },
+ openrouter: { api_key: "synthetic-unrelated-key" },
+ },
+ });
+
+ expect(config).toEqual({
+ model_provider: "openai",
+ profile: "bedrock",
+ profiles: {
+ bedrock: {
+ model: "openai.gpt-5.6-luna",
+ model_provider: "amazon-bedrock",
+ },
+ },
+ model_providers: {
+ "amazon-bedrock": {
+ aws: { region: "us-east-2", profile: "security-prod" },
+ },
+ },
+ });
+ expect(scanModelProvider(config)).toBe("amazon-bedrock");
+ expect(JSON.stringify(config)).not.toContain("synthetic-");
+ });
+});
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 996c6a2be..bd2de2ebc 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -38,13 +38,10 @@ import {
classifyConnectionFailure,
environmentValue,
initialCredentialsAvailable,
- scanPreflightCodexConfig,
- scanRuntimeCodexConfig,
} from "../src/api.js";
import {
FIREWORKS_CODEX_PROVIDER,
OPENROUTER_CODEX_PROVIDER,
- writeCodexConfig,
type JsonObject,
} from "../src/config.js";
import { estimateScanCost, type ScanCost } from "../src/cost.js";
@@ -80,6 +77,50 @@ const EXTERNAL_PROVIDER_CASES = [
FIREWORKS_CODEX_PROVIDER,
],
] as const;
+const BEDROCK_AUTHENTICATION_CASES = [
+ [
+ "Bedrock bearer token",
+ {
+ AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer",
+ AWS_REGION: "us-west-2",
+ },
+ "AWS_BEARER_TOKEN_BEDROCK",
+ ],
+ [
+ "AWS environment credentials",
+ {
+ AWS_ACCESS_KEY_ID: "synthetic-aws-access-key",
+ AWS_SECRET_ACCESS_KEY: "synthetic-aws-secret-key",
+ AWS_SESSION_TOKEN: "synthetic-aws-session-token",
+ },
+ "AWS_ACCESS_KEY_ID",
+ ],
+ [
+ "AWS profile",
+ {
+ AWS_PROFILE: "synthetic-bedrock-profile",
+ AWS_DEFAULT_REGION: "us-east-1",
+ },
+ "AWS_PROFILE",
+ ],
+ [
+ "AWS web identity",
+ {
+ AWS_ROLE_ARN: "arn:aws:iam::123456789012:role/synthetic-bedrock",
+ AWS_WEB_IDENTITY_TOKEN_FILE: "/synthetic/web-identity-token",
+ },
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
+ ],
+ [
+ "AWS container credentials",
+ {
+ AWS_CONTAINER_CREDENTIALS_RELATIVE_URI:
+ "/synthetic/container-credentials",
+ },
+ "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
+ ],
+ ["default AWS credential chain", {}, "default_credential_chain"],
+] as const;
const TestClientBase = CodexSecurity as unknown as new (
config: Record<string, unknown>,
dependencies: Record<string, unknown>,
@@ -261,353 +302,6 @@ describe("CodexSecurity orchestration", () => {
);
});
- test("uses a root-read filesystem profile with writable workspace and workbench state", () => {
- const stateDirectory = join(tmpdir(), "codex-security-persistent-state");
- const original = {
- sandbox_mode: "workspace-write",
- allow_login_shell: true,
- default_permissions: "unsafe",
- permissions: {
- existing: { filesystem: { ":root": "read" } },
- codex_security_scan: {
- extends: ":workspace",
- filesystem: { ":tmpdir": "write" },
- },
- },
- };
-
- expect(scanRuntimeCodexConfig(original, stateDirectory)).toEqual({
- allow_login_shell: false,
- default_permissions: "codex_security_scan",
- permissions: {
- existing: { filesystem: { ":root": "read" } },
- codex_security_scan: {
- filesystem: {
- ":root": "read",
- ":workspace_roots": "write",
- [stateDirectory]: "write",
- },
- },
- },
- });
- expect(original).toMatchObject({
- sandbox_mode: "workspace-write",
- allow_login_shell: true,
- default_permissions: "unsafe",
- });
- });
-
- test("keeps persistent credentials read-only within writable scan state", () => {
- const stateDirectory = join(tmpdir(), "codex-security-persistent-state");
- const credentialHome = join(stateDirectory, "codex-home");
- const config = scanRuntimeCodexConfig({}, stateDirectory, credentialHome);
-
- expect(config).toMatchObject({
- permissions: {
- codex_security_scan: {
- filesystem: {
- ":root": "read",
- ":workspace_roots": "write",
- [stateDirectory]: "write",
- [credentialHome]: "read",
- },
- },
- },
- });
- });
-
- test("projects only capability and trust metadata into the readable preflight config", async () => {
- const root = await temporaryDirectory();
- const configPath = join(root, "config-preflight.toml");
- const repository = join(root, "repository");
- const ordinaryProject = join(
- root,
- "settings-service-development-monkey-dataset",
- );
- await mkdir(repository);
- const sanitized = scanPreflightCodexConfig({
- model: "gpt-5.6-sol",
- model_reasoning_effort: "high",
- features: {
- plugins: true,
- goals: true,
- multi_agent_v2: { enabled: false, secret: "FEATURE_SECRET" },
- api_key: "FEATURE_KEY",
- },
- agents: { max_threads: 12, max_depth: 2, token: "AGENT_TOKEN" },
- profile: "review",
- profiles: {
- review: {
- model: "profile-model",
- features: { goals: true, secret: "PROFILE_SECRET" },
- agents: { max_threads: 4, token: "PROFILE_AGENT_TOKEN" },
- shell_environment_policy: { set: { SECRET: "PROFILE_ENV_SECRET" } },
- },
- secret_profile: { features: { goals: false } },
- "credential-prod": { features: { goals: false } },
- development: { features: { goals: true } },
- ["a".repeat(129)]: { features: { goals: false } },
- },
- project_root_markers: [
- ".git",
- ".workspace",
- ".env",
- "PASSWORD_VALUE",
- "settings.gradle",
- "a".repeat(257),
- ],
- projects: {
- [repository]: { trust_level: "trusted", token: "PROJECT_TOKEN" },
- [join(root, "secret-project")]: { trust_level: "trusted" },
- [join(root, "bearer-PRIVATE")]: { trust_level: "trusted" },
- [ordinaryProject]: { trust_level: "untrusted" },
- relative: { trust_level: "trusted" },
- [join(root, "bad-trust")]: { trust_level: "PROJECT_SECRET" },
- },
- mcp_servers: { private: { bearer_token: "MCP_TOKEN" } },
- shell_environment_policy: { set: { SECRET: "SHELL_SECRET" } },
- });
- expect(sanitized).toEqual({
- model: "gpt-5.6-sol",
- model_reasoning_effort: "high",
- features: { goals: true, multi_agent_v2: { enabled: false } },
- agents: { max_threads: 12, max_depth: 2 },
- profile: "review",
- profiles: {
- review: {
- model: "profile-model",
- features: { goals: true },
- agents: { max_threads: 4 },
- },
- development: { features: { goals: true } },
- },
- project_root_markers: [".git", ".workspace", "settings.gradle"],
- projects: {
- [repository]: { trust_level: "trusted" },
- [ordinaryProject]: { trust_level: "untrusted" },
- },
- });
- await writeCodexConfig(configPath, sanitized);
- const serialized = await readFile(configPath, "utf8");
- for (const secret of [
- "FEATURE_SECRET",
- "FEATURE_KEY",
- "AGENT_TOKEN",
- "PROFILE_SECRET",
- "PROFILE_AGENT_TOKEN",
- "PROFILE_ENV_SECRET",
- "PROJECT_TOKEN",
- "MCP_TOKEN",
- "SHELL_SECRET",
- ]) {
- expect(serialized).not.toContain(secret);
- }
- const interpreter =
- Bun.which("python3") ?? Bun.which("python") ?? Bun.which("py");
- expect(interpreter).not.toBeNull();
- const output = execFileSync(
- interpreter!,
- [
- join(PLUGIN_ROOT, "scripts", "config_preflight.py"),
- "--skill",
- "security-scan",
- "--config",
- configPath,
- "--cwd",
- repository,
- "--multi-agent-runtime-owner",
- "native",
- "--multi-agent-runtime-version",
- "v1",
- "--multi-agent-runtime-provenance",
- "tool-surface",
- "--runtime-check",
- "delegation_available=true",
- "--runtime-check",
- "goal_tools_available=true",
- "--effective-config",
- "features.goals=true",
- ],
- {
- env: { PATH: process.env["PATH"], CODEX_HOME: join(root, "denied") },
- encoding: "utf8",
- },
- );
- const preflight = JSON.parse(output) as Record<string, unknown>;
- expect(preflight["status"]).toBe("ready");
- expect(preflight["config_resolution"]).toBe("manual-layers");
- expect(preflight["config_paths"]).toEqual([configPath]);
- expect(preflight["config_profile"]).toBe("review");
- expect(JSON.stringify(preflight)).toContain("max_threads");
- expect(JSON.stringify(preflight)).toContain("12");
-
- const bridgeConfigPath = join(root, "bridge-preflight.toml");
- const bridge = scanPreflightCodexConfig({
- features: { goals: true },
- multiagent_config: {
- max_concurrency: 12,
- token: "BRIDGE_TOKEN",
- },
- mcp_servers: { private: { bearer_token: "BRIDGE_MCP_TOKEN" } },
- });
- expect(bridge).toEqual({
- features: { goals: true },
- multiagent_config: { max_concurrency: 12 },
- });
- await writeCodexConfig(bridgeConfigPath, bridge);
- const bridgeSerialized = await readFile(bridgeConfigPath, "utf8");
- expect(bridgeSerialized).not.toContain("BRIDGE_TOKEN");
- expect(bridgeSerialized).not.toContain("BRIDGE_MCP_TOKEN");
- const bridgeOutput = execFileSync(
- interpreter!,
- [
- join(PLUGIN_ROOT, "scripts", "config_preflight.py"),
- "--skill",
- "security-scan",
- "--config",
- bridgeConfigPath,
- "--cwd",
- repository,
- "--multi-agent-runtime-owner",
- "codex-bridge",
- "--multi-agent-runtime-version",
- "v2",
- "--multi-agent-runtime-provenance",
- "verified-bridge",
- "--runtime-check",
- "delegation_available=true",
- "--runtime-check",
- "goal_tools_available=true",
- "--effective-config",
- "features.goals=true",
- ],
- {
- env: { PATH: process.env["PATH"], CODEX_HOME: join(root, "denied") },
- encoding: "utf8",
- },
- );
- const bridgePreflight = JSON.parse(bridgeOutput) as Record<string, unknown>;
- expect(bridgePreflight["status"]).toBe("ready");
- expect(bridgePreflight["config_resolution"]).toBe("manual-layers");
- expect(bridgePreflight["config_paths"]).toEqual([bridgeConfigPath]);
- expect(bridgePreflight["multi_agent_mode"]).toBe("bridge-v2");
- expect(JSON.stringify(bridgePreflight)).toContain(
- "multiagent_config.max_concurrency",
- );
- expect(JSON.stringify(bridgePreflight)).toContain("12");
- expect(() =>
- scanPreflightCodexConfig({
- projects: Object.fromEntries(
- Array.from({ length: 256 }, (_, index) => [
- `/workspace/${index}/${"界".repeat(1300)}`,
- { trust_level: "trusted" },
- ]),
- ),
- }),
- ).toThrow(
- "sanitized Codex Security preflight config exceeds the size limit",
- );
- const emptyV2 = scanPreflightCodexConfig({
- features: {
- multi_agent_v2: {
- unknown: true,
- max_concurrent_threads_per_session: 1_000_001,
- },
- },
- });
- expect(emptyV2).toEqual({});
- await expect(
- writeCodexConfig(join(root, "empty-v2.toml"), emptyV2),
- ).resolves.toBeUndefined();
- });
-
- test("prioritizes the selected profile and active project before projection limits", () => {
- const activeProject = "/workspace/active";
- const profiles = Object.fromEntries([
- ...Array.from({ length: 256 }, (_, index) => [
- `profile_${index}`,
- { features: { goals: index % 2 === 0 } },
- ]),
- ["selected", { agents: { max_threads: 17 } }],
- ]);
- const projects = Object.fromEntries([
- ...Array.from({ length: 256 }, (_, index) => [
- `/workspace/project-${index}`,
- { trust_level: "untrusted" },
- ]),
- [activeProject, { trust_level: "trusted" }],
- ]);
-
- const prioritized = scanPreflightCodexConfig(
- {
- profile: "selected",
- profiles,
- projects,
- },
- join(activeProject, "packages", "service"),
- );
-
- expect(prioritized["profile"]).toBe("selected");
- expect(Object.keys(prioritized["profiles"] as JsonObject)).toHaveLength(
- 256,
- );
- expect(prioritized["profiles"]).toMatchObject({
- selected: { agents: { max_threads: 17 } },
- });
- expect(Object.keys(prioritized["projects"] as JsonObject)).toHaveLength(
- 256,
- );
- expect(prioritized["projects"]).toMatchObject({
- [activeProject]: { trust_level: "trusted" },
- });
-
- const validProfiles = Object.fromEntries(
- Array.from({ length: 256 }, (_, index) => [
- `valid_${index}`,
- { features: { goals: true } },
- ]),
- );
- const validProjects = Object.fromEntries(
- Array.from({ length: 256 }, (_, index) => [
- `/valid/project-${index}`,
- { trust_level: "trusted" },
- ]),
- );
- const afterInvalid = scanPreflightCodexConfig({
- profiles: {
- ...Object.fromEntries(
- Array.from({ length: 256 }, (_, index) => [
- `invalid.profile.${index}`,
- { features: { goals: false } },
- ]),
- ),
- ...validProfiles,
- },
- projects: {
- ...Object.fromEntries(
- Array.from({ length: 256 }, (_, index) => [
- `relative-${index}`,
- { trust_level: "trusted" },
- ]),
- ),
- ...validProjects,
- },
- });
-
- expect(Object.keys(afterInvalid["profiles"] as JsonObject)).toHaveLength(
- 256,
- );
- expect(afterInvalid["profiles"]).toMatchObject({
- valid_255: { features: { goals: true } },
- });
- expect(Object.keys(afterInvalid["projects"] as JsonObject)).toHaveLength(
- 256,
- );
- expect(afterInvalid["projects"]).toMatchObject({
- "/valid/project-255": { trust_level: "trusted" },
- });
- });
-
test("selects a real-scan target in the active repository layout", async () => {
await expect(
stat(join(REPOSITORY_ROOT, INTEGRATION_TARGET)),
@@ -1073,26 +767,6 @@ describe("CodexSecurity orchestration", () => {
await client.close();
});
- test.each(EXTERNAL_PROVIDER_CASES)(
- "keeps the %s provider in sanitized scan configuration",
- (_name, provider, _apiKey, model, providerConfig) => {
- expect(
- scanPreflightCodexConfig({
- model,
- model_provider: provider,
- model_providers: {
- [provider]: providerConfig,
- private: { api_key: "synthetic-secret" },
- },
- }),
- ).toEqual({
- model,
- model_provider: provider,
- model_providers: { [provider]: providerConfig },
- });
- },
- );
-
test.each(EXTERNAL_PROVIDER_CASES)(
"requires the %s API key instead of accepting another provider's credentials",
async (name, provider, apiKey, model, providerConfig) => {
@@ -1222,6 +896,251 @@ describe("CodexSecurity orchestration", () => {
},
);
+ test.each(BEDROCK_AUTHENTICATION_CASES)(
+ "runs Amazon Bedrock scans through %s without signing in to OpenAI",
+ async (_name, credentials, source) => {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ const codexHome = join(root, "codex-home");
+ const scanDir = join(root, "scan");
+ await mkdir(repository);
+ await mkdir(codexHome);
+ await mkdir(scanDir, { mode: 0o700 });
+ let codexOptions: CodexOptions | null = null;
+ let authentication: ScanAuthentication | undefined;
+ const environment = {
+ OPENAI_API_KEY: "synthetic-openai-key",
+ CODEX_API_KEY: "synthetic-codex-key",
+ OPENROUTER_API_KEY: "synthetic-openrouter-key",
+ FIREWORKS_API_KEY: "synthetic-fireworks-key",
+ ...credentials,
+ };
+ const client = new TestClient(
+ {
+ codexOverrides: {
+ model: "openai.gpt-5.6-luna",
+ model_provider: "amazon-bedrock",
+ },
+ },
+ {
+ environment,
+ prepareRuntime: async () => ({
+ ...preparedRuntime(codexHome),
+ environment,
+ credentialsAvailable: false,
+ }),
+ resolvePluginPython: async () => "/managed/python",
+ prepareOutputDir: async () => scanDir,
+ repositoryRevision: async () => "deadbeef",
+ resolveCodexCommand: () => {
+ throw new Error("Amazon Bedrock must not sign in to OpenAI");
+ },
+ createCodex: (options: CodexOptions) => {
+ codexOptions = options;
+ return {
+ startThread: () => ({
+ id: null,
+ async runStreamed() {
+ await copyCompletedScan(root);
+ return { events: completedEvents() };
+ },
+ }),
+ };
+ },
+ },
+ );
+
+ const preflight = await client.preflight(repository, { maxCostUsd: 1 });
+ expect(preflight).toMatchObject({
+ model: "openai.gpt-5.6-luna",
+ modelProvider: "amazon-bedrock",
+ authentication: { method: "aws_credentials", source, verified: false },
+ maxCostUsd: 1,
+ });
+ expect(JSON.stringify(preflight)).not.toContain("synthetic-");
+ const result = await client.run(repository, {
+ maxCostUsd: 1,
+ onAuthentication: (selected) => {
+ authentication = selected;
+ },
+ });
+ expect(result).toMatchObject({ threadId: "thread-1" });
+ expect(authentication).toEqual({
+ method: "aws_credentials",
+ source,
+ verified: false,
+ });
+ expect((codexOptions as CodexOptions | null)?.env).toMatchObject(
+ credentials,
+ );
+ const configuration = JSON.parse(
+ await readFile(join(PLUGIN_ROOT, ".mcp.json"), "utf8"),
+ ) as { mcpServers: Record<string, { env_vars: string[] }> };
+ const mcpEnvironment = Object.fromEntries(
+ Object.entries((codexOptions as CodexOptions | null)?.env ?? {}).filter(
+ ([name]) =>
+ configuration.mcpServers["codex-security"]!.env_vars.includes(name),
+ ),
+ );
+ expect(mcpEnvironment).toMatchObject(credentials);
+ expect(result.cost).toMatchObject({ model: "openai.gpt-5.6-luna" });
+ for (const key of [
+ "OPENAI_API_KEY",
+ "CODEX_API_KEY",
+ "OPENROUTER_API_KEY",
+ "FIREWORKS_API_KEY",
+ ]) {
+ expect((codexOptions as CodexOptions | null)?.env).not.toHaveProperty(
+ key,
+ );
+ }
+ expect((codexOptions as CodexOptions | null)?.apiKey).toBeUndefined();
+ await client.close();
+ },
+ );
+
+ test("uses the selected Bedrock profile for authentication and cost limits", async () => {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ const codexHome = join(root, "codex-home");
+ const scanDir = join(root, "scan");
+ await mkdir(repository);
+ await mkdir(codexHome);
+ await mkdir(scanDir, { mode: 0o700 });
+ let codexOptions: CodexOptions | null = null;
+ let authentication: ScanAuthentication | undefined;
+ let savedRecipe: Record<string, unknown> | undefined;
+ const environment = {
+ OPENAI_API_KEY: "synthetic-openai-key-must-not-be-used",
+ AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer",
+ AWS_REGION: "us-east-2",
+ };
+ const client = new TestClient(
+ {
+ codexOverrides: {
+ profile: "bedrock",
+ model_provider: "openai",
+ profiles: {
+ bedrock: {
+ model: "openai.gpt-5.6-luna",
+ model_provider: "amazon-bedrock",
+ },
+ },
+ model_providers: {
+ "amazon-bedrock": {
+ aws: { region: "us-east-2", profile: "security-prod" },
+ },
+ },
+ },
+ },
+ {
+ environment,
+ prepareRuntime: async () => ({
+ ...preparedRuntime(codexHome),
+ environment,
+ credentialsAvailable: false,
+ }),
+ resolvePluginPython: async () => "/managed/python",
+ prepareOutputDir: async () => scanDir,
+ repositoryRevision: async () => "deadbeef",
+ runWorkbench: async (_options: unknown, args: readonly string[]) => {
+ if (args[0] === "register-cli-scan") {
+ savedRecipe = JSON.parse(args[args.indexOf("--recipe-json") + 1]!);
+ }
+ return mockWorkbench(args);
+ },
+ resolveCodexCommand: () => {
+ throw new Error("The Bedrock profile must not sign in to OpenAI");
+ },
+ createCodex: (options: CodexOptions) => {
+ codexOptions = options;
+ return {
+ startThread: () => ({
+ id: null,
+ async runStreamed() {
+ await copyCompletedScan(root);
+ return { events: completedEvents() };
+ },
+ }),
+ };
+ },
+ },
+ );
+
+ await expect(
+ client.preflight(repository, { maxCostUsd: 1 }),
+ ).resolves.toMatchObject({
+ model: "openai.gpt-5.6-luna",
+ modelProvider: "amazon-bedrock",
+ maxCostUsd: 1,
+ authentication: {
+ method: "aws_credentials",
+ source: "AWS_BEARER_TOKEN_BEDROCK",
+ verified: false,
+ },
+ });
+ const result = await client.run(repository, {
+ maxCostUsd: 1,
+ onAuthentication: (selected) => {
+ authentication = selected;
+ },
+ });
+
+ expect(authentication).toEqual({
+ method: "aws_credentials",
+ source: "AWS_BEARER_TOKEN_BEDROCK",
+ verified: false,
+ });
+ expect((codexOptions as CodexOptions | null)?.env).toMatchObject({
+ AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer",
+ AWS_REGION: "us-east-2",
+ });
+ expect((codexOptions as CodexOptions | null)?.env).not.toHaveProperty(
+ "OPENAI_API_KEY",
+ );
+ expect(result.cost).toMatchObject({ model: "openai.gpt-5.6-luna" });
+ expect(savedRecipe).toMatchObject({
+ config: {
+ model_provider: "openai",
+ profile: "bedrock",
+ profiles: {
+ bedrock: {
+ model: "openai.gpt-5.6-luna",
+ model_provider: "amazon-bedrock",
+ },
+ },
+ model_providers: {
+ "amazon-bedrock": {
+ aws: { region: "us-east-2", profile: "security-prod" },
+ },
+ },
+ },
+ });
+ await client.close();
+ });
+
+ test("does not accept Bedrock credentials for an OpenAI scan", async () => {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ await mkdir(repository);
+ const client = new TestClient(
+ {},
+ {
+ environment: {
+ AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer",
+ AWS_ACCESS_KEY_ID: "synthetic-aws-access-key",
+ AWS_SECRET_ACCESS_KEY: "synthetic-aws-secret-key",
+ },
+ },
+ );
+
+ expect((await client.preflight(repository)).authentication).toEqual({
+ method: "stored_credentials",
+ verified: false,
+ });
+ await client.close();
+ });
+
test("isolates authentication observer failures from scan startup", async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
diff --git a/sdk/typescript/tests-ts/cli-authentication.test.ts b/sdk/typescript/tests-ts/cli-authentication.test.ts
index 1a8ad98ef..fb3fa0640 100644
--- a/sdk/typescript/tests-ts/cli-authentication.test.ts
+++ b/sdk/typescript/tests-ts/cli-authentication.test.ts
@@ -337,6 +337,111 @@ describe("CLI authentication", () => {
}
});
+ test("reports Amazon Bedrock authentication without exposing AWS credentials", async () => {
+ for (const [environment, source] of [
+ [
+ { AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer" },
+ "AWS_BEARER_TOKEN_BEDROCK",
+ ],
+ [
+ {
+ AWS_ACCESS_KEY_ID: "synthetic-aws-access-key",
+ AWS_SECRET_ACCESS_KEY: "synthetic-aws-secret-key",
+ },
+ "AWS_ACCESS_KEY_ID",
+ ],
+ [{ AWS_PROFILE: "synthetic-bedrock-profile" }, "AWS_PROFILE"],
+ [{}, "default_credential_chain"],
+ ] as const) {
+ const stdout = capture();
+ const stderr = capture(false);
+ const deps = dependencies({ environment });
+ deps.createSecurity = () => ({
+ run: async (_repository, options) => {
+ options?.onAuthentication?.({
+ method: "aws_credentials",
+ source,
+ verified: false,
+ });
+ return fakeResult();
+ },
+ preflight: async () => fakePreflight(),
+ close: async () => {},
+ });
+
+ expect(
+ await main(
+ [
+ "scan",
+ "--provider",
+ "amazon-bedrock",
+ "--model",
+ "openai.gpt-5.6-luna",
+ "--json",
+ "--verbose",
+ ],
+ stdout.stream,
+ stderr.stream,
+ deps,
+ ),
+ ).toBe(0);
+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
+ expect(stderr.text()).toContain(
+ `Authentication: AWS credentials from ${source}.`,
+ );
+ expect(stderr.text()).toContain(
+ `method="aws_credentials" source="${source}"`,
+ );
+ expect(stderr.text()).not.toContain("synthetic-");
+ expect(stderr.text()).not.toContain("stored Codex credentials");
+ expect(stderr.text()).not.toContain("--auth chatgpt");
+ }
+ });
+
+ test("provides provider-aware Amazon Bedrock authentication failure guidance", async () => {
+ for (const [detail, expected] of [
+ [
+ "401 invalid credentials for org-private",
+ "Check your Amazon Bedrock bearer token",
+ ],
+ [
+ "403 model access denied for org-private",
+ "Check your AWS identity and Bedrock model permissions",
+ ],
+ ] as const) {
+ const stderr = capture(false);
+ const deps = dependencies({
+ environment: { AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer" },
+ });
+ deps.createSecurity = () => ({
+ run: async (_repository, options) => {
+ options?.onAuthentication?.({
+ method: "aws_credentials",
+ source: "AWS_BEARER_TOKEN_BEDROCK",
+ verified: false,
+ });
+ throw new CodexSecurityError(detail);
+ },
+ preflight: async () => fakePreflight(),
+ close: async () => {},
+ });
+
+ expect(
+ await main(
+ ["scan", "--codex", 'model_provider="amazon-bedrock"'],
+ capture().stream,
+ stderr.stream,
+ deps,
+ ),
+ ).toBe(2);
+ expect(stderr.text()).toContain(expected);
+ expect(stderr.text()).toContain("AWS_BEARER_TOKEN_BEDROCK");
+ expect(stderr.text()).not.toContain("synthetic-");
+ expect(stderr.text()).not.toContain("org-private");
+ expect(stderr.text()).not.toContain("--auth chatgpt");
+ }
+ });
+
test("offers the existing interactive prompt when both sign-ins are available", async () => {
for (const [argv, selection] of [
[["scan"], "chatgpt"],
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index 725e8b42f..5475ef491 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -36,6 +36,7 @@ import {
VERSION,
} from "../src/index.js";
import { main, parseCodexOverrides, Progress } from "../src/cli.js";
+import { scanPreflightCodexConfig } from "../src/api.js";
import {
DEFAULT_CODEX_CONFIG,
FIREWORKS_CODEX_PROVIDER,
@@ -121,7 +122,9 @@ describe("CLI", () => {
model: { type: "string" },
verbose: { type: "boolean" },
effort: { enum: ["minimal", "low", "medium", "high", "xhigh"] },
- provider: { enum: ["openai", "openrouter", "fireworks"] },
+ provider: {
+ enum: ["openai", "openrouter", "fireworks", "amazon-bedrock"],
+ },
failOnSeverity: { enum: ["critical", "high", "medium", "low"] },
headless: { type: "boolean" },
},
@@ -1906,7 +1909,9 @@ describe("CLI", () => {
"Use plain text progress instead of the interactive dashboard.",
);
expect(help.text()).toContain("--model <string>");
- expect(help.text()).toContain("--provider <openai|openrouter|fireworks>");
+ expect(help.text()).toContain(
+ "--provider <openai|openrouter|fireworks|amazon-bedrock>",
+ );
expect(help.text()).toContain(
`OpenAI model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`,
);
@@ -1972,7 +1977,9 @@ describe("CLI", () => {
);
expect(help.text()).not.toContain("--outputDir");
expect(help.text()).not.toContain("--maxAttempts");
- expect(help.text()).toContain("--provider <openai|openrouter|fireworks>");
+ expect(help.text()).toContain(
+ "--provider <openai|openrouter|fireworks|amazon-bedrock>",
+ );
expect(stderr.text()).toBe("");
});
@@ -2061,6 +2068,31 @@ describe("CLI", () => {
},
);
+ test("routes scans through the built-in Amazon Bedrock provider", async () => {
+ for (const options of [
+ ["--provider", "amazon-bedrock", "--model", "openai.gpt-5.6-luna"],
+ ["--provider=amazon-bedrock", "--codex", 'model="openai.gpt-5.6-luna"'],
+ ] as const) {
+ let config: CodexSecurityConfig | undefined;
+ expect(
+ await main(
+ ["scan", ".", ...options],
+ capture().stream,
+ capture().stream,
+ dependencies({
+ environment: { AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock" },
+ onConfig: (value) => (config = value),
+ }),
+ ),
+ ).toBe(0);
+ expect(config?.codexOverrides).toEqual({
+ model: "openai.gpt-5.6-luna",
+ model_provider: "amazon-bedrock",
+ });
+ expect(config?.codexOverrides).not.toHaveProperty("model_providers");
+ }
+ });
+
test("parses repeatable options and every scan target through Incur", async () => {
const pathOutput = capture();
let pathOptions: unknown;
@@ -2176,7 +2208,11 @@ describe("CLI", () => {
"high",
),
).toThrow("--effort conflicts with --codex model_reasoning_effort");
- for (const provider of ["openrouter", "fireworks"] as const) {
+ for (const provider of [
+ "openrouter",
+ "fireworks",
+ "amazon-bedrock",
+ ] as const) {
expect(() =>
parseCodexOverrides([], undefined, undefined, provider),
).toThrow(`--model is required when using --provider ${provider}`);
@@ -2756,6 +2792,67 @@ describe("CLI", () => {
expect(configuration).toContain('reasoning_effort="high"');
});
+ test.each([
+ [
+ "Amazon Bedrock",
+ "amazon-bedrock",
+ "openai.gpt-5.6-luna",
+ { aws: { region: "us-east-2", profile: "security-prod" } },
+ { AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer" },
+ ],
+ [
+ "OpenRouter",
+ "openrouter",
+ "anthropic/claude-sonnet-4.5",
+ OPENROUTER_CODEX_PROVIDER,
+ { OPENROUTER_API_KEY: "synthetic-openrouter-key" },
+ ],
+ [
+ "Fireworks AI",
+ "fireworks",
+ "accounts/fireworks/models/qwen3-235b-a22b",
+ FIREWORKS_CODEX_PROVIDER,
+ { FIREWORKS_API_KEY: "synthetic-fireworks-key" },
+ ],
+ ] as const)(
+ "reruns profile-selected %s scans with their saved provider configuration",
+ async (_name, provider, model, providerConfig, environment) => {
+ const savedConfig = scanPreflightCodexConfig({
+ model_provider: "openai",
+ profile: "selected",
+ profiles: { selected: { model, model_provider: provider } },
+ model_providers: { [provider]: providerConfig },
+ });
+ let rerunConfig: CodexSecurityConfig | undefined;
+
+ expect(
+ await main(
+ ["scans", "rerun", "scan-original", "--json"],
+ capture().stream,
+ capture().stream,
+ dependencies({
+ environment,
+ onConfig: (value) => (rerunConfig = value),
+ onWorkbench: () => ({
+ recipe: {
+ repository: "/original/repository",
+ target: { kind: "repository", paths: [] },
+ mode: "standard",
+ config: savedConfig,
+ },
+ }),
+ }),
+ ),
+ ).toBe(0);
+ expect(rerunConfig?.codexOverrides).toMatchObject({
+ model_provider: "openai",
+ profile: "selected",
+ profiles: { selected: { model, model_provider: provider } },
+ model_providers: { [provider]: providerConfig },
+ });
+ },
+ );
+
test("enables verbose diagnostics through CODEX_SECURITY_LOG_LEVEL", async () => {
const stdout = capture();
const stderr = capture();
diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.ts
index 1e62aeb83..6897c4d4d 100644
--- a/sdk/typescript/tests-ts/config.test.ts
+++ b/sdk/typescript/tests-ts/config.test.ts
@@ -4,7 +4,7 @@ import { join } from "node:path";
import { afterEach, describe, expect, test } from "bun:test";
import { parse } from "smol-toml";
import { scanRuntimeCodexConfig } from "../src/api.js";
-import { scanModelConfiguration } from "../src/config.js";
+import { scanModelConfiguration, scanModelProvider } from "../src/config.js";
import {
ConfigurationError,
DEFAULT_CODEX_CONFIG,
@@ -133,6 +133,41 @@ describe("Codex configuration", () => {
});
});
+ test("resolves the selected profile's provider before the root provider", async () => {
+ for (const [overrides, expected] of [
+ [
+ {
+ profile: "bedrock",
+ model_provider: "openai",
+ profiles: {
+ bedrock: { model_provider: "amazon-bedrock" },
+ },
+ },
+ "amazon-bedrock",
+ ],
+ [
+ {
+ profile: "bedrock",
+ model_provider: "amazon-bedrock",
+ profiles: { bedrock: { model: "openai.gpt-5.6-luna" } },
+ },
+ "amazon-bedrock",
+ ],
+ [
+ {
+ profile: "missing",
+ model_provider: "openai",
+ profiles: { bedrock: { model_provider: "amazon-bedrock" } },
+ },
+ "openai",
+ ],
+ [{}, undefined],
+ ] as const) {
+ const config = await mergedCodexConfig({ codexOverrides: overrides });
+ expect(scanModelProvider(config)).toBe(expected);
+ }
+ });
+
test("rejects invalid model settings from the selected Codex profile", async () => {
for (const [profile, message] of [
[{ model: " " }, "model must be a nonempty string"],
diff --git a/sdk/typescript/tests-ts/cost.test.ts b/sdk/typescript/tests-ts/cost.test.ts
index 3469f98e1..a3876f196 100644
--- a/sdk/typescript/tests-ts/cost.test.ts
+++ b/sdk/typescript/tests-ts/cost.test.ts
@@ -163,6 +163,24 @@ describe("scan cost", () => {
expect(estimateScanCost("gpt-5.6-luna", usage)?.estimatedUsd).toBe(1.4);
});
+ test("uses canonical OpenAI pricing for Amazon Bedrock model identifiers", () => {
+ const usage = { input_tokens: 1_000_000, output_tokens: 1_000_000 };
+
+ for (const [model, expectedUsd] of [
+ ["openai.gpt-5.6", 35],
+ ["openai.gpt-5.6-sol", 35],
+ ["openai.gpt-5.6-terra", 14],
+ ["openai.gpt-5.6-luna", 1.4],
+ ] as const) {
+ expect(estimateScanCost(model, usage)).toMatchObject({
+ model,
+ estimatedUsd: expectedUsd,
+ });
+ }
+
+ expect(estimateScanCost("openai.unknown-model", usage)).toBeNull();
+ });
+
test("uses current Terra and Luna input, cache, and output rates", () => {
for (const [model, input, cached, write, output] of [
["gpt-5.6-terra", 2, 0.2, 2.5, 12],
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 6ce95cf5d..cafe1f7ac 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -124,6 +124,49 @@ describe("plugin runtime preparation", () => {
).toBe(true);
});
+ test("forwards bundled Bedrock credentials through the MCP worker environment", async () => {
+ const awsKeys = [
+ "AWS_BEARER_TOKEN_BEDROCK",
+ "AWS_ACCESS_KEY_ID",
+ "AWS_SECRET_ACCESS_KEY",
+ "AWS_SESSION_TOKEN",
+ "AWS_PROFILE",
+ "AWS_REGION",
+ "AWS_DEFAULT_REGION",
+ "AWS_CONFIG_FILE",
+ "AWS_SHARED_CREDENTIALS_FILE",
+ "AWS_ROLE_ARN",
+ "AWS_ROLE_SESSION_NAME",
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
+ "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
+ "AWS_CONTAINER_CREDENTIALS_FULL_URI",
+ "AWS_CONTAINER_AUTHORIZATION_TOKEN",
+ "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",
+ ];
+ const configuration = JSON.parse(
+ await readFile(join(PLUGIN_ROOT, ".mcp.json"), "utf8"),
+ ) as {
+ mcpServers: Record<string, { env_vars: string[] }>;
+ };
+ const parentEnvironment = Object.fromEntries(
+ awsKeys.map((name) => [name, `synthetic-${name.toLowerCase()}`]),
+ );
+ const allowed = new Set(
+ configuration.mcpServers["codex-security"]!.env_vars,
+ );
+ const mcpEnvironment = Object.fromEntries(
+ Object.entries(parentEnvironment).filter(([name]) => allowed.has(name)),
+ );
+ const worker = spawnSync(
+ process.execPath,
+ ["-e", "process.stdout.write(JSON.stringify(process.env))"],
+ { encoding: "utf8", env: mcpEnvironment },
+ );
+
+ expect(worker.status).toBe(0);
+ expect(JSON.parse(worker.stdout)).toMatchObject(parentEnvironment);
+ });
+
test("rejects control characters in bundled artifact paths and candidate IDs", async () => {
const schema = JSON.parse(
await readFile(