-
Notifications
You must be signed in to change notification settings - Fork 687
fix: harden credential and runtime trust boundaries (rebase of #916) #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b82b16
fix(google): validate Vertex location before ADC auth
Ingwannu ee14555
fix: harden local credential and runtime boundaries
Ingwannu d8d0b2f
fix(claude): narrow the no-context fallback to the destination slot
lidge-jun 727722c
fix(claude): restore fail-closed credential stripping, and pin why
lidge-jun a90981e
Merge remote-tracking branch 'origin/dev' into codex/916-trust-bounda…
lidge-jun 4874390
test: align startServer attestation-secret call sites with the dev de…
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * Trusted facts captured by the plain-Node npm launcher before Bun auto-loads | ||
| * project dotenv files. The random proof travels in argv while the context | ||
| * travels in the environment, so a project `.env` cannot forge the pair during | ||
| * an ordinary `ocx ...` invocation. | ||
| */ | ||
| export const NODE_LAUNCH_CONTEXT_ENV = "OCX_NODE_LAUNCH_CONTEXT"; | ||
| export const NODE_LAUNCH_PROOF_PREFIX = "--ocx-internal-launch-proof="; | ||
|
|
||
| export const ANTHROPIC_PARENT_ENV_SLOTS = [ | ||
| "ANTHROPIC_API_KEY", | ||
| "ANTHROPIC_AUTH_TOKEN", | ||
| "ANTHROPIC_BASE_URL", | ||
| ] as const; | ||
|
|
||
| export type AnthropicParentEnvSlot = typeof ANTHROPIC_PARENT_ENV_SLOTS[number]; | ||
|
|
||
| export type TrustedNodeLaunchContext = { | ||
| anthropicEnvSlots: readonly AnthropicParentEnvSlot[]; | ||
| }; | ||
|
|
||
| let trustedContext: TrustedNodeLaunchContext | null = null; | ||
|
|
||
| function isLaunchProof(value: string): boolean { | ||
| return /^[A-Za-z0-9_-]{43}$/.test(value); | ||
| } | ||
|
|
||
| /** Consume the internal proof before normal CLI argument parsing. */ | ||
| export function initializeNodeLauncherContext( | ||
| argv: string[] = process.argv, | ||
| env: NodeJS.ProcessEnv = process.env, | ||
| ): TrustedNodeLaunchContext | null { | ||
| const proofArgs: string[] = []; | ||
| for (let index = argv.length - 1; index >= 2; index -= 1) { | ||
| const value = argv[index]; | ||
| if (!value?.startsWith(NODE_LAUNCH_PROOF_PREFIX)) continue; | ||
| proofArgs.push(value.slice(NODE_LAUNCH_PROOF_PREFIX.length)); | ||
| argv.splice(index, 1); | ||
| } | ||
|
|
||
| const raw = env[NODE_LAUNCH_CONTEXT_ENV]; | ||
| delete env[NODE_LAUNCH_CONTEXT_ENV]; | ||
| // Older launchers used this unauthenticated marker. Never let a project | ||
| // dotenv resurrect it as a trusted provenance channel. | ||
| delete env.OCX_PRE_BUN_ANTHROPIC_ENV; | ||
| trustedContext = null; | ||
|
|
||
| if (proofArgs.length !== 1 || !raw || raw.length > 2048) return null; | ||
| const proof = proofArgs[0]!; | ||
| if (!isLaunchProof(proof)) return null; | ||
|
|
||
| try { | ||
| const parsed = JSON.parse(raw) as { | ||
| version?: unknown; | ||
| proof?: unknown; | ||
| anthropicEnvSlots?: unknown; | ||
| }; | ||
| if (parsed.version !== 1 || parsed.proof !== proof || !Array.isArray(parsed.anthropicEnvSlots)) { | ||
| return null; | ||
| } | ||
| const allowed = new Set<string>(ANTHROPIC_PARENT_ENV_SLOTS); | ||
| const slots = parsed.anthropicEnvSlots.filter( | ||
| (slot): slot is AnthropicParentEnvSlot => typeof slot === "string" && allowed.has(slot), | ||
| ); | ||
| if (slots.length !== parsed.anthropicEnvSlots.length || new Set(slots).size !== slots.length) { | ||
| return null; | ||
| } | ||
| trustedContext = { anthropicEnvSlots: slots }; | ||
| return trustedContext; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function trustedNodeLauncherContext(): TrustedNodeLaunchContext | null { | ||
| return trustedContext; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an untrusted environment supplies
OCX_BUN_RUNTIME_PATHas a symlink that currently resolves toprocess.execPath,samePathaccepts it but this return preserves the attacker-controlled symlink name.durableBunRuntime()then embeds that name into a service or Codex shim, so the repository can retarget the symlink after installation and make the durable launcher execute an arbitrary binary. This remains reachable from a direct Bun/legacy launch where project dotenv can supply the otherwise unauthenticated marker pair; return the verifiedprocess.execPath(as the previous provenance path did), a fixed canonical path, or authenticate the pair before allowing it into durable artifacts.AGENTS.md reference: AGENTS.md:L218-L224
Useful? React with 👍 / 👎.