From 59f0915c03350d1ac23a00213cf691c0c52090e8 Mon Sep 17 00:00:00 2001 From: Heimdall Date: Thu, 12 Nov 2026 10:17:21 +0000 Subject: [PATCH] Desk credential: only an all-desk-scope token skips the consent receipt; comment says the door withholds ids Co-Authored-By: Claude Sonnet 5.5 --- src/Bifrost.Web/Features/Desk/DeskEndpoints.cs | 4 ++-- src/Bifrost.Web/Features/Oidc/OidcEndpoints.cs | 3 ++- tests/Bifrost.Web.Tests/DeskCredentialTests.cs | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Bifrost.Web/Features/Desk/DeskEndpoints.cs b/src/Bifrost.Web/Features/Desk/DeskEndpoints.cs index 3c275ce..2108840 100644 --- a/src/Bifrost.Web/Features/Desk/DeskEndpoints.cs +++ b/src/Bifrost.Web/Features/Desk/DeskEndpoints.cs @@ -275,8 +275,8 @@ public static class DeskEndpoints } } - // A note is a decider's own words, and an answerer id names an account: only a caller on the admin-set list reads - // either (visibility ruling c; X3). + // A note is a decider's own words: only a caller on the admin-set list reads one. Bifrost strips notes itself; answerer + // and decider ids are withheld by Huginn's door (desk-read-visibility-withheld-ids), not here. private static bool IsDecider(DeskDoorContext context) => context.Deciders.Contains(context.Subject, StringComparer.Ordinal); diff --git a/src/Bifrost.Web/Features/Oidc/OidcEndpoints.cs b/src/Bifrost.Web/Features/Oidc/OidcEndpoints.cs index 782f5f2..a789882 100644 --- a/src/Bifrost.Web/Features/Oidc/OidcEndpoints.cs +++ b/src/Bifrost.Web/Features/Oidc/OidcEndpoints.cs @@ -114,7 +114,8 @@ public static class OidcEndpoints } /// A token whose scopes include a desk scope is a desk token. Only the chat token requires the training-notice receipt. - private static bool IsDeskToken(ClaimsPrincipal? principal) => principal is not null && principal.GetScopes().Any(DeskEndpoints.IsDeskScope); + // Only a token whose every scope is a desk scope skips the consent gate: a client that may hold chat scopes too cannot ride a desk scope past the receipt. + private static bool IsDeskToken(ClaimsPrincipal? principal) => principal is not null && principal.GetScopes() is { Length: > 0 } scopes && scopes.All(DeskEndpoints.IsDeskScope); private static async Task ExchangeAsync(HttpContext http, BifrostDbContext db) { diff --git a/tests/Bifrost.Web.Tests/DeskCredentialTests.cs b/tests/Bifrost.Web.Tests/DeskCredentialTests.cs index f6205e4..8a10318 100644 --- a/tests/Bifrost.Web.Tests/DeskCredentialTests.cs +++ b/tests/Bifrost.Web.Tests/DeskCredentialTests.cs @@ -160,6 +160,18 @@ public sealed class DeskCredentialTests : IDisposable Assert.False(string.IsNullOrEmpty(await ExchangeAsync(client, later, laterCode, DeskClient, DeskSecret))); } + [Fact] + public async Task A_desk_scope_mixed_with_a_chat_scope_does_not_skip_the_training_notice_receipt() + { + var (client, identity) = await SignedInAsync(); + await RemoveReceiptsAsync(identity, withdrawOnly: false); + + var mixed = NewRequest(DeskClient, DeskRedirect, "openid desk.read"); + var final = await DriveAsync(client, mixed); + Assert.Equal(HttpStatusCode.Redirect, final.StatusCode); + Assert.DoesNotContain("code=", final.Headers.Location!.OriginalString); + } + [Fact] public async Task The_chat_client_can_neither_ask_for_a_desk_scope_nor_use_its_own_token_on_the_desk() { @@ -337,6 +349,7 @@ public sealed class DeskCredentialTests : IDisposable Permissions.Endpoints.Token, Permissions.GrantTypes.AuthorizationCode, Permissions.ResponseTypes.Code, + Permissions.Prefixes.Scope + Scopes.OpenId, Permissions.Prefixes.Scope + DeskEndpoints.ReadScope, Permissions.Prefixes.Scope + DeskEndpoints.AnswerScope, Permissions.Prefixes.Scope + DeskWebApplicationFactory.OtherAudienceScope,