Skip to content

Preserve Cloudfare HTTP cookies in codex#17783

Merged
shijie-oai merged 7 commits intomainfrom
shijie/cf-cookie-preservation-http
Apr 21, 2026
Merged

Preserve Cloudfare HTTP cookies in codex#17783
shijie-oai merged 7 commits intomainfrom
shijie/cf-cookie-preservation-http

Conversation

@shijie-oai
Copy link
Copy Markdown
Collaborator

@shijie-oai shijie-oai commented Apr 14, 2026

Summary

  • Adds a process-local, in-memory cookie store for ChatGPT HTTP clients.
  • Limits cookie storage and replay to a shared ChatGPT host allowlist.
  • Wires the shared store into the default Codex reqwest client and backend client.
  • Shares the ChatGPT host allowlist with remote-control URL validation to avoid drift.
  • Enables reqwest cookie support and updates lockfiles.


/// Adds the process-local ChatGPT cookie jar used by Codex HTTP clients.
///
/// The jar is intentionally not persisted to disk. It only preserves cookies for ChatGPT backend
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the key - we do it in memory and no disk persistence so that new CLI/app-server instance get the latest cookies from initial request.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

qq what's the story between app-server requests and the client layer requests today? Would client layer have a different set of cookies and if they did would it pass down to app-server?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nope they would use the same one cause most if not all request goes through app server. There are definitely individual requests in the app (i.e. codex web tasks etc) but those are not concerning for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sg. just wasn't sure if that story behind the vs-code requests and app-server requests had evolved

pub fn is_allowed_chatgpt_host(host: &str) -> bool {
host == "chatgpt.com"
|| host.ends_with(".chatgpt.com")
|| host == "chat.openai.com"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am not 100% sure if this is needed? Can we confirm?

Comment on lines +4 to +5
host == "chatgpt.com"
|| host.ends_with(".chatgpt.com")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these two overlap?
and what about chatgpt-preview-*?
also rust noob question: does rust have a set presence operator?

Copy link
Copy Markdown
Collaborator Author

@shijie-oai shijie-oai Apr 14, 2026

Choose a reason for hiding this comment

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

these two overlap?

one is strict check and one is looking at the ending so staging.chatgpt.com like url would qualify too.

chatgpt-preview-*

I am not familiar with and I am not sure if we can even point CLI traffic that way?

set presence operator

It most and we can convert to use that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

one is strict check and one is looking at the ending so staging.chatgpt.com like url would qualify too.

1st comment more around if strict || loose can we omit the strict

preview-*

that's the personal sa-server staging deployment

@shijie-oai shijie-oai force-pushed the shijie/cf-cookie-preservation-http branch from 515e4a2 to 8def983 Compare April 15, 2026 02:11
@shijie-oai shijie-oai marked this pull request as ready for review April 15, 2026 05:33
@shijie-oai shijie-oai requested a review from jif-oai April 15, 2026 05:33
@shijie-oai
Copy link
Copy Markdown
Collaborator Author

@codex review

@shijie-oai shijie-oai force-pushed the shijie/cf-cookie-preservation-http branch from 8def983 to 40de915 Compare April 15, 2026 14:45
@shijie-oai shijie-oai requested a review from ccy-oai April 15, 2026 17:15
@shijie-oai shijie-oai marked this pull request as draft April 15, 2026 17:17
normalize_remote_control_url("https://chat.openai.com/backend-api")
.expect("chat.openai.com URL should normalize"),
RemoteControlTarget {
websocket_url: "wss://chat.openai.com/backend-api/wham/remote/control/server"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

did we touch websocket?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is for remote control only and I think I will the chagpt_host check consolidation here.

@shijie-oai shijie-oai force-pushed the shijie/cf-cookie-preservation-http branch from 40de915 to ebf719e Compare April 16, 2026 05:47
@shijie-oai shijie-oai changed the title Preserve ChatGPT HTTP cookies Preserve Cloudfare HTTP cookies in codex Apr 17, 2026
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai left a comment

Choose a reason for hiding this comment

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

We need to make sure everyone uses the codex-client. After quickly checking, I could find cloud-tasks/src/env_detect.rs for example that does not rely on it (which is not good though)

Ok after processing my other comments


fn is_chatgpt_cookie_url(url: &reqwest::Url) -> bool {
match url.scheme() {
"http" | "https" => {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should reject http for non-local ChatGPT hosts for multiple security reasons

@@ -1,5 +1,6 @@
use crate::outgoing_message::OutgoingMessage;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This couples remote-control endpoint validation to the cookie/client host allowlist. Those are different security boundaries: a host that is safe for Cloudflare cookie replay is not automatically a valid remote-control websocket/enrollment endpoint. Can we keep a remote-control-specific predicate here, or move the shared data into a small policy module that forces each caller to opt into the right use case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sorry did not get to reply earlier - agree with the assessment and I will break it up again.

@shijie-oai shijie-oai force-pushed the shijie/cf-cookie-preservation-http branch from ebf719e to 54e4816 Compare April 21, 2026 18:13
@shijie-oai shijie-oai marked this pull request as ready for review April 21, 2026 19:19
@shijie-oai shijie-oai force-pushed the shijie/cf-cookie-preservation-http branch from 04241a8 to 6f4f15b Compare April 21, 2026 20:23
@shijie-oai shijie-oai force-pushed the shijie/cf-cookie-preservation-http branch from 6f4f15b to 6189c17 Compare April 21, 2026 20:55
@shijie-oai shijie-oai merged commit c5e9c6f into main Apr 21, 2026
28 checks passed
@shijie-oai shijie-oai deleted the shijie/cf-cookie-preservation-http branch April 21, 2026 21:40
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants