Grant start reuses the app-caller gate instead of a second caller read; public grant start is 401 app_auth_required

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-29 20:50:05 +01:00
commit b7e86eeef6
3 changed files with 10 additions and 15 deletions

View file

@ -263,10 +263,10 @@ person an app has invited (see the invite grant below).
`LinkRefusal` and the code `identity_not_linked` or `link_initiator_mismatch`.
- Invite grant. An app whose profile sets `mayGrantFirstLogin` (only `bifrost`)
may start `mode: "sign_in"` with `firstLoginGrant: "invite"`, saying it has
invited this person. The start must carry that app's own secret; any other
caller, any other app, any other mode, or any other value is
`400 first_login_grant_refused` (a Bifrost start without the secret is still
`401 app_auth_required`). The grant rides only in the signed state
invited this person. The start must carry that app's own secret: any other
caller, including a public start, is `401 app_auth_required`. An app whose
profile may not grant, any other mode, or any other value is
`400 first_login_grant_refused`. The grant rides only in the signed state
(`first_login_grant`), so nothing a browser sends can set it, and the state
stays single-use. At the callback a `sub` no account holds, under a grant,
mints one account with that identity linked, and audits

View file

@ -829,19 +829,14 @@ export async function startOAuthFlow(
if (options?.trustedBrowserAttemptId && handoff.kind === "browser_completion") {
handoff = { kind: "browser_completion", attemptId: options.trustedBrowserAttemptId };
}
if ((entitlementPolicy || profile.startRequiresAppCaller || (input.mode === "connect" && input.connection !== undefined)) && (!isAppCaller(caller) || caller.appSlug !== profile.slug)) {
if ((entitlementPolicy || profile.startRequiresAppCaller || input.firstLoginGrant !== undefined || (input.mode === "connect" && input.connection !== undefined)) && (!isAppCaller(caller) || caller.appSlug !== profile.slug)) {
return { statusCode: 401, body: { error: "app_auth_required" } };
}
// A grant is the app's word that it invited this person: only the authenticated app caller of a profile that may grant, and only on sign_in.
// After the app-secret gate, so a caller without the secret learns nothing about what a grant needs.
// A grant is the app's word that it invited this person: the app-caller gate above has already admitted only the profile's own app,
// and a caller without the secret learns nothing about what a grant needs. Here: only a profile that may grant, only on sign_in.
if (input.firstLoginGrant !== undefined) {
const grantAllowed =
input.firstLoginGrant === "invite" &&
input.mode === "sign_in" &&
profile.mayGrantFirstLogin === true &&
isAppCaller(caller) && caller.appSlug === profile.slug;
if (!grantAllowed) {
if (!(input.firstLoginGrant === "invite" && input.mode === "sign_in" && profile.mayGrantFirstLogin === true)) {
return {
statusCode: 400,
body: { error: "first_login_grant_refused", detail: "firstLoginGrant needs the app's own sign_in start, from an app that may grant." },

View file

@ -608,13 +608,13 @@ describe("an invite grant lets Bifrost's sign-in start mint the first Google acc
expect(res.statusCode, JSON.stringify(headers)).toBeGreaterThanOrEqual(400);
expect(res.json().authorizationUrl).toBeUndefined();
}
// An app that does not require a caller is still refused by the grant gate itself.
// An app that does not require a caller is still refused: a grant is a start only the app itself may make.
const open = await app.inject({
method: "POST",
url: "/v1/oauth/discord/start",
payload: { appSlug: "repixelizer", mode: "sign_in", returnTo: "https://repixelizer.gamecult.org/app/", firstLoginGrant: "invite" },
});
expect([open.statusCode, open.json().error]).toEqual([400, "first_login_grant_refused"]);
expect([open.statusCode, open.json().error]).toEqual([401, "app_auth_required"]);
expect(accountCount(store)).toBe(0);
});