Skip to content

Persist Cloudflare affinity cookies for MCP HTTP - #29516

Merged
stevenlee-oai merged 1 commit into
mainfrom
dev/stevenlee/mcp-cloudflare-affinity-cookies
Jun 26, 2026
Merged

Persist Cloudflare affinity cookies for MCP HTTP#29516
stevenlee-oai merged 1 commit into
mainfrom
dev/stevenlee/mcp-cloudflare-affinity-cookies

Conversation

@stevenlee-oai

@stevenlee-oai stevenlee-oai commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Codex Thread 019ef1f9-36e2-7e91-9337-504f097b9dc1

Why

Hosted plugin-service Streamable HTTP MCP traffic uses https://chatgpt.com/backend-api/ps/mcp and depends on Cloudflare's __cflb cookie for load-balancer affinity. The local and exec-server http/request path built a fresh reqwest client for each request without installing Codex's existing shared ChatGPT Cloudflare cookie store, so affinity could be lost between calls.

This is an affinity-hardening change motivated by an incident investigation. It does not establish the broader connector-cache incident RCA or claim to fix that incident in full.

What changed

  • Install the existing process-local, strictly allowlisted ChatGPT Cloudflare cookie store on the reqwest client used by ReqwestHttpClient.
  • Fresh clients now share allowed Cloudflare infrastructure cookies within the process that originates the local or exec-server network request.
  • Keep the existing HTTPS ChatGPT-host and Cloudflare-cookie-name restrictions. This does not introduce a general cookie jar or send ChatGPT Cloudflare cookies to unrelated hosts.

Test coverage

  • codex-client unit coverage verifies that the existing strict store accepts and returns __cflb for HTTPS ChatGPT URLs.
  • The exec-server HTTPS integration test sends four independent http/request calls through a local TLS-intercepting proxy and verifies that:
    • Set-Cookie: __cflb=west is sent on the next plugin-service request;
    • a later Set-Cookie: __cflb=central replaces the stored value;
    • non-Cloudflare session cookies are discarded;
    • no stored ChatGPT Cloudflare cookie is sent to a non-ChatGPT host.
  • just test -p codex-client — 38 passed.
  • just test -p codex-exec-server --test chatgpt_cloudflare_affinity — 1 passed.
  • just bazel-lock-check — passed.

Non-goals

  • No persistence of ChatGPT auth, account, session, residency, or arbitrary cookies.
  • No cookie persistence for third-party MCP servers.
  • No special composition of caller-provided Cookie headers.
  • No plugin-service, connector-cache, Habitat/habicache, routing, redirect, or API-contract changes.
  • No broader incident RCA conclusions.

@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 33f610dc7c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mzeng-openai mzeng-openai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we take a look at these two edge cases?

Comment thread codex-rs/exec-server/src/client/reqwest_http_client.rs Outdated
Comment thread codex-rs/codex-client/src/chatgpt_cloudflare_cookies.rs Outdated
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-cloudflare-affinity-cookies branch from da8a509 to 9bfec1b Compare June 23, 2026 22:44
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-cloudflare-affinity-cookies branch from 9bfec1b to ac39273 Compare June 26, 2026 01:38
@stevenlee-oai
stevenlee-oai merged commit b5866ee into main Jun 26, 2026
31 checks passed
@stevenlee-oai
stevenlee-oai deleted the dev/stevenlee/mcp-cloudflare-affinity-cookies branch June 26, 2026 06:23
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants