Relay's error description is set only when one survives

Typecheck under exactOptionalPropertyTypes refused the relay commit: a
provider error that filters down to nothing left errorDescription
explicitly undefined in the page and handoff payloads. The field is now
added only when a relayed value remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 15:50:58 +02:00
commit f94729f5f7
2 changed files with 5 additions and 3 deletions

View file

@ -972,6 +972,8 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
if (request.query.error) {
const providerError = relayedProviderText(request.query.error, 64);
const providerErrorDescription = relayedProviderText(request.query.error_description, 256);
const relayedDescription = providerErrorDescription ?? providerError;
const relayedDescriptionField = relayedDescription ? { errorDescription: relayedDescription } : {};
await denyBrowserAttempt("provider_error");
if (handoff.kind === "backend_callback") {
await maybeDeliverBackendHandoff(handoff, {
@ -986,7 +988,7 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
returnTo: statePayload.return_to,
connection: statePayload.connection,
error: "provider_error",
errorDescription: providerErrorDescription ?? providerError,
...relayedDescriptionField,
});
}
@ -1002,7 +1004,7 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
returnTo: statePayload.return_to,
...(handoff.kind === "backend_callback" ? { attemptId: handoff.attemptId } : {}),
error: "provider_error",
errorDescription: providerErrorDescription ?? providerError,
...relayedDescriptionField,
})
);
}

View file

@ -1427,7 +1427,7 @@ describe("the relayed provider error", () => {
expect(providerError).toBe("e".repeat(64));
expect(providerErrorDescription).toHaveLength(256);
expect(providerErrorDescription).toMatch(allowed);
expect(providerErrorDescription.startsWith("<script>alert(1)</script>xxx")).toBe(true);
expect(String(providerErrorDescription).startsWith("<script>alert(1)</script>xxx")).toBe(true);
});
it("cannot inject markup into the browser page, and is bounded there", async () => {