TypeScript
fix(shared): T3 Connect devices connect to hosts with a Latvian, Lithuanian, Basque or Azerbaijani locale (#19616)
shivam18f26cf17950
diff --git a/packages/shared/src/dpop.test.ts b/packages/shared/src/dpop.test.tsindex 67a56f394b2..c6760e4df71 100644--- a/packages/shared/src/dpop.test.ts+++ b/packages/shared/src/dpop.test.ts@@ -2,6 +2,7 @@import * as NodeCrypto from "node:crypto";import { assert, describe, it } from "@effect/vitest";+import { vi } from "vite-plus/test";import {computeDpopAccessTokenHash,@@ -55,6 +56,31 @@ describe("verifyDpopProof", () => {publicJwk,});+ it("computes the RFC 7638 thumbprint whatever the host locale", () => {+ // Latvian collation sorts "y" before "kty", which broke every remote client.+ const latvian = new Intl.Collator("lv");+ const localeCompare = vi.spyOn(String.prototype, "localeCompare").mockImplementation(function (+ this: string,+ that: string,+ ) {+ return latvian.compare(this, that);+ });+ try {+ const rfc7638Input = JSON.stringify({+ crv: publicJwk.crv,+ kty: publicJwk.kty,+ x: publicJwk.x,+ y: publicJwk.y,+ });+ assert.equal(+ computeDpopJwkThumbprint(publicJwk),+ NodeCrypto.createHash("sha256").update(rfc7638Input).digest("base64url"),+ );+ } finally {+ localeCompare.mockRestore();+ }+ });+it("verifies an ES256 DPoP proof and returns the RFC 7638 thumbprint", () => {const thumbprint = computeDpopJwkThumbprint(publicJwk);const result = verifyDpopProof({diff --git a/packages/shared/src/relaySigning.ts b/packages/shared/src/relaySigning.tsindex 6b8b8cb2c7c..69122707027 100644--- a/packages/shared/src/relaySigning.ts+++ b/packages/shared/src/relaySigning.ts@@ -9,7 +9,9 @@ export function stableStringify(value: unknown): string {if (isRecord(value)) {return `{${Object.entries(value).filter(([, entryValue]) => entryValue !== undefined)- .sort(([left], [right]) => left.localeCompare(right))+ // Code-unit order, not localeCompare: signatures and RFC 7638 thumbprints+ // must match across machines whatever their OS locale.+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)).map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`;}