diff --git a/docs/guest-accounts.md b/docs/guest-accounts.md index 6046d93..56e6271 100644 --- a/docs/guest-accounts.md +++ b/docs/guest-accounts.md @@ -19,7 +19,7 @@ These four are the Bifrost steward's; they replace the recommendations further d 1. **Name and shape: a stored `Membership.Role` (enum `AccountRole`), not a boolean.** One stored field is one reading, and an account with no role is denied by default (least privilege). `MemberRole` keeps its name and meaning; renaming it is not needed, and nothing existing is removed. 2. **Invite: a single-use code redeemed from a form, never a token in a URL.** The issuer is shown the code once; the guest pastes it into `POST /invite/guest` (a body, not a path or query), so it reaches no log, referrer or browser history. Hashed at rest, seven days, one use, receipted on issue, accept and revoke. The issuer may bind `ExpectedProvider` (optional, narrows the invite). The sign-in return path carries only the Heimdall attempt, never the code. -3. **Provider lists: Bifrost narrows to the intersection with Heimdall's `bifrost` profile, `discord, patreon`; no widening.** Twitch cannot start in Heimdall, so dropping it removes nothing live; it logs a deprecation warning for one release before the entry goes (deprecate before remove). Google stays link-only (PRs #81, #82) and becomes a sign-in provider only when an issued invite needs it, by a profile change in Heimdall first. Which provider sletz uses is still the issuer's to learn. +3. **Provider lists: Bifrost narrows to the intersection with Heimdall's `bifrost` profile, `discord, patreon`; no widening.** Twitch cannot start in Heimdall, so dropping it removes nothing live; it logs a deprecation warning for one release before the entry goes (deprecate before remove). Google is a sign-in provider too: a Google start carrying a live invite asks Heimdall for an invite grant, and Heimdall mints an account only under it (Bifrost PR #92). Which provider sletz uses is still the issuer's to learn. 4. **Collector: a guest has no `member_id` and none of their messages are collected.** A sender with no linked member is already dropped (`docs/answer-collector-consent.md` l.197 in Heimdall). A `member_id`, and a consent record under it, exists only on promotion to `member`. ## The shape in one paragraph @@ -108,13 +108,7 @@ issuer may not have); the issuer may still set `ExpectedProvider` (see Rulings). are added and the invite is spent. If the existing account is `Left` or `Erased`, refuse. 4. Bifrost issues its own cookie as for any account. From there the guest reaches chat through the one OIDC client. -Gap, drift found while reading, still true on main: Bifrost's `AllowedProviders` is `discord, patreon, twitch` -(`HeimdallAuthService.cs:37-42`), but Heimdall's `bifrost` app profile allows `discord, patreon, google` -(`app-profiles.ts:152`, `bifrostProfile`). Twitch cannot start in Heimdall and Google is refused by Bifrost as a sign-in provider. -Main's only Google path is the explicit link by an already signed-in member (`HeimdallAttemptPurpose.LinkAwaitGoogle`, -`HeimdallAuthService.cs:672`, PRs #81 and #82); it never signs anyone in, so it does not close the gap. A guest with -neither Discord, Patreon nor a Google account cannot sign in, and GitHub is not a Heimdall sign-in provider for -this app. Which provider sletz uses is unknown to me; align the two lists before the first invite. +Bifrost's `AllowedProviders` is `discord, patreon, twitch, google` (`HeimdallAuthService.cs`); Heimdall's `bifrost` app profile allows `discord, patreon, google` (`app-profiles.ts`, `bifrostProfile`), so Twitch cannot start in Heimdall. A Google start carrying a live invite asks Heimdall for an invite grant (PR #92); Google also stays the explicit link by a signed-in member (`HeimdallAttemptPurpose.LinkAwaitGoogle`, PRs #81 and #82). Which provider sletz uses is unknown; the issuer learns it before the first invite. ## Guest rights diff --git a/docs/linked-accounts.md b/docs/linked-accounts.md index c8c10f5..08a2240 100644 --- a/docs/linked-accounts.md +++ b/docs/linked-accounts.md @@ -24,7 +24,7 @@ Every action is a POST with antiforgery; a GET starts nothing. The completion ro ## Which provider proves the account -An ordinary proof sign-in through Discord or Patreon when the account no longer holds that login makes Heimdall mint a new, unrelated account that holds it (those providers are `mints_account`), and the freed login then answers `identity_linked_elsewhere` when the member tries to link it back. Google is `requires_link`: Heimdall refuses a Google sign-in for a login no account holds (`identity_not_linked`) and never mints. So Bifrost never guesses a provider, and it does not use the "provider you signed in with" claim in the session (that records how you signed in once, not what the account holds now). This guarantee covers this page's proofs only: the older anonymous `GET /auth/heimdall/{provider}` still starts an ordinary sign-in through any named provider, and can overwrite an in-flight attempt slot; that route is unchanged here. +An ordinary proof sign-in through Discord or Patreon when the account no longer holds that login makes Heimdall mint a new, unrelated account that holds it (those providers are `mints_account`), and the freed login then answers `identity_linked_elsewhere` when the member tries to link it back. Google is `requires_link`: Heimdall refuses a Google sign-in for a login no account holds (`identity_not_linked`) and mints only under an invite grant, which a proof never asks for. So Bifrost never guesses a provider, and it does not use the "provider you signed in with" claim in the session (that records how you signed in once, not what the account holds now). This guarantee covers this page's proofs only: the older anonymous `GET /auth/heimdall/{provider}` still starts an ordinary sign-in through any named provider, and can overwrite an in-flight attempt slot; that route is unchanged here. - With a current list (the five-minute snapshot), the proof goes through a provider on it: Discord, else Patreon, else Google. - With no list (first visit, five minutes passed, a restart), the page offers only "Show my logins through Google (cannot create an account) / Discord / Patreon" and says plainly that Bifrost cannot tell what the account holds, so the member picks a login they know it holds. A named Discord or Patreon the account turns out not to hold still mints at Heimdall: that is the member's choice and the page says so beforehand. A refresh with no list and no named provider starts nothing (`provider_needed`). diff --git a/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs b/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs index 775b0ca..dc7981a 100644 --- a/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs +++ b/src/Bifrost.Web/Features/Heimdall/HeimdallAuthService.cs @@ -169,7 +169,7 @@ public sealed class HeimdallAuthService( new Uri(payload.AuthorizationUrl, UriKind.Absolute), replaceSlot ?? ChooseSlot(requestCookies), Protect(attempt)); } - /// A start that cannot reach Heimdall is a refusal like any other, never a 500. + /// True when the cookie names a live invite, read through ChatInviteService, the one owner of invites. private async Task HoldsLiveInviteAsync(IEnumerable> requestCookies, CancellationToken cancellationToken) { foreach (var (name, value) in requestCookies) @@ -183,6 +183,7 @@ public sealed class HeimdallAuthService( return false; } + /// A start that cannot reach Heimdall is a refusal like any other, never a 500. private async Task SendStartAsync(HttpRequestMessage message, CancellationToken cancellationToken) { try diff --git a/tests/Bifrost.Web.Tests/GoogleInviteSignInTests.cs b/tests/Bifrost.Web.Tests/GoogleInviteSignInTests.cs index 61e1e53..a00973b 100644 --- a/tests/Bifrost.Web.Tests/GoogleInviteSignInTests.cs +++ b/tests/Bifrost.Web.Tests/GoogleInviteSignInTests.cs @@ -50,32 +50,79 @@ public sealed class GoogleInviteSignInTests } [Fact] - public async Task A_google_start_without_a_live_invite_carries_no_grant() + public async Task A_google_start_with_no_cookie_or_a_junk_cookie_carries_no_grant() { using var host = new HeimdallHost(); - var (redeemed, _) = await MintAsync(host); - var (revoked, revokedId) = await MintAsync(host); - var (expired, _) = await MintAsync(host); - using (var scope = host.Services.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - var hash = ChatInviteService.Hash(redeemed); - (await db.ChatInvites.SingleAsync(x => x.TokenHash == hash)).RedeemedAtUtc = host.Clock.Now; - await scope.ServiceProvider.GetRequiredService().RevokeAsync(revokedId, Guid.NewGuid(), CancellationToken.None); - await db.SaveChangesAsync(); - } + await MintAsync(host); - host.Clock.Advance(ChatInviteService.Lifetime + TimeSpan.FromMinutes(1)); - var (fresh, _) = await MintAsync(host); // minted after the jump: live, so the three above are the only dead ones. - - foreach (var cookie in new string?[] { null, Jar("not-a-token"), Jar(redeemed), Jar(revoked), Jar(expired) }) + foreach (var cookie in new string?[] { null, Jar("not-a-token") }) { await host.StartAsync(provider: "google", cookieHeader: cookie); Assert.Equal("", Grant(host)); } + } - await host.StartAsync(provider: "google", cookieHeader: Jar(fresh)); + [Fact] + public async Task A_google_start_with_a_redeemed_invite_carries_no_grant() + { + using var host = new HeimdallHost(); + var (token, _) = await MintAsync(host); + using (var scope = host.Services.CreateScope()) + { + var db = scope.ServiceProvider.GetRequiredService(); + var hash = ChatInviteService.Hash(token); + (await db.ChatInvites.SingleAsync(x => x.TokenHash == hash)).RedeemedAtUtc = host.Clock.Now; + await db.SaveChangesAsync(); + } + + await host.StartAsync(provider: "google", cookieHeader: Jar(token)); + Assert.Equal("", Grant(host)); + } + + [Fact] + public async Task A_google_start_with_a_revoked_invite_carries_no_grant() + { + using var host = new HeimdallHost(); + var (token, id) = await MintAsync(host); + using (var scope = host.Services.CreateScope()) + { + Assert.True(await scope.ServiceProvider.GetRequiredService().RevokeAsync(id, Guid.NewGuid(), CancellationToken.None)); + } + + await host.StartAsync(provider: "google", cookieHeader: Jar(token)); + Assert.Equal("", Grant(host)); + } + + [Fact] + public async Task A_google_start_with_an_expired_invite_carries_no_grant() + { + using var host = new HeimdallHost(); + var (token, _) = await MintAsync(host); + await host.StartAsync(provider: "google", cookieHeader: Jar(token)); Assert.Equal("invite", Grant(host)); + + host.Clock.Advance(ChatInviteService.Lifetime + TimeSpan.FromMinutes(1)); + + await host.StartAsync(provider: "google", cookieHeader: Jar(token)); + Assert.Equal("", Grant(host)); + } + + [Fact] + public async Task A_link_or_proof_start_with_a_live_invite_held_sends_no_grant() + { + using var host = new HeimdallHost(); + var (token, _) = await MintAsync(host); + var cookies = new[] { new KeyValuePair(ChatInviteService.CookieName, token) }; + using var scope = host.Services.CreateScope(); + var service = scope.ServiceProvider.GetRequiredService(); + + foreach (var purpose in Enum.GetValues().Where(x => x != Bifrost.Web.Features.Heimdall.HeimdallAttemptPurpose.SignIn)) + { + var before = host.Heimdall.StartBodies.Count; + await service.StartAsync("google", "https://localhost", Bifrost.Web.Features.Shared.LocalReturnPath.Parse("/"), false, cookies, CancellationToken.None, purpose, Guid.NewGuid().ToString()); + Assert.Equal(before + 1, host.Heimdall.StartBodies.Count); + Assert.Equal("", Grant(host)); + } } [Fact]