Skip to content

Commit 18f26cf

Browse files
shivamhwpPR Batch Testerclaudejuliusmarminge
authored
fix(shared): T3 Connect devices connect to hosts with a Latvian, Lithuanian, Basque or Azerbaijani locale (pingdotgg#19616)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent bf2608a commit 18f26cf

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)