fix(ui): percent-encode logId/request_id in /spend/logs/ui endpoint (#47808)

This commit is contained in:
Charlie Freeman 2026-10-22 15:21:59 +08:00
parent f2118fc767
commit 51875ec3e0
3 changed files with 21 additions and 3 deletions

View file

@ -9,6 +9,7 @@ single markdown report that can be pasted into a bug report or handed to another
import json
import os
import re
import urllib.parse
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from datetime import datetime, timezone
@ -177,7 +178,7 @@ class SpendLogsFetcher:
return DebugFailure(f"Unexpected {uri} response: {e}")
def payload(self, request_id: str) -> RequestResponsePayload | None | DebugFailure:
uri: Final = f"/spend/logs/ui/{request_id}"
uri: Final = f"/spend/logs/ui/{urllib.parse.quote(request_id, safe='')}"
raw: Final = self._get(uri)
if isinstance(raw, DebugFailure):
return raw

View file

@ -1177,4 +1177,20 @@ describe("getUiConfig runtime backend discovery", () => {
discovery_mode: "well_known_fallback",
});
});
it("encodes special characters in logId when calling uiSpendLogDetailsCall", async () => {
const originalFetch = global.fetch;
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
json: vi.fn().mockResolvedValue({ id: "test" }),
});
global.fetch = mockFetch;
try {
await Networking.uiSpendLogDetailsCall("token-123", "chatcmpl-123#a1", "2026-01-01");
const calledUrl = String(mockFetch.mock.calls.at(-1)?.[0]);
expect(calledUrl).toContain("/spend/logs/ui/chatcmpl-123%23a1?start_date=2026-01-01");
} finally {
global.fetch = originalFetch;
}
});
});

View file

@ -4779,9 +4779,10 @@ export const createGuardrailCall = async (accessToken: string, guardrailData: an
export const uiSpendLogDetailsCall = async (accessToken: string, logId: string, start_date: string) => {
try {
// Construct base URL
const encodedLogId = encodeURIComponent(logId);
let url = proxyBaseUrl
? `${proxyBaseUrl}/spend/logs/ui/${logId}?start_date=${encodeURIComponent(start_date)}`
: `/spend/logs/ui/${logId}?start_date=${encodeURIComponent(start_date)}`;
? `${proxyBaseUrl}/spend/logs/ui/${encodedLogId}?start_date=${encodeURIComponent(start_date)}`
: `/spend/logs/ui/${encodedLogId}?start_date=${encodeURIComponent(start_date)}`;
const response = await fetch(url, {
method: "GET",