forked from lidge-jun/opencodex
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(claude-intercept): require per-install auth for local CONNECT proxy #593
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
Open
luvs01
wants to merge
4
commits into
dev
Choose a base branch
from
codex/propose-fix-for-authentication-bypass-vulnerability
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+385
−48
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5adfffb
fix(claude-intercept): authenticate local proxy clients
luvs01 a43b57d
fix(claude-intercept): migrate owned legacy proxy envs and harden tok…
devin-ai-integration[bot] ea47803
fix(claude-intercept): harden token ACLs on Windows and degrade unrea…
devin-ai-integration[bot] 46b9681
ci: retrigger to pick up dev's #848 provenance-test fix
devin-ai-integration[bot] 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
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,87 @@ | ||
| import { randomBytes } from "node:crypto"; | ||
| import { chmodSync, linkSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { isMissingPathError } from "../../config/atomic-write"; | ||
| import { hardenSecretDir, hardenSecretPath } from "../../lib/windows-secret-acl"; | ||
|
|
||
| const TOKEN_FILE = "proxy-token"; | ||
|
|
||
| export function claudeInterceptProxyTokenPath(configDir: string): string { | ||
| return join(configDir, "claude-intercept", TOKEN_FILE); | ||
| } | ||
|
|
||
| /** | ||
| * The persisted CONNECT credential, or `null` when none is usable. Never writes: | ||
| * read-only inspection paths call this, so missing, empty, and unreadable files | ||
| * all collapse to "no token" and classify as stale rather than throwing. | ||
| */ | ||
| export function readClaudeInterceptProxyToken(configDir: string): string | null { | ||
| try { | ||
| const token = readFileSync(claudeInterceptProxyTokenPath(configDir), "utf8").trim(); | ||
| return token.length > 0 ? token : null; | ||
| } catch { // no-excuse-ok: catch -- every read failure means no usable credential; write paths surface real errors when minting. | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Return the per-install CONNECT credential, creating it with owner-only permissions. | ||
| * The file publishes through an atomic no-replace link, so concurrent creators (a server | ||
| * start racing an apply) all return the single committed value instead of splitting a | ||
| * generated token from the one clients were told. On Windows, `chmod` is a no-op against | ||
| * inherited NTFS grants, so the directory and file go through the repo's icacls hardener. | ||
| */ | ||
| export function ensureClaudeInterceptProxyToken(configDir: string): string { | ||
| const path = claudeInterceptProxyTokenPath(configDir); | ||
| const existing = readClaudeInterceptProxyToken(configDir); | ||
| if (existing) { | ||
| try { | ||
| // A restored or hand-edited file may carry broader permissions than the | ||
| // writer left; re-pin owner-only before trusting the credential again. | ||
| if (process.platform === "win32") hardenSecretPath(path, { required: true }); | ||
| else if ((statSync(path).mode & 0o077) !== 0) chmodSync(path, 0o600); | ||
| return existing; | ||
| } catch (error) { | ||
| if (!isMissingPathError(error)) throw error; | ||
| // Vanished between read and stat — mint a fresh one below rather than | ||
| // returning a token that is no longer persisted anywhere. | ||
| } | ||
| } | ||
| const dir = join(configDir, "claude-intercept"); | ||
| mkdirSync(dir, { recursive: true }); | ||
| try { chmodSync(dir, 0o700); } catch { // no-excuse-ok: catch -- non-POSIX filesystems may ignore chmod. | ||
| } | ||
| if (process.platform === "win32") hardenSecretDir(dir, { required: true }); | ||
| const token = randomBytes(32).toString("base64url"); | ||
| const tmp = join(dir, `.${TOKEN_FILE}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`); | ||
| writeFileSync(tmp, `${token}\n`, { mode: 0o600 }); | ||
| try { chmodSync(tmp, 0o600); } catch { // no-excuse-ok: catch -- non-POSIX filesystems may ignore chmod. | ||
| } | ||
| if (process.platform === "win32") hardenSecretPath(tmp, { required: true, timeoutMemoKey: path }); | ||
| try { | ||
| try { | ||
| linkSync(tmp, path); // atomic no-replace publish; EEXIST means a peer committed first | ||
| return token; | ||
| } catch (error) { | ||
| const code = (error as NodeJS.ErrnoException).code; | ||
| if (code === "EEXIST") { | ||
| const committed = readClaudeInterceptProxyToken(configDir); | ||
| if (committed) return committed; | ||
| renameSync(tmp, path); // an empty placeholder is corruption, not a winner | ||
| return token; | ||
| } | ||
| if (code === "EPERM" || code === "EXDEV" || code === "ENOSYS") { | ||
| // Filesystem without hard links: rename still publishes, then the reread | ||
| // resolves a concurrent overwrite to the committed file rather than our lost write. | ||
| renameSync(tmp, path); | ||
| return readClaudeInterceptProxyToken(configDir) ?? token; | ||
| } | ||
| throw error; | ||
| } | ||
| } finally { | ||
| try { | ||
| unlinkSync(tmp); | ||
| } catch { // no-excuse-ok: catch -- the publish above already consumed the temp file. | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.