From e5c9228be26a5793894b55c9098a83628006a607 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 8 Sep 2026 14:22:26 +0200 Subject: [PATCH] app.ts: never trust a caller-chosen completion code or returnTo origin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createAuthCompletion no longer takes `code: handoff.attemptId` — the store mints it (previous commit); attemptId is passed through only as the new `attemptId` correlation field. The redeem route's updateAuthAttempt call used request.body.completionCode as if it were the attempt handle, which only ever worked by the coincidence that the private plane's own flow had code === handle; it now uses completion.attemptId, the real correlation. startOAuthFlow also refuses any returnTo whose origin is not in the target app's AppProfile.allowedReturnOrigins (400 return_to_not_allowed). Before this, returnTo was validated only as `format: uri`, and the browser handoff page postMessages the completion payload to new URL(returnTo).origin — an unlisted origin was an exfiltration primitive for whatever the browser flow hands back, completion code included. Co-Authored-By: Claude Opus 5 --- src/app.ts | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/app.ts b/src/app.ts index 6332dc0..378f015 100644 --- a/src/app.ts +++ b/src/app.ts @@ -23,7 +23,7 @@ import { type Provider, } from "./contracts.js"; import { issueAccessClaim, type IssueAccessClaimInput } from "./claims.js"; -import { builtInAppProfiles, getAppProfile, serializeAppProfile, supportsProvider } from "./app-profiles.js"; +import { builtInAppProfiles, getAppProfile, isAllowedReturnOrigin, serializeAppProfile, supportsProvider } from "./app-profiles.js"; import { listAppProfiles, resolveAppProfile } from "./app-registry.js"; import { renderBrowserHandoffPage } from "./browser-handoff.js"; import { type HeimdallConfig, loadConfig } from "./config.js"; @@ -522,6 +522,13 @@ export async function startOAuthFlow( }; } + if (!isAllowedReturnOrigin(profile, input.returnTo)) { + return { + statusCode: 400, + body: { error: "return_to_not_allowed", detail: `returnTo must land on an origin ${profile.slug} owns.` }, + }; + } + let handoff: OAuthHandoff; try { handoff = normalizeOAuthHandoff(input.handoff); @@ -1190,8 +1197,15 @@ export async function buildApp(options: BuildAppOptions = {}): Promise