The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(server): accept a case-insensitive DPoP authorization scheme (#30337)
Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
spoukyii committed
Nov 5, 2026 at 20:26 UTC
c12fd6c0352510cc9c65fb7d18504c1973a1e0c0
4 files changed
+74
-2
apps/server/src/auth/EnvironmentAuth.test.ts
+39
@@ -785,6 +785,45 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodePlatformCrypto.layer))(
785
),
786
);
787
788
+ it.effect.each(["DPoP", "dpop", "dPoP"])(
789
+ "accepts %s for a proof-bound HTTP request",
790
+ (scheme) =>
791
+ Effect.gen(function* () {
792
+ const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
793
+ const key = makeDpopKey();
794
+ const { access_token: token } =
795
+ yield* serverAuth.exchangeBootstrapCredentialForAccessToken(
796
+ "desktop-bootstrap-token",
797
+ ["orchestration:read"],
798
+ requestMetadata,
799
+ { proofKeyThumbprint: key.thumbprint },
800
+ );
801
+ const iat = Math.floor((yield* DateTime.now).epochMilliseconds / 1_000);
802
+ const request = {
803
+ method: "GET",
804
+ url: "/api/auth/session",
805
+ cookies: {},
806
+ headers: {
807
+ host: "192.168.1.50:3773",
808
+ authorization: `${scheme} ${token}`,
809
+ dpop: key.sign({
810
+ method: "GET",
811
+ url: "http://192.168.1.50:3773/api/auth/session",
812
+ token,
813
+ iat,
814
+ }),
815
+ },
816
+ } as never;
817
+ expect((yield* serverAuth.authenticateHttpRequest(request)).sessionId).toBeTypeOf(
818
+ "string",
819
+ );
820
+ }).pipe(
821
+ Effect.provide(
822
+ layerEnvironmentAuth({ desktopBootstrapToken: "desktop-bootstrap-token" }),
823
+ ),
824
+ ),
825
+ );
826
+
827
it.effect("rejects a replayed proof on a bound RPC socket ticket", () =>
828
Effect.gen(function* () {
829
const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
apps/server/src/auth/EnvironmentAuth.ts
+1
-1
@@ -640,7 +640,7 @@ export function parseBearerToken(request: HttpServerRequest.HttpServerRequest):
640
641
function parseDpopToken(request: HttpServerRequest.HttpServerRequest): string | null {
642
const header = request.headers["authorization"];
643
- if (typeof header !== "string" || !header.startsWith(DPOP_AUTHORIZATION_PREFIX)) {
643
+ if (typeof header !== "string" || !/^DPoP /i.test(header)) {
644
return null;
645
}
646
const token = header.slice(DPOP_AUTHORIZATION_PREFIX.length).trim();
apps/server/src/auth/http.test.ts
+33
@@ -158,3 +158,36 @@ it.effect("sets the selected browser session cookies through the HTTP route", ()
158
);
159
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
160
);
161
+
162
+it.effect.each(["DPoP", "dpop"])("challenges a refused %s request with DPoP", (scheme) =>
163
+ Effect.gen(function* () {
164
+ const random = yield* SecureRandom.SecureRandom;
165
+ const unusedSecretStore = ServerSecretStore.ServerSecretStore.of({
166
+ get: () => Effect.succeedNone,
167
+ set: () => Effect.void,
168
+ create: () => Effect.void,
169
+ getOrCreateRandom: () => Effect.die("Not used by these routes."),
170
+ remove: () => Effect.void,
171
+ });
172
+ const requestContext = Context.make(SecureRandom.SecureRandom, random).pipe(
173
+ Context.add(ServerSecretStore.ServerSecretStore, unusedSecretStore),
174
+ );
175
+ return yield* Effect.acquireUseRelease(
176
+ Effect.sync(() => HttpRouter.toWebHandler(layerRoutes, { disableLogger: true })),
177
+ (environment) =>
178
+ Effect.promise(async () => {
179
+ const refused = await environment.handler(
180
+ postJson(
181
+ "/api/auth/pairing-token",
182
+ { scopes: ["orchestration:read"] },
183
+ { authorization: `${scheme} not-a-valid-token` },
184
+ ),
185
+ requestContext,
186
+ );
187
+ expect(refused.status).toBe(401);
188
+ expect(refused.headers.get("www-authenticate")).toBe("DPoP");
189
+ }),
190
+ (environment) => Effect.promise(() => environment.dispose()),
191
+ );
192
+ }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
193
+);
apps/server/src/auth/http.ts
+1
-1
@@ -57,7 +57,7 @@ const appendDpopChallengeOnUnauthorized =
57
const request = yield* HttpServerRequest.HttpServerRequest;
58
const usesDpop =
59
(request.originalUrl.startsWith("/oauth/token") && request.headers.dpop !== undefined) ||
60
- request.headers.authorization?.startsWith("DPoP ") === true;
60
+ /^DPoP /i.test(request.headers.authorization ?? "");
61
if (usesDpop) {
62
yield* appendDpopChallengeHeader;
63
}