Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] fix: guard DPoP fallback URL construction (#3503)

Wout Stiens92e54fb96c5e
diff --git a/apps/server/src/auth/dpop.ts b/apps/server/src/auth/dpop.ts
index 87dc0c263..f19984eb3 100644
--- a/apps/server/src/auth/dpop.ts
+++ b/apps/server/src/auth/dpop.ts
@@ -3,7 +3,8 @@ import * as Crypto from "effect/Crypto";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Encoding from "effect/Encoding";
-import type * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
+import * as Option from "effect/Option";
+import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
import {
ServerAuthDpopReplayKeyCalculationError,
@@ -13,22 +14,6 @@ import {
} from "./EnvironmentAuth.ts";
import * as ServerSecretStore from "./ServerSecretStore.ts";
-function firstHeaderValue(value: string | undefined): string | undefined {
- const first = value?.split(",")[0]?.trim();
- return first && first.length > 0 ? first : undefined;
-}
-
-export function requestAbsoluteUrl(request: HttpServerRequest.HttpServerRequest): string {
- try {
- return new URL(request.originalUrl).href;
- } catch {
- const host = firstHeaderValue(request.headers.host) ?? "127.0.0.1";
- const forwardedProto = firstHeaderValue(request.headers["x-forwarded-proto"]);
- const proto = forwardedProto === "https" || forwardedProto === "http" ? forwardedProto : "http";
- return new URL(request.originalUrl, `${proto}://${host}`).href;
- }
-}
-
export const mapDpopReplayStoreError = (
error: ServerSecretStore.SecretStoreError,
): ServerAuthInvalidCredentialError | ServerAuthInternalError =>
@@ -48,11 +33,17 @@ export const verifyRequestDpopProof = (input: {
}) =>
Effect.gen(function* () {
const proof = input.request.headers.dpop;
+ const url = HttpServerRequest.toURL(input.request);
+ if (Option.isNone(url)) {
+ return yield* new ServerAuthInvalidCredentialError({
+ diagnostic: "Invalid DPoP request URL.",
+ });
+ }
const now = yield* DateTime.now;
const result = verifyDpopProof({
proof,
method: input.request.method,
- url: requestAbsoluteUrl(input.request),
+ url: url.value.href,
nowEpochSeconds: Math.floor(now.epochMilliseconds / 1_000),
...(input.expectedThumbprint ? { expectedThumbprint: input.expectedThumbprint } : {}),
...(input.expectedAccessToken ? { expectedAccessToken: input.expectedAccessToken } : {}),