Desk: mask answerer ids for non-deciders where notes are already nilled

DeskNotes becomes DeskRedaction: one function over entry and list that nils
every note and replaces every answerer with the fixed sentinel "masked" for a
caller who is not a decider of the Mind (X3). A decider keeps both. The
sentinel is not derived from the account id and is not a UUID.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-11 17:44:38 +00:00
commit fb9fa6c91f
4 changed files with 61 additions and 16 deletions

View file

@ -183,14 +183,3 @@ public static class DeskUnavailables
"unavailable: the outcome is not confirmed, try again with the same request_id",
retryAfterSeconds);
}
// Notes are returned only to deciders. For everyone else Bifrost nils every note at the door: the key stays written
// (every key written, nil where absent), so the stripped body is still the contract's shape. Cards, outcomes, codes
// and counts are untouched; Huginn returns the full record.
public static class DeskNotes
{
public static ForkEntry Strip(ForkEntry entry) =>
entry with { Record = entry.Record with { Answers = [.. entry.Record.Answers.Select(a => a with { Note = null })] } };
public static ForkList Strip(ForkList list) => list with { Forks = [.. list.Forks.Select(Strip)] };
}

View file

@ -167,7 +167,7 @@ public static class DeskEndpoints
var listed = await door.ListAsync(mind.Socket, context, listRequest! with { Mind = mind.Id }, cancellationToken);
if (listed is DeskListOutcome.Listed(var list))
{
await WriteJsonAsync(http, 200, IsDecider(context) ? list : DeskNotes.Strip(list));
await WriteJsonAsync(http, 200, IsDecider(context) ? list : DeskRedaction.ForNonDecider(list));
}
else if (listed is DeskListOutcome.ForkTooLarge(var largeId, var largeOrder))
{
@ -187,7 +187,7 @@ public static class DeskEndpoints
var found = await door.ReadAsync(mind.Socket, context, forkId, cancellationToken);
if (found is DeskReadOutcome.Found(var entry))
{
await WriteJsonAsync(http, 200, IsDecider(context) ? entry : DeskNotes.Strip(entry));
await WriteJsonAsync(http, 200, IsDecider(context) ? entry : DeskRedaction.ForNonDecider(entry));
}
else if (found is DeskReadOutcome.ForkTooLarge(var largeFork))
{
@ -253,7 +253,8 @@ public static class DeskEndpoints
}
}
// A note is a decider's own words: only a caller on the admin-set list reads them (visibility ruling c).
// 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).
private static bool IsDecider(DeskDoorContext context) =>
context.Deciders.Contains(context.Subject, StringComparer.Ordinal);

View file

@ -0,0 +1,25 @@
namespace Bifrost.Web.Features.Desk;
// What a caller who is not a decider of the Mind does not read, taken out at the door and nowhere else. For them
// every note is nil and every answerer is the sentinel; every key stays written (nil where absent, a string where a
// string is required), so the redacted body is still the contract's shape. Cards, outcomes, codes, counts and the
// number of answers are untouched; Huginn returns the full record and Bifrost drops and adds nothing.
//
// The sentinel is one fixed string for every answer: nothing derived from an account id (a hash or a per-reader
// alias would still let a reader link two answers to one person, or confirm a guess), and it is not a D-format
// UUID, so it cannot be mistaken for an account. The contract's `answerer` is a non-empty string and nothing more.
public static class DeskRedaction
{
public const string MaskedAnswerer = "masked";
public static ForkEntry ForNonDecider(ForkEntry entry) =>
entry with
{
Record = entry.Record with
{
Answers = [.. entry.Record.Answers.Select(a => a with { Note = null, Answerer = MaskedAnswerer })],
},
};
public static ForkList ForNonDecider(ForkList list) => list with { Forks = [.. list.Forks.Select(ForNonDecider)] };
}

View file

