fix: validate Codex base URL scheme and host
Merged
MY
4mo ago+96+96+01234567890123456789-2-2-0123456789
Summary
Hardens the Codex base URL so credentials are only sent to https (or loopback http) endpoints, falling back to the default backend otherwise. Addresses the open CodeQL js/file-access-to-http finding (alert #1), which fired because file-derived config (providers.codex.baseUrl) flowed into the fetch URL.
Changes
- Add
resolveCodexBaseUrl/isLoopbackHostinsrc/providers/codex.ts; restrict tohttps:(loopbackhttp:for local tests), fall back to the default ChatGPT backend for anything else. - Codex fetch behavior is unchanged for default/valid configs; ZAI is untouched (its URL is already a constant).
- Add tests covering safe URLs (https + loopback http) and unsafe fallbacks (
http://evil.example,ftp://,not a url). - CodeQL alert #1 dismissed as false positive (the auth-to-headers taint path is intrinsic to the plugin).
Type
- fix
Checklist
-
bun run typecheckpasses -
bun run checkpasses -
bun testpasses, or tests are not needed - Conventional commit message used
- Changeset added if user-facing, or noted as not needed
- PR description is concise
Summary by cubic
Validate the Codex base URL so tokens only go to HTTPS or loopback HTTP; invalid or non-HTTPS values fall back to the default backend to close the CodeQL js/file-access-to-http finding.
- Bug Fixes
- Added
resolveCodexBaseUrlandisLoopbackHostto allow onlyhttps:or loopbackhttp:; IPv6 loopback now correctly handles[::1]. - No behavior change for valid configs; ZAI provider untouched.
- Added tests for safe URLs and fallback on unsafe/invalid inputs.
- Added
[!NOTE]
Validate Codex base URL scheme and host, falling back to default backend when unsafe
- Adds
resolveCodexBaseUrl in src/providers/codex.ts to validate the configured base URL: only https is accepted, or http for loopback hosts (localhost, 127.x.x.x, ::1).
- Invalid URLs, unsupported schemes, or non-loopback
http hosts fall back to the default ChatGPT backend URL.
fetchCodexUsage now uses the resolved URL instead of the raw config.baseUrl.
- Behavioral Change: previously any
baseUrl value was used as-is; now unsafe or malformed values are silently replaced with the default backend.
Macroscope summarized 6997ede.