Skip to content

Commit 9d0192d

Browse files
PR Batch Testerclaude
andcommitted
fix(shared): T3 Connect devices connect to hosts with a Latvian, Lithuanian, Basque or Azerbaijani locale
stableStringify sorted object keys with localeCompare and no locale, so the host's OS locale picked the order. Under lv, lt, eu and az the RFC 7638 thumbprint input came out as crv,y,kty,x (or crv,x,kty,y), the host computed a different key thumbprint than the client and the cloud, and every remote credential failed with invalid_credential. Sort by code unit instead. Closes #19610 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 348f217 commit 9d0192d

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/shared/src/dpop.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as NodeCrypto from "node:crypto";
33

44
import { assert, describe, it } from "@effect/vitest";
5+
import { vi } from "vite-plus/test";
56

67
import {
78
computeDpopAccessTokenHash,
@@ -55,6 +56,31 @@ describe("verifyDpopProof", () => {
5556
publicJwk,
5657
});
5758

59+
it("computes the RFC 7638 thumbprint whatever the host locale", () => {
60+
// Latvian collation sorts "y" before "kty", which broke every remote client.
61+
const latvian = new Intl.Collator("lv");
62+
const localeCompare = vi.spyOn(String.prototype, "localeCompare").mockImplementation(function (
63+
this: string,
64+
that: string,
65+
) {
66+
return latvian.compare(this, that);
67+
});
68+
try {
69+
const rfc7638Input = JSON.stringify({
70+
crv: publicJwk.crv,
71+
kty: publicJwk.kty,
72+
x: publicJwk.x,
73+
y: publicJwk.y,
74+
});
75+
assert.equal(
76+
computeDpopJwkThumbprint(publicJwk),
77+
NodeCrypto.createHash("sha256").update(rfc7638Input).digest("base64url"),
78+
);
79+
} finally {
80+
localeCompare.mockRestore();
81+
}
82+
});
83+
5884
it("verifies an ES256 DPoP proof and returns the RFC 7638 thumbprint", () => {
5985
const thumbprint = computeDpopJwkThumbprint(publicJwk);
6086
const result = verifyDpopProof({

‎packages/shared/src/relaySigning.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export function stableStringify(value: unknown): string {
99
if (isRecord(value)) {
1010
return `{${Object.entries(value)
1111
.filter(([, entryValue]) => entryValue !== undefined)
12-
.sort(([left], [right]) => left.localeCompare(right))
12+
// Code-unit order, not localeCompare: signatures and RFC 7638 thumbprints
13+
// must match across machines whatever their OS locale.
14+
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
1315
.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`)
1416
.join(",")}}`;
1517
}

0 commit comments

Comments
 (0)