Files
codex/codex-rs/exec-server/src/client_inbound_request_limit.rs
T
viyatb-oai 54487a5b61 Bound inbound exec-server requests across client transports (#47362)
## What changed

- Enforce an 8 KiB encoded-message limit for requests, unrecognized notifications, and malformed messages received by exec-server clients over stdio, WebSocket, relay, and Noise relay transports.
- Allow process output, exit, close, and HTTP request body notifications up to 2 MiB. Keep responses and errors subject to existing transport limits, and preserve executor-side request limits.
- Read stdio stderr in chunks of at most 8 KiB.
- Drop outgoing server-request `tracestate` values larger than 512 bytes while preserving `traceparent`.

## Testing

Add regression coverage for oversized requests across transports, malformed messages, requests wrapped in `RawValue`, fragmented Noise messages, large responses, streamed notifications, and trace-context preservation.

GitOrigin-RevId: 3fb87b6dc334296985ef40983d7276acfe9b9796
2026-09-22 21:07:20 +00:00

41 lines
1.6 KiB
Rust

use codex_exec_server_protocol::EXEC_CLOSED_METHOD;
use codex_exec_server_protocol::EXEC_EXITED_METHOD;
use codex_exec_server_protocol::EXEC_OUTPUT_DELTA_METHOD;
use codex_exec_server_protocol::HTTP_REQUEST_BODY_DELTA_METHOD;
use codex_exec_server_protocol::JSONRPCMessage;
use codex_exec_server_protocol::MAX_HTTP_BODY_DELTA_BYTES;
// A transport may materialize one larger frame before its JSON-RPC kind is known.
pub(crate) const MAX_CLIENT_INBOUND_REQUEST_LEN: usize = 8 * 1024;
// Streamed HTTP bodies carry up to 1 MiB before base64 and JSON-RPC framing.
pub(crate) const MAX_CLIENT_INBOUND_NOTIFICATION_LEN: usize = 2 * MAX_HTTP_BODY_DELTA_BYTES;
pub(crate) fn client_inbound_message_exceeded_limit(
message: Result<&JSONRPCMessage, &serde_json::Error>,
encoded_len: usize,
max_request_len: usize,
) -> Option<usize> {
let max_len = match message {
Ok(JSONRPCMessage::Notification(notification))
if matches!(
notification.method.as_str(),
EXEC_OUTPUT_DELTA_METHOD
| EXEC_EXITED_METHOD
| EXEC_CLOSED_METHOD
| HTTP_REQUEST_BODY_DELTA_METHOD
) =>
{
MAX_CLIENT_INBOUND_NOTIFICATION_LEN
}
Ok(JSONRPCMessage::Request(_)) | Ok(JSONRPCMessage::Notification(_)) | Err(_) => {
max_request_len
}
Ok(JSONRPCMessage::Response(_)) | Ok(JSONRPCMessage::Error(_)) => return None,
};
(encoded_len > max_len).then_some(max_len)
}
#[cfg(test)]
#[path = "client_inbound_request_limit_tests.rs"]
mod tests;