Skip to content

fix: remove browser UA spoofing for ChatGPT API requests#124

Merged
Loongphy merged 3 commits into
mainfrom
fix/remove-ua-spoofing-for-usage-api
May 28, 2026
Merged

fix: remove browser UA spoofing for ChatGPT API requests#124
Loongphy merged 3 commits into
mainfrom
fix/remove-ua-spoofing-for-usage-api

Conversation

@Loongphy
Copy link
Copy Markdown
Owner

Summary

Replace the Chrome browser User-Agent string with an honest codex-auth/<version> identifier for all requests to chatgpt.com/backend-api endpoints (usage, account check).

Motivation

The previous UA was a hardcoded Chrome browser string:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

This was unnecessary — the API works fine with a transparent client identifier. The official Codex CLI similarly identifies itself as codex_cli_rs/<version>.

Testing

Verified with a Business (team) account that the usage API returns HTTP 200 with codex-auth/0.3.0-alpha.9 UA.

Replace Chrome browser User-Agent with honest `codex-auth/<version>`
identifier for all requests to chatgpt.com backend-api endpoints
(usage, account check).

The previous Chrome UA string was unnecessary — the API works fine
with a transparent client identifier, matching how the official
Codex CLI identifies itself as `codex_cli_rs/<version>`.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Greptile Summary

This PR replaces the hardcoded Chrome browser User-Agent string with a transparent codex-auth/<version> identifier for all chatgpt.com/backend-api requests, and renames the constant from browser_user_agent to user_agent across the codebase.

  • http_types.zig: Drops the Chrome UA literal, imports version.zig, and builds the new value via compile-time string concatenation ("codex-auth/" ++ version.app_version).
  • http.zig / http_node.zig: All four references (re-export + three call sites) are updated to user_agent, completing the rename with no orphaned references.

Confidence Score: 5/5

Safe to merge — a straightforward UA string replacement with all references consistently updated.

The change is a mechanical find-and-replace: one constant redefined in http_types.zig and every call site in http.zig and http_node.zig updated in the same commit. The new value uses a compile-time ++ concatenation of two string literals, which is valid Zig. No logic, auth flow, or data handling is altered.

No files require special attention.

Important Files Changed

Filename Overview
src/api/http_types.zig Replaces the hardcoded Chrome UA string with "codex-auth/" ++ version.app_version; renames constant to user_agent. The version.app_version is a compile-time literal so string concatenation is valid Zig.
src/api/http.zig Re-export updated from types.browser_user_agent to types.user_agent; single-line change, consistent with the rename in http_types.zig.
src/api/http_node.zig All four references (import binding + three call sites at lines 269, 337, 414) updated from browser_user_agent to user_agent; no logic changes.

Sequence Diagram

sequenceDiagram
    participant C as codex-auth client
    participant N as Node.js helper
    participant API as chatgpt.com/backend-api

    C->>N: "spawn with UA = "codex-auth/0.3.0-alpha.9""
    Note over N: runNodeBearerGetJsonCommand<br/>runNodeGetJsonCommand<br/>runNodeGetJsonBatchCommand
    N->>API: GET /usage (User-Agent: codex-auth/0.3.0-alpha.9)
    API-->>N: 200 OK + JSON
    N-->>C: parsed response
Loading

Reviews (3): Last reviewed commit: "fix: update remaining browser_user_agent..." | Re-trigger Greptile

Comment thread src/api/http_types.zig Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 28, 2026

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-arm64@bf66e54

@loongphy/codex-auth-darwin-x64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-x64@bf66e54

@loongphy/codex-auth-linux-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-arm64@bf66e54

@loongphy/codex-auth-linux-x64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-x64@bf66e54

@loongphy/codex-auth-win32-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-arm64@bf66e54

@loongphy/codex-auth-win32-x64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-x64@bf66e54

@loongphy/codex-auth

npx https://pkg.pr.new/@loongphy/codex-auth@bf66e54

commit: bf66e54

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Comment thread src/api/http_types.zig
pub const child_process_timeout_ms: []const u8 = "7000";
pub const child_process_timeout_ms_value: u64 = 7000;
pub const browser_user_agent: []const u8 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36";
pub const user_agent: []const u8 = "codex-auth/" ++ version.app_version;
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.

P0 Build-breaking rename — two call sites not updated

browser_user_agent was renamed to user_agent here, but src/api/http.zig (line 14) and src/api/http_node.zig (line 16) still import types.browser_user_agent. Because that symbol no longer exists in http_types.zig, both files will fail to compile. The rename must be propagated to every reference, including the aliased re-exports in http.zig and the local binding + all three use-sites in http_node.zig (lines 16, 269, 337, 414).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/api/http_types.zig
Line: 9

Comment:
**Build-breaking rename — two call sites not updated**

`browser_user_agent` was renamed to `user_agent` here, but `src/api/http.zig` (line 14) and `src/api/http_node.zig` (line 16) still import `types.browser_user_agent`. Because that symbol no longer exists in `http_types.zig`, both files will fail to compile. The rename must be propagated to every reference, including the aliased re-exports in `http.zig` and the local binding + all three use-sites in `http_node.zig` (lines 16, 269, 337, 414).

How can I resolve this? If you propose a fix, please make it concise.

Fix in Codex

The remote rename of browser_user_agent → user_agent in http_types.zig
left stale references in http.zig and http_node.zig.
@Loongphy Loongphy merged commit 5706e85 into main May 28, 2026
13 checks passed
@Loongphy Loongphy deleted the fix/remove-ua-spoofing-for-usage-api branch May 28, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant