Audit events never carry a completion code
Soul pass 5, S5-3: auth_completion_created stored completion.code, which the unauthenticated redeem route turns into the session until it expires (300 s by default), so the audit trail could redeem a live sign-in. The two auth_completion_redeemed events (the HTTP redeem route and the private command plane's redeem by attempt) stored the spent code as well. All three payloads drop it. Nothing reads audit payloads back: the store has no audit read, and no repository indexed by VoidBot consumes these events. The event's sessionId already names the completion (one per callback), so no replacement key is added. This matches Heimdall's own witness contract, which says codes are redacted from audit exports. Tests drive a sign-in through the HTTP redeem route and through the plane, pin each payload exactly, and check the code appears in no audit event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
731ce08cfa
commit
963150f537
4 changed files with 69 additions and 3 deletions
|
|
@ -1304,10 +1304,12 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
|
|||
sessionId: issued.session.sessionId,
|
||||
appSlug: statePayload.app_slug,
|
||||
eventType: "auth_completion_created",
|
||||
// Never the completion code: until it expires, the unauthenticated
|
||||
// redeem route turns it into the session. The event's sessionId
|
||||
// already names the completion, one per callback.
|
||||
eventPayloadJson: {
|
||||
provider: request.params.provider,
|
||||
mode: statePayload.mode,
|
||||
completionCode: completion.code,
|
||||
expiresAt: completion.expiresAt,
|
||||
},
|
||||
createdAt: nowIso,
|
||||
|
|
@ -1449,7 +1451,6 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
|
|||
eventPayloadJson: {
|
||||
provider: completion.provider,
|
||||
mode: completion.mode,
|
||||
completionCode: completion.code,
|
||||
},
|
||||
createdAt: nowIso,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -357,7 +357,6 @@ async function completeAuth(
|
|||
eventPayloadJson: {
|
||||
provider: completion.provider,
|
||||
mode: completion.mode,
|
||||
completionCode: completion.code,
|
||||
},
|
||||
createdAt: now,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -717,6 +717,33 @@ describe("Heimdall service", () => {
|
|||
expect(secondRedeemResponse.statusCode).toBe(410);
|
||||
});
|
||||
|
||||
it("keeps the completion code out of the audit trail, live or redeemed", async () => {
|
||||
const store = new InMemoryStore();
|
||||
const app = await buildApp({ config: createTestConfig(), store, oauthRuntimes: { discord: createMockDiscordRuntime() } });
|
||||
apps.push(app);
|
||||
const auditEvents = () =>
|
||||
[...(store as unknown as { auditEvents: Map<string, { eventType: string; sessionId?: string; eventPayloadJson: unknown }> }).auditEvents.values()];
|
||||
|
||||
const stateToken = await startDiscordSignIn(app);
|
||||
const callback = await app.inject({
|
||||
method: "GET",
|
||||
url: `/v1/oauth/discord/callback?code=test-code&state=${encodeURIComponent(stateToken)}`,
|
||||
});
|
||||
const { code, expiresAt } = callback.json().completion as { code: string; expiresAt: string };
|
||||
const created = auditEvents().filter((event) => event.eventType === "auth_completion_created");
|
||||
expect(created.map((event) => event.eventPayloadJson)).toEqual([{ provider: "discord", mode: "sign_in", expiresAt }]);
|
||||
expect(created[0]!.sessionId).toEqual(expect.any(String));
|
||||
// While the code is live, the audit trail must not be a way to redeem it.
|
||||
expect(JSON.stringify(auditEvents())).not.toContain(code);
|
||||
|
||||
const redeem = await app.inject({ method: "POST", url: "/v1/apps/repixelizer/auth-completions/redeem", payload: { completionCode: code } });
|
||||
expect(redeem.statusCode).toBe(201);
|
||||
const redeemed = auditEvents().filter((event) => event.eventType === "auth_completion_redeemed");
|
||||
expect(redeemed.map((event) => event.eventPayloadJson)).toEqual([{ provider: "discord", mode: "sign_in" }]);
|
||||
expect(redeemed[0]!.sessionId).toBe(created[0]!.sessionId);
|
||||
expect(JSON.stringify(auditEvents())).not.toContain(code);
|
||||
});
|
||||
|
||||
it("refreshes a Repixelizer app claim from a Heimdall refresh token without provider OAuth", async () => {
|
||||
const store = new InMemoryStore();
|
||||
let exchangeCalls = 0;
|
||||
|
|
|
|||
|
|
@ -109,3 +109,42 @@ it("keeps a provider's refusal body out of every plaintext part of the reply", a
|
|||
expect(reply.diagnostics).toEqual(["Heimdall denied the private command (ProviderResponseError, provider_status)."]);
|
||||
expect(plaintext(reply)).not.toContain("CANARY");
|
||||
});
|
||||
|
||||
it("keeps the completion code out of the audit trail when the plane redeems by attempt", async () => {
|
||||
vi.stubGlobal("fetch", async (url: string | URL) => {
|
||||
const u = String(url);
|
||||
if (u.endsWith("/oauth2/token")) {
|
||||
return new Response(
|
||||
JSON.stringify({ access_token: "a", refresh_token: "r", token_type: "Bearer", expires_in: 60, scope: "identify" }),
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
if (u.endsWith("/users/@me")) return new Response(JSON.stringify({ id: "u1", username: "u1" }), { status: 200 });
|
||||
if (u.includes("/member")) return new Response(JSON.stringify({ roles: ["r"] }), { status: 200 });
|
||||
return new Response("{}", { status: 404 });
|
||||
});
|
||||
const cfg = config();
|
||||
const store = new InMemoryStore();
|
||||
const app = await buildApp({ config: cfg, store });
|
||||
resources.push(app);
|
||||
const plane = await startHeimdallPrivateCommandPlane(app, cfg);
|
||||
resources.push(plane);
|
||||
const policy = { kind: "discord_role_access", guildId: "g", allowedRoleIds: ["r"] };
|
||||
const begin = open(await command(plane.endpoint, "heimdall.auth.begin", "heimdall.auth_begin_command.v1", "k1",
|
||||
{ provider: "discord", mode: "sign_in", returnTo: "https://yggdrasil.gamecult.org/ghostlight/", entitlementPolicy: policy }));
|
||||
const state = new URL(String((begin.navigation as { url: string }).url)).searchParams.get("state")!;
|
||||
const callback = await app.inject({
|
||||
method: "GET",
|
||||
url: `/v1/oauth/discord/callback?code=c1&state=${encodeURIComponent(state)}`,
|
||||
headers: { accept: "application/json" },
|
||||
});
|
||||
const code = (callback.json().completion as { code: string }).code;
|
||||
const done = open(await command(plane.endpoint, "heimdall.auth.complete", "heimdall.auth_complete_command.v1", "k2", { handle: begin.handle }));
|
||||
expect(done.status).toBe("authenticated");
|
||||
|
||||
const events = [...(store as unknown as { auditEvents: Map<string, { eventType: string; eventPayloadJson: unknown }> }).auditEvents.values()];
|
||||
expect(events.filter((event) => event.eventType === "auth_completion_redeemed").map((event) => event.eventPayloadJson)).toEqual([
|
||||
{ provider: "discord", mode: "sign_in" },
|
||||
]);
|
||||
expect(JSON.stringify(events)).not.toContain(code);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue