The best way to control Claude Code, Codex and more from any computer or phone
[codex] fix: guard DPoP fallback URL construction (#3503)
Co-authored-by: Codex <codex@openai.com> Co-authored-by: Julius Marminge <jmarminge@gmail.com>
Wout Stiens committed
Jun 23, 2026 at 01:21 UTC
92e54fb96c5e24c45fc0fa7066a3a4d38294dfc7
1 file changed
+9
-18
apps/server/src/auth/dpop.ts
+9
-18
@@ -3,7 +3,8 @@ import * as Crypto from "effect/Crypto";
3
import * as DateTime from "effect/DateTime";
4
import * as Effect from "effect/Effect";
5
import * as Encoding from "effect/Encoding";
6
-import type * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
6
+import * as Option from "effect/Option";
7
+import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
8
9
import {
10
ServerAuthDpopReplayKeyCalculationError,
@@ -13,22 +14,6 @@ import {
14
} from "./EnvironmentAuth.ts";
15
import * as ServerSecretStore from "./ServerSecretStore.ts";
16
16
-function firstHeaderValue(value: string | undefined): string | undefined {
17
- const first = value?.split(",")[0]?.trim();
18
- return first && first.length > 0 ? first : undefined;
19
-}
20
-
21
-export function requestAbsoluteUrl(request: HttpServerRequest.HttpServerRequest): string {
22
- try {
23
- return new URL(request.originalUrl).href;
24
- } catch {
25
- const host = firstHeaderValue(request.headers.host) ?? "127.0.0.1";
26
- const forwardedProto = firstHeaderValue(request.headers["x-forwarded-proto"]);
27
- const proto = forwardedProto === "https" || forwardedProto === "http" ? forwardedProto : "http";
28
- return new URL(request.originalUrl, `${proto}://${host}`).href;
29
- }
30
-}
31
-
17
export const mapDpopReplayStoreError = (
18
error: ServerSecretStore.SecretStoreError,
19
): ServerAuthInvalidCredentialError | ServerAuthInternalError =>
@@ -48,11 +33,17 @@ export const verifyRequestDpopProof = (input: {
33
}) =>
34
Effect.gen(function* () {
35
const proof = input.request.headers.dpop;
36
+ const url = HttpServerRequest.toURL(input.request);
37
+ if (Option.isNone(url)) {
38
+ return yield* new ServerAuthInvalidCredentialError({
39
+ diagnostic: "Invalid DPoP request URL.",
40
+ });
41
+ }
42
const now = yield* DateTime.now;
43
const result = verifyDpopProof({
44
proof,
45
method: input.request.method,
55
- url: requestAbsoluteUrl(input.request),
46
+ url: url.value.href,
47
nowEpochSeconds: Math.floor(now.epochMilliseconds / 1_000),
48
...(input.expectedThumbprint ? { expectedThumbprint: input.expectedThumbprint } : {}),
49
...(input.expectedAccessToken ? { expectedAccessToken: input.expectedAccessToken } : {}),