diff --git a/c/openai_server.py b/c/openai_server.py index 1fa1669..a68e449 100644 --- a/c/openai_server.py +++ b/c/openai_server.py @@ -672,9 +672,13 @@ class APIHandler(BaseHTTPRequestHandler): self.send_header("Vary", "Origin") def require_auth(self): - if self.server.api_key and self.headers.get("Authorization") != f"Bearer {self.server.api_key}": - raise APIError(401, "Invalid or missing API key.", None, "invalid_api_key", - "authentication_error") + if self.server.api_key: + import hmac + provided = self.headers.get("Authorization", "") + expected = f"Bearer {self.server.api_key}" + if not hmac.compare_digest(provided, expected): + raise APIError(401, "Invalid or missing API key.", None, "invalid_api_key", + "authentication_error") def read_json(self): try: diff --git a/c/resource_plan.py b/c/resource_plan.py index b5571d3..33674e1 100644 --- a/c/resource_plan.py +++ b/c/resource_plan.py @@ -151,8 +151,9 @@ def discover_gpus(): except (OSError, subprocess.SubprocessError): return [] devices = [] - for line in result.stdout.splitlines(): - fields = [field.strip() for field in line.split(",", 3)] + import csv + for fields in csv.reader(result.stdout.splitlines()): + fields = [f.strip() for f in fields] if len(fields) != 4: continue try: