fix: configure Codex provider authentication
This commit is contained in:
@@ -1834,11 +1834,16 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
|
||||
def _handle_codex_vehicle_control(self) -> None:
|
||||
"""Run an allowlisted MCP tool over the authenticated loopback bridge."""
|
||||
|
||||
try:
|
||||
content_length = int(self.headers.get("Content-Length", "0"))
|
||||
except ValueError:
|
||||
content_length = 0
|
||||
if not self._is_unproxied_loopback_request():
|
||||
self._json(
|
||||
{"error": "local_access_required", "message": "仅允许本机 Codex 工具调用。"},
|
||||
HTTPStatus.FORBIDDEN,
|
||||
)
|
||||
self._drain_rejected_request_body(content_length, max_bytes=32 * 1024)
|
||||
return
|
||||
if not self.assistant.authenticate_internal_request(
|
||||
self.headers.get("X-N7-Internal-Token", "")
|
||||
@@ -1847,6 +1852,7 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
|
||||
{"error": "invalid_internal_token", "message": "Codex 工具认证失败。"},
|
||||
HTTPStatus.FORBIDDEN,
|
||||
)
|
||||
self._drain_rejected_request_body(content_length, max_bytes=32 * 1024)
|
||||
return
|
||||
try:
|
||||
payload = self._read_json_body(max_bytes=32 * 1024)
|
||||
@@ -2846,17 +2852,22 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
|
||||
if slot_acquired:
|
||||
self.speech_preview_http_slots.release()
|
||||
|
||||
def _drain_rejected_request_body(self, content_length: int) -> None:
|
||||
"""Gracefully finish an early-rejected POST without doing speech work.
|
||||
def _drain_rejected_request_body(
|
||||
self,
|
||||
content_length: int,
|
||||
*,
|
||||
max_bytes: int = 2 * 1024 * 1024,
|
||||
) -> None:
|
||||
"""Gracefully finish an early-rejected POST without processing its payload.
|
||||
|
||||
Closing a Windows socket while its peer's request body is still unread can
|
||||
replace an already-written HTTP error with TCP RST. Flush the rejection
|
||||
first, then briefly discard a valid-sized body so clients reliably receive
|
||||
the 4xx response. The preview/transcriber concurrency gates still run
|
||||
before any audio is read or decoded.
|
||||
the 4xx response. Callers choose a strict size ceiling, and authorization or
|
||||
concurrency gates still run before any payload is read or decoded.
|
||||
"""
|
||||
|
||||
if content_length <= 0 or content_length > 2 * 1024 * 1024:
|
||||
if content_length <= 0 or content_length > max_bytes:
|
||||
return
|
||||
self.close_connection = True
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user