fix(http): adopt an incoming x-request-id only when it is a plain token

The header is echoed on the response and written into every log line. Both
readers (the proxy and apiHandler) now accept it only when it matches
^[A-Za-z0-9-]{8,64}$ and otherwise use a fresh id.
This commit is contained in:
Marc-André Bombeck committed 2026-10-15 20:24:01 +02:00
1 parent f72ec02484
commit 9ee89f2455
4 files changed
+127 -7

No files matched your search

+5 -5
View File
@@ -54,6 +54,7 @@ import {
attachRecordContextEcho,
} from "./sharing/record-session-fence";
import { refuseOnKeyMismatch } from "./boot/key-mismatch-refusal";
import { acceptIncomingRequestId } from "./http/request-id";
import {
capturedRateLimit,
rateLimitResponseHeaders,
@@ -229,11 +230,10 @@ export function apiHandler<T extends (...args: any[]) => Promise<Response>>(
const evt = new WideEventBuilder("http");
// Propagate x-request-id if present
const incomingRequestId = safeRequestProp(
request,
(r) => r.headers.get("x-request-id"),
null,
// Propagate x-request-id when it is a well-formed token. A malformed one
// never reaches the log or the response; the event keeps its fresh id.
const incomingRequestId = acceptIncomingRequestId(
safeRequestProp(request, (r) => r.headers.get("x-request-id"), null),
);
if (incomingRequestId) evt.setRequestId(incomingRequestId);