mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Escape turn metadata headers as ASCII JSON (#19620)
## Why `x-codex-turn-metadata` is sent as an HTTP/WebSocket header, but Codex was serializing the metadata JSON with raw UTF-8 string contents. When a workspace path contains non-ASCII characters, common HTTP stacks can reject or corrupt that header before the request reaches the provider. Fixes #17468. Also addresses the duplicate WebSocket report in #19581. ## What changed - Added `codex_utils_string::to_ascii_json_string`, a shared helper that serializes JSON normally while escaping non-ASCII string content as `\uXXXX`. - Switched turn metadata header serialization, including merged Responses API client metadata, to use the ASCII-safe JSON helper. - Added coverage for non-ASCII workspace paths and non-ASCII client metadata while preserving the same parsed JSON values. ## Verification - `cargo test -p codex-utils-string` - `cargo test -p codex-core turn_metadata` - `just bazel-lock-check`
This commit is contained in:
1 parent
b1546008fc
commit
4241df4d79
6 files changed
+146
-3
No files matched your search
@@ -4,6 +4,7 @@ use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
|
||||
use codex_utils_string::to_ascii_json_string;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use tokio::task::JoinHandle;
|
||||
@@ -71,7 +72,7 @@ pub(crate) struct TurnMetadataBag {
|
||||
|
||||
impl TurnMetadataBag {
|
||||
fn to_header_value(&self) -> Option<String> {
|
||||
serde_json::to_string(self).ok()
|
||||
to_ascii_json_string(self).ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ fn merge_turn_metadata(
|
||||
.or_insert_with(|| Value::String(value.clone()));
|
||||
}
|
||||
}
|
||||
serde_json::to_string(&metadata).ok()
|
||||
to_ascii_json_string(&metadata).ok()
|
||||
}
|
||||
|
||||
fn build_turn_metadata_bag(
|
||||
|
||||
Reference in new issue
Block a user