@ -374,7 +374,13 @@ public sealed class DeskReadTests
private static DeskAnswerDocument Doc(string id, string outcome, string? of, string? retracts, string? note) => new(
DeskSchemas.DeskAnswer, id, DeskReplay.ChatFork, outcome, of, retracts, null, "h", note == null ? null : "a", note,
"2026-11-12T19:00:00Z", "2026-11-12T19:00:01Z", false, DeskWebApplicationFactory.Alice, "Steward", "r-" + id);
"2026-11-12T19:00:00Z", "2026-11-12T19:00:01Z", false, AnswererOf(id), "Steward", "r-" + id);
// Four different accounts, so a mask that kept any one of them, or told two apart, is seen.
private static readonly string[] Answerers =
[DeskWebApplicationFactory.Alice, DeskWebApplicationFactory.Steward, DeskWebApplicationFactory.Member, "0badc0de-0000-4000-8000-00000000000d"];
private static string AnswererOf(string answerId) => Answerers[int.Parse(answerId[1..]) - 1];
// Counted, Revision, Retraction and Refused documents, every one carrying the decider's note.
private static ForkEntry NotedEntry()
@ -424,10 +430,17 @@ public sealed class DeskReadTests
Assert.DoesNotContain("decider's own words", list);
Assert.False(AnyNote(JsonNode.Parse(read)));
Assert.False(AnyNote(JsonNode.Parse(list)));
// No answerer id of any answer reaches a non-decider, and every answer says the same thing instead.
var readMasked = JsonNode.Parse(read)!["record"]!["answers"]!.AsArray().Select(a => (string?)a!["answerer"]);
Assert.Equal(4, readMasked.Count());
Assert.All(readMasked, answerer => Assert.Equal("masked", answerer));
var masked = JsonNode.Parse(list)!["forks"]!.AsArray().SelectMany(f => f!["record"]!["answers"]!.AsArray()).Select(a => (string?)a!["answerer"]);
Assert.Equal(8, masked.Count());
Assert.All(masked, answerer => Assert.Equal("masked", answerer));
// Outcomes and cards stay; the key stays written as nil, so the body is still the contract's shape.
var expected = JsonSerializer.SerializeToNode(NotedEntry() with
{
Record = NotedEntry().Record with { Answers = [.. NotedEntry().Record.Answers.Select(a => a with { Note = null })] },
Record = NotedEntry().Record with { Answers = [.. NotedEntry().Record.Answers.Select(a => a with { Note = null, Answerer = DeskRedaction.MaskedAnswerer })] },
}, DeskJson.Options);
Assert.True(DeskVectors.SameShape(JsonNode.Parse(read), expected));
var answers = JsonNode.Parse(read)!["record"]!["answers"]!.AsArray();
@ -436,6 +449,22 @@ public sealed class DeskReadTests
Assert.Equal(2, JsonNode.Parse(list)!["forks"]!.AsArray().Count);
}
[Fact]
public async Task Bifrost_relays_exactly_the_entries_the_door_returns_to_any_reader()
{
using var factory = new DeskWebApplicationFactory();
await factory.EnsureAccountAsync(DeskWebApplicationFactory.Member, true);
await factory.EnsureAccountAsync(DeskWebApplicationFactory.Alice, true);
var forks = Enumerable.Range(1, 7).Select(i => DeskReplay.Entry(DeskReplay.Card("gamecult-chat:question:q" + i))).ToArray();
factory.Door.ListScript = (_, r) => new DeskListOutcome.Listed(new ForkList("gamecult.fork.list.v0", r.Mind, "s1", 7, 0, forks, null));
foreach (var account in new[] { DeskWebApplicationFactory.Member, DeskWebApplicationFactory.Alice })
{
var reply = await factory.SendAsync("GET", "/api/desk/gamecult-chat/forks", null, factory.Token(account, "bifrost-desk", "desk.read"));
Assert.Equal(forks.Select(f => f.Card.ForkId), JsonNode.Parse(reply.Body)!["forks"]!.AsArray().Select(f => (string?)f!["card"]!["fork_id"]));
}
}
[Fact]
public async Task A_decider_reads_and_lists_the_notes()
{
@ -445,6 +474,7 @@ public sealed class DeskReadTests
var (read, list) = await BodiesAsync(factory, DeskWebApplicationFactory.Alice);
Assert.Contains(Secret + " 3", read);
Assert.Equal(Answerers, JsonNode.Parse(read)!["record"]!["answers"]!.AsArray().Select(a => (string?)a!["answerer"]));
Assert.Equal(8, JsonNode.Parse(list)!["forks"]!.AsArray().Sum(f => f!["record"]!["answers"]!.AsArray().Count(a => a!["note"] is not null)));
Assert.True(DeskVectors.SameShape(JsonNode.Parse(read), JsonSerializer.SerializeToNode(NotedEntry(), DeskJson.Options)));
}