From 7de12e84be92e2696f1aed7d0f8292a941f1e170 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 15:49:30 +0200 Subject: [PATCH] Relayed provider errors are printable, bounded and inert in the page Self's ruling: the provider_error relay stays, because it is the protocol, but its error and error_description are query parameters anyone can write. Only the characters RFC 6749 4.1.2.1 allows in them survive (%x20-21, %x23-5B, %x5D-7E), and each is cut to a bound (64 and 256). The JSON answer, the browser page and the backend handoff all take the relayed values. The page has no template engine. Every value in it goes through serializeForScript, which escapes `<`, apart from the fallback URL in the link's href, which the URL serializer percent-encodes. A test puts `"\\\u0007é${"x".repeat(300)}`; + const allowed = /^[\x20-\x21\x23-\x5b\x5d-\x7e]*$/; + + function providerErrorUrl(stateToken: string): string { + const query = new URLSearchParams({ state: stateToken, error: `${"e".repeat(100)}\u0000`, error_description: injected }); + return `/v1/oauth/discord/callback?${query.toString()}`; + } + + it("is printable and bounded in the JSON answer", async () => { + const app = await buildApp({ config: createTestConfig() }); + apps.push(app); + + const response = await app.inject({ method: "GET", url: providerErrorUrl(await startDiscordSignIn(app)) }); + + expect(response.statusCode).toBe(400); + const { providerError, providerErrorDescription } = response.json() as Record; + expect(providerError).toBe("e".repeat(64)); + expect(providerErrorDescription).toHaveLength(256); + expect(providerErrorDescription).toMatch(allowed); + expect(providerErrorDescription.startsWith("xxx")).toBe(true); + }); + + it("cannot inject markup into the browser page, and is bounded there", async () => { + const app = await buildApp({ config: createTestConfig() }); + apps.push(app); + + const response = await app.inject({ + method: "GET", + url: providerErrorUrl(await startDiscordSignIn(app)), + headers: { accept: "text/html" }, + }); + + expect(response.headers["content-type"]).toContain("text/html"); + expect(response.body.match(/