Skip to content

Commit d5bfcc3

Browse files
committed
[owl] Make Bearer Auth case-insensitive (#811)
API server: owl - Make Bearer Auth case-insensitive - Bug fix: messages
1 parent d64ded7 commit d5bfcc3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

services/api/src/owl/utils/handlers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def make_response(
8787
headers["x-request-id"] = request.headers.get("x-request-id", "")
8888
request_headers = {k.lower(): v for k, v in request.headers.items()}
8989
token = request_headers.get("authorization", "")
90-
if token.startswith("Bearer "):
91-
request_headers["authorization"] = f"Bearer {mask_string(token[7:], include_len=False)}"
90+
if token.lower().startswith("bearer "):
91+
request_headers["authorization"] = (
92+
f"{token[:6]} {mask_string(token[7:], include_len=False)}"
93+
)
9294
else:
9395
request_headers["authorization"] = mask_string(token, include_len=False)
9496
response = ORJSONResponse(

services/api/src/owl/utils/lm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _map_and_log_exception(
234234
messages: list[dict] | None = None,
235235
**hyperparams,
236236
) -> Exception:
237-
messages = [mask_content(m) for m in messages]
237+
messages = [mask_content(m) for m in messages] if messages else None
238238
err_mssg = getattr(e, "message", str(e))
239239
if isinstance(e, JamaiException):
240240
return e

services/api/tests/routers/test_serving.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ def test_model_info(setup: ServingContext):
310310
assert isinstance(response, ModelInfoListResponse)
311311
assert len(response.data) == 4
312312

313+
# Test Bearer Auth case-insensitivity
314+
response = JamAI(
315+
user_id=setup.user_id,
316+
project_id=setup.project_ids[0],
317+
headers={"Authorization": f"beaRER {ENV_CONFIG.service_key_plain}"},
318+
).model_info()
319+
assert isinstance(response, ModelInfoListResponse)
320+
assert len(response.data) == 4
321+
313322
response = client.model_info(model=chat_model_id)
314323
assert len(response.data) == 1
315324
assert response.data[0].id == chat_model_id

0 commit comments

Comments
 (0)