2026-11-26 15:47 UTC

Leaked Claude Code mirror shows remote-session proxy CA and relay code

state: watchingheat: mediumuncertainty: highrelevance: mediumclaude-code agent-security mitm-proxyAnthropic

What is this?

A public GitHub mirror of Claude Code source, reportedly originating from a March 31, 2026 npm source-map exposure, contains a module that appears to configure an upstream proxy for remote sessions. The code describes downloading a proxy CA certificate, adding it to a CA bundle, and routing eligible HTTPS subprocess traffic through a local relay; it also explicitly excludes Anthropic and several other domains. The mirror’s single squashed baseline does not establish when or whether this code was present in an official release. The supplied sources do not verify the code’s provenance, deployment, traffic scope, or any user exposure, and do not establish that the certificate was used maliciously.

Why it matters

The code describes a potentially consequential security boundary in a widely used AI coding tool: a remote-session feature can add a proxy CA to subprocess trust stores and send selected HTTPS traffic through a relay. If deployed, that could enable server-side inspection or modification of eligible traffic, while the listed bypasses and fail-open behavior shape its scope. But the available evidence is a source file in a mirror, not proof this code shipped or handled users’ traffic. This is worth tracking as a security and agent-infrastructure question, not treating as a confirmed compromise.

Current assessment

A Hacker News post links to `upstreamproxy.ts` in a public Claude Code source mirror. The file’s comments and implementation say the feature activates only in remote sessions when server-injected `CCR_UPSTREAM_PROXY_ENABLED` is set and a session token is present. It fetches a CA certificate from the configured Anthropic base URL, combines it with the system CA bundle, starts a local CONNECT-to-WebSocket relay, and exposes proxy and CA environment variables to agent subprocesses. It also sets a Linux process-dumpability control, removes the token file after relay startup, and fails open by disabling the proxy on setup errors. The code explicitly excludes Anthropic, loopback/private-network and several package-registry and GitHub domains; those exclusions mean the supplied code does not support a claim that all session traffic, or Anthropic API traffic, is intercepted. The certificate is described in the code as a proxy CA; calling it “forged” or inferring malicious use is not established by these sources. A March 31 X post is identified as the earliest artifact for the source exposure, and the mirror’s single squashed baseline is dated March 31, but neither establishes when this particular module entered official Claude Code, whether it was enabled in production, which destinations matched relay routes, or what the relay could inspect or alter. The October 22 HN framing and October 28 follow-up are discussion, not independent verification. Track for official Anthropic confirmation, release/package history, feature-flag and relay-routing details, and evidence of actual deployment or traffic impact before drawing conclusions about user exposure.

Measured heat

now 0 pts/hpeak 0 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 5786h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

03-30 13:00⭐ origin echo-reconstructedThe furthest-back primary artifact identified is Chaofan Shou’s X post: “Claude code source code has been leaked via a map file in their npm
Chaofan Shou (@shoucccc) on x (echo) · attributed from hn.story.50184897
—
10-21 17:50first on hacker news · published · +4924.8hClaude Code has expected a forged CA and MitM since April
cududa
—
10-21 17:50amplified on hacker news 👑hn.story.50184897
cududa
peak 4 · 0 comments · 66% of case engagement
10-27 14:05amplified on hacker newshn.story.50259590
joozio
peak 2 · 0 comments · 34% of case engagement
10-21 18:26our radar first saw it · +4925.4hdiscovery anchor: hn.story.50184897—

Evidence (3) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnClaude Code has expected a forged CA and MitM since April
Retrieved article excerpt

Open article · Retrieved 2026-10-21T18:28:56.361892+00:00

## Repository navigation



## FilesExpand file tree

main

/

# upstreamproxy.ts

Copy path

BlameMore file actions

BlameMore file actions

## Latest commit

## History

[History](https://github.com/Andytonglove/claude-code-leak/commits/main/src/upstreamproxy/upstreamproxy.ts)

History

285 lines (267 loc) · 9.58 KB

main

/

# upstreamproxy.ts

Copy path

Top

## File metadata and controls

- Code
- Blame

285 lines (267 loc) · 9.58 KB

[Raw](https://github.com/Andytonglove/claude-code-leak/raw/refs/heads/main/src/upstreamproxy/upstreamproxy.ts)

Copy raw file

Download raw file

Open symbols panel

Edit and raw actions

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

/\*\*

\* CCR upstreamproxy — container-side wiring.

\*

\* When running inside a CCR session container with upstreamproxy configured,

\* this module:

\* 1. Reads the session token from /run/ccr/session\_token

\* 2. Sets prctl(PR\_SET\_DUMPABLE, 0) to block same-UID ptrace of the heap

\* 3. Downloads the upstreamproxy CA cert and concatenates it with the

\* system bundle so curl/gh/python trust the MITM proxy

\* 4. Starts a local CONNECT→WebSocket relay (see relay.ts)

\* 5. Unlinks the token file (token stays heap-only; file is gone before

\* the agent loop can see it, but only after the relay is confirmed up

\* so a supervisor restart can retry)

\* 6. Exposes HTTPS\_PROXY / SSL\_CERT\_FILE env vars for all agent subprocesses

\*

\* Every step fails open: any error logs a warning and disables the proxy.

\* A broken proxy setup must never break an otherwise-working session.

\*

\* Design doc: api-go/ccr/docs/plans/CCR\_AUTH\_DESIGN.md § "Week-1 pilot scope".

\*/

import { mkdir, readFile, unlink, writeFile } from 'fs/promises'

import { homedir } from 'os'

import { join } from 'path'

import { registerCleanup } from '../utils/cleanupRegistry.js'

import { logForDebugging } from '../utils/debug.js'

import { isEnvTruthy } from '../utils/envUtils.js'

import { isENOENT } from '../utils/errors.js'

import { startUpstreamProxyRelay } from './relay.js'

export const SESSION\_TOKEN\_PATH = '/run/ccr/session\_token'

const SYSTEM\_CA\_BUNDLE = '/etc/ssl/certs/ca-certificates.crt'

// Hosts the proxy must NOT intercept. Covers loopback, RFC1918, the IMDS

// range, and the package registries + GitHub that CCR containers already

// reach directly. Mirrors airlock/scripts/sandbox-shell-ccr.sh.

const NO\_PROXY\_LIST = [

'localhost',

'127.0.0.1',

'::1',

'169.254.0.0/16',

'10.0.0.0/8',

'172.16.0.0/12',

'192.168.0.0/16',

// Anthropic API: no upstream route will ever match, and the MITM breaks

// non-Bun runtimes (Python httpx/certifi doesn't trust the forged CA).

// Three forms because NO\_PROXY parsing differs across runtimes:

// \*.anthropic.com — Bun, curl, Go (glob match)

// .anthropic.com — Python urllib/httpx (suffix match, strips leading dot)

// anthropic.com — apex domain fallback

'anthropic.com',

'.anthropic.com',

'\*.anthropic.com',

'github.com',

'api.github.com',

'\*.github.com',

'\*.githubusercontent.com',

'registry.npmjs.org',

'pypi.org',

'files.pythonhosted.org',

'index.crates.io',

'proxy.golang.org',

].join(',')

type UpstreamProxyState = {

enabled: boolean

port?: number

caBundlePath?: string

}

let state: UpstreamProxyState = { enabled: false }

/\*\*

\* Initialize upstreamproxy. Called once from init.ts. Safe to call when the

\* feature is off or the token file is absent — returns {enabled: false}.

\*

\* Overridable paths are for tests; production uses the defaults.

\*/

export async function initUpstreamProxy(opts?: {

tokenPath?: string

systemCaPath?: string

caBundlePath?: string

ccrBaseUrl?: string

}): Promise<UpstreamProxyState> {

if (!isEnvTruthy(process.env.CLAUDE\_CODE\_REMOTE)) {

return state

}

// CCR evaluates ccr\_upstream\_proxy\_enabled server-side (where GrowthBook is

// warm) and injects this env var via StartupContext.EnvironmentVariables.

// Every CCR session is a fresh container with no GB cache, so a client-side

// GB check here always returned the default (false).

if (!isEnvTruthy(process.env.CCR\_UPSTREAM\_PROXY\_ENABLED)) {

return state

}

const sessionId = process.env.CLAUDE\_CODE\_REMOTE\_SESSION\_ID

if (!sessionId) {

logForDebugging(

'[upstreamproxy] CLAUDE\_CODE\_REMOTE\_SESSION\_ID unset; proxy disabled',

{ level: 'warn' },

)

return state

}

const tokenPath = opts?.tokenPath ?? SESSION\_TOKEN\_PATH

const token = await readToken(tokenPath)

if (!token) {

logForDebugging('[upstreamproxy] no session token file; proxy disabled')

return state

}

setNonDumpable()

// CCR injects ANTHROPIC\_BASE\_URL via StartupContext (sessionExecutor.ts /

// sessionHandler.ts). getOauthConfig() is wrong here: it keys off

// USER\_TYPE + USE\_{LOCAL,STAGING}\_OAUTH, none of which the container sets,

// so it always returned the prod URL and the CA fetch 404'd.

const baseUrl =

opts?.ccrBaseUrl ??

process.env.ANTHROPIC\_BASE\_URL ??

'https://api.anthropic.com'

const caBundlePath =

opts?.caBundlePath ?? join(homedir(), '.ccr', 'ca-bundle.crt')

const caOk = await downloadCaBundle(

baseUrl,

opts?.systemCaPath ?? SYSTEM\_CA\_BUNDLE,

caBundlePath,

)

if (!caOk) return state

try {

const wsUrl = baseUrl.replace(/^http/, 'ws') + '/v1/code/upstreamproxy/ws'

const relay = await startUpstreamProxyRelay({ wsUrl, sessionId, token })

registerCleanup(async () => relay.stop())

state = { enabled: true, port: relay.port, caBundlePath }

logForDebugging(`[upstreamproxy] enabled on 127.0.0.1:${relay.port}`)

// Only unlink after the listener is up: if CA download or listen()

// fails, a supervisor restart can retry with the token still on disk.

await unlink(tokenPath).catch(() => {

logForDebugging('[upstreamproxy] token file unlink failed', {

level: 'warn',

})

})

} catch (err) {

logForDebugging(

`[upstreamproxy] relay start failed: ${err instanceof Error ? err.message : String(err)}; proxy disabled`,

{ level: 'warn' },

)

}

return state

}

/\*\*

\* Env vars to merge into every agent subprocess. Empty when the proxy is

\* disabled. Called from subprocessEnv() so Bash/MCP/LSP/hooks all inherit

\* the same recipe.

\*/

export function getUpstreamProxyEnv(): Record<string, string> {

if (!state.enabled || !state.port || !state.caBundlePath) {

// Child CLI processes can't re-initialize the relay (token file was

// unlinked by the parent), but the parent's relay is still running and

// reachable at 127.0.0.1:<port>. If we inherited proxy vars from the

// parent (HTTPS\_PROXY + SSL\_CERT\_FILE both set), pass them through so

// our subprocesses also route through the parent's relay.

if (process.env.HTTPS\_PROXY && process.env.SSL\_CERT\_FILE) {

const inherited: Record<string, string> = {}

for (const key of [

'HTTPS\_PROXY',

'https\_proxy',

'NO\_PROXY',

'no\_proxy',

'SSL\_CERT\_FILE',

'NODE\_EXTRA\_CA\_CERTS',

'REQUESTS\_CA\_BUNDLE',

'CURL\_CA\_BUNDLE',

]) {

if (process.env[key]) inherited[key] = process.env[key]

}

return inherited

}

return {}

}

const proxyUrl = `http://127.0.0.1:${state.port}`

// HTTPS only: the relay handles CONNECT and nothing else. Plain HTTP has

// no credentials to inject, so routing it through the relay would just

// break the request with a 405.

return {

HTTPS\_PROXY: proxyUrl,

https\_proxy: proxyUrl,

NO\_PROXY: NO\_PROXY\_LIST,

no\_proxy: NO\_PROXY\_LIST,

SSL\_CERT\_FILE: state.caBundlePath,

NODE\_EXTRA\_CA\_CERTS: state.caBundlePath,

REQUESTS\_CA\_BUNDLE: state.caBundlePath,

CURL\_CA\_BUNDLE: state.caBundlePath,

}

}

/\*\* Test-only: reset module state between test cases. \*/

export function resetUpstreamProxyForTests(): void {

state = { enabled: false }

}

async function readToken(path: string): Promise<string | null> {

try {

const raw = await readFile(path, 'utf8')

return raw.trim() || null

} catch (err) {

if (isENOENT(err)) return null

logForDebugging(

`[upstreamproxy] token read failed: ${err instanceof Error ? err.message : String(err)}`,

{ level: 'warn' },

)

return null

}

}

/\*\*

\* prctl(PR\_SET\_DUMPABLE, 0) via libc FFI. Blocks same-UID ptrace of this

\* process, so a prompt-injected `gdb -p $PPID` can't scrape the token from

\* the heap. Linux-only; silently no-ops elsewhere.

\*/

function setNonDumpable(): void {

if (process.platform !== 'linux' || typeof Bun === 'undefined') return

try {

// eslint-disable-next-line @typescript-eslint/no-require-imports

const ffi = require('bun:ffi') as typeof import('bun:ffi')

const lib = ffi.dlopen('libc.so.6', {

prctl: {

args: ['int', 'u64', 'u64', 'u64', 'u64'],

returns: 'int',

},

} as const)

const PR\_SET\_DUMPABLE = 4

const rc = lib.symbols.prctl(PR\_SET\_DUMPABLE, 0n, 0n, 0n, 0n)

if (rc !== 0) {

logForDebugging(

'[upstreamproxy] prctl(PR\_SET\_DUMPABLE,0) returned nonzero',

{

level: 'warn',

},

)

}

} catch (err) {

logForDebugging(

`[upstreamproxy] prctl unavailable: ${err instanceof Error ? err.message : String(err)}`,

{ level: 'warn' },

)

}

}

async function downloadCaBundle(

baseUrl: string,

systemCaPath: string,

outPath: string,

): Promise<boolean> {

try {

// eslint-disable-next-line eslint-plugin-n/no-unsupported-features/node-builtins

const resp = await fetch(`${baseUrl}/v1/code/upstreamproxy/ca-cert`, {

// Bun has no default fetch timeout — a hung endpoint would block CLI

// startup forever. 5s is generous for a small PEM.

signal: AbortSignal.timeout(5000),

})

if (!resp.ok) {

logForDebugging(

`[upstreamproxy] ca-cert fetch ${resp.status}; proxy disabled`,

{ level: 'warn' },

)

return false

}

const ccrCa = await resp.text()

const systemCa = await readFile(systemCaPath, 'utf8').catch(() => '')

await mkdir(join(outPath, '..'), { recursive: true })

await writeFile(outPath, systemCa + '\n' + ccrCa, 'utf8')

return true

} catch (err) {

logForDebugging(

`[upstreamproxy] ca-cert download failed: ${err instanceof Error ? err.message : String(err)}; proxy disabled`,

{ level: 'warn' },

)

return false

}

}
cududa40
🟧 echo.x ⭐The furthest-back primary artifact identified is Chaofan Shou’s X post: “Claude code source code has been leaked via a map file in their npmChaofan Shou (@shoucccc)——
🟧 hnClaude Code's Source Got Leaked. Here's What's Worth Learningjoozio20

Interpretation history

Decision trace