mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
chatgpt.com answers Cloudflare Workers' egress with a 403 "Unable to load site" page, so Codex via the Orca account could never get an answer through the egress proxy (#767 made that a printed error). Cloud Run's egress is answered normally (probed, then deleted). - cloud/apps/chatgpt-relay: a dependency-free Node relay. chatgpt.com only, the same Codex path pinning as the Worker (shared sandbox-control/src/codex-paths.ts), SSE streamed chunk by chunk, no WebSocket upgrades, hop and Cloud Run headers dropped, logs without headers, bodies or queries. - Cloud Run IAM authenticates the Worker: one invoker service account (run.invoker on the relay only); the Worker mints a Google ID token for the relay URL and sends it in X-Serverless-Authorization, so the swapped ChatGPT Authorization passes through untouched. - sandbox-control: CHATGPT_RELAY_URL + CHATGPT_RELAY_SERVICE_ACCOUNT route the egress proxy's chatgpt.com fetches through the relay; unset, chatgpt.com goes direct as before. A relay sign-in failure answers Codex a 503 JSON detail instead of reaching chatgpt.com. - cloud/infra/chatgpt-relay: Terraform (staging backend applied; production is a runbook step).
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
// The chatgpt.com paths Codex's login may be used on. Shared, unchanged, by the Worker's egress proxy
|
|
// (codex-credentials.ts) and the ChatGPT relay (cloud/apps/chatgpt-relay), which pins the same paths a
|
|
// second time. Erasable TypeScript only: the relay runs this file with Node's type stripping.
|
|
|
|
/**
|
|
* The ChatGPT backend calls Codex makes with its login (seen live, Codex 0.166): the Codex API itself, its
|
|
* plugin catalog and usage. Nothing else on chatgpt.com (conversations, memories, connectors) gets the token.
|
|
*/
|
|
const CODEX_PREFIXES = ['/backend-api/codex/']
|
|
const CODEX_EXACT_GETS = new Set([
|
|
'/backend-api/ps/plugins/list',
|
|
'/backend-api/ps/plugins/installed',
|
|
'/backend-api/ps/plugins/suggested/codex',
|
|
'/backend-api/plugins/featured',
|
|
'/backend-api/plugins/export/curated',
|
|
'/backend-api/wham/usage'
|
|
])
|
|
|
|
export function codexPathAllowed(method: string, path: string): boolean {
|
|
const pathname = path.split('?')[0] ?? ''
|
|
// Plain segments only: no encoded or dot segments that could walk out of an allowed prefix.
|
|
if (!/^(\/[A-Za-z0-9_~-][A-Za-z0-9._~-]*)+\/?$/.test(pathname) || /(^|\/)\.\.?(\/|$)/.test(pathname)) {
|
|
return false
|
|
}
|
|
if (CODEX_PREFIXES.some((prefix) => pathname.startsWith(prefix))) {
|
|
return true
|
|
}
|
|
return method.toUpperCase() === 'GET' && CODEX_EXACT_GETS.has(pathname)
|
|
}
|