Skip to content

Commit 7003a12

Browse files
Pigbibicodex
andcommitted
Sanitize Codex quota app-server environment
Co-Authored-By: Codex <noreply@openai.com>
1 parent 857fea3 commit 7003a12

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

service/codex_account.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import time
1111
from typing import Any
1212

13+
from service.adapters.codex_adapter import _codex_env
14+
1315

1416
def _bool_env(name: str, default: bool = False) -> bool:
1517
value = os.environ.get(name, "").strip().lower()
@@ -108,6 +110,7 @@ def read_codex_rate_limits(timeout_seconds: float | None = None) -> dict[str, An
108110
stdout=subprocess.PIPE,
109111
stderr=subprocess.DEVNULL,
110112
text=True,
113+
env=_codex_env(),
111114
)
112115
_send(
113116
proc,
@@ -153,6 +156,10 @@ def read_codex_rate_limits(timeout_seconds: float | None = None) -> dict[str, An
153156
proc.wait(timeout=0.5)
154157
except subprocess.TimeoutExpired:
155158
proc.kill()
159+
try:
160+
proc.wait(timeout=0.5)
161+
except subprocess.TimeoutExpired:
162+
pass
156163
for stream in (proc.stdin, proc.stdout):
157164
if stream is not None:
158165
stream.close()

tests/test_codex_account.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def test_reads_sanitized_rate_limits_from_app_server(self) -> None:
3636
"""
3737
#!/usr/bin/env python3
3838
import json
39+
import os
3940
import sys
4041
42+
if os.environ.get("CODEX_AUDIT_SERVICE_TOKEN") or os.environ.get("OPENAI_API_KEY"):
43+
sys.exit(7)
44+
4145
for line in sys.stdin:
4246
message = json.loads(line)
4347
method = message.get("method")
@@ -66,6 +70,8 @@ def test_reads_sanitized_rate_limits_from_app_server(self) -> None:
6670
fake_codex.chmod(0o700)
6771
env = {
6872
"CODEX_AUDIT_SERVICE_CODEX_ACCOUNT_USAGE": "1",
73+
"CODEX_AUDIT_SERVICE_TOKEN": "service-token-must-not-reach-codex",
74+
"OPENAI_API_KEY": "openai-key-must-not-reach-codex",
6975
"PATH": str(bin_dir) + os.pathsep + os.environ.get("PATH", ""),
7076
}
7177
with patch.dict(os.environ, env, clear=True):

0 commit comments

Comments
 (0)