Skip to content

feat(fapitest): add an embedder-style login UI, and follow nested types in the key-material guard - #1000

Merged
osanderson merged 6 commits into
mainfrom
test/key-guard-nested-and-login-helper
Nov 26, 2026
Merged

osanderson merged 6 commits into
mainfrom
test/key-guard-nested-and-login-helper

Conversation

@osanderson

Copy link
Copy Markdown
Collaborator

Two test-infrastructure follow-ups from the audit work. Only fapitest and the mutants file change, and nothing on the wire changes.

test: the key-material guard follows nested types

The guard in fapitest/key_rendering_guard_test.go flagged only fields that hold a key directly. #986 showed the gap: the federation issuers printed an Ed25519 key through their unexported deps field, a struct holding a Signer, and the guard didn't see it.

What the guard does now:

  • Nested types: a field counts as holding key material if its type reaches such a field. The guard follows pointers, slices, arrays, map values, channels, generic type arguments, inline structs and named types declared anywhere in the module, including internal/.
  • Cycles: a cycle stops at a type already being resolved, and only an outermost "no key material" result is cached, so a cycle cut short can't hide a holder found later.
  • Same rule as before: a field like this must be covered by a matrix case that renders the outer value, exactly as a direct holder must.

Fields it newly flagged, all now covered, none of them leaking:

  • the issuers' deps and their shadows' Dependencies;
  • keys.signerKeyManager.backends, and custodyKeyManager, which gets a new case;
  • ephemeral.KeyManager.keys and .decryption;
  • the client sealers' keys;
  • the interactioncookie and sessioncookie jars, which get a new case;
  • the new EmbedderUI.sealed.

Checks:

  • With the issuers' cover entries removed, the guard flags all ten issuer fields.
  • TestKeyMaterialIndexFollowsNestedTypes runs the detection on a small made-up package, including a cycle.
  • A field typed as an interface, such as keys.KeyManager, still can't be followed.

feat(fapitest): Harness.EmbedderUI, a model login and consent UI

(*Harness).EmbedderUI(EmbedderUIOptions) returns an http.Handler that serves an embedder-style UI over the harness's server, using only public APIs so an embedder can copy the pattern.

What it serves:

  • Sign-in: a POST that sets the UI's own session cookie.
  • Authorize: a GET that calls BeginAuthorization, seals the interaction with interactioncookie, and renders a consent page.
  • Consent: a POST that is refused (403) without a session the UI issued. Otherwise it completes the interaction for the signed-in subject and redirects to the client.

Defences on every page: the POSTs refuse cross-origin requests, and the pages carry server.AuthorizationPageHeaders.

The unsafe mode: keeping the raw handle in a plain cookie is reachable only through the explicit UnsafeRawHandleCookie option, and is meant for negative tests. The E-3 leak tests from #989 now use the helper, with their scenarios and assertions unchanged. #989's check still holds: with the cookie jar's AEAD check falling back to plaintext, the sealed-cookie test fails.

Tests of the helper:

  • completing the flow over TLS issues a code for the signed-in subject;
  • consent without a session, or with one the UI never issued, gets 403;
  • the handle is sealed by default, and kept raw only with the option.

Checks

  • Mutants: four new, all killed.
  • Suites: the race suite, every example module and the interop client pass, and lint is clean.

🤖 Generated with Claude Code

osanderson and others added 4 commits November 26, 2026 22:17
TestKeyHolderMatrixCoversEveryKeyField only looked at a field's own
type, so a field reaching key material through a struct it points to
went unseen: the federation issuers' deps field, a pointer to a
Dependencies struct holding the Signer, was not flagged, although its
rendering is what printed an Ed25519 key before the issuers gained
their redacting Format methods.

The guard now indexes the named types the guarded packages and
internal/ declare and counts a field as holding key material when its
type, through pointers, slices, arrays, map values, channels, generic
type arguments, inline structs and those named types, reaches a field
that holds it directly. Cycles end at a type already being resolved,
and only an outermost negative result is memoized, so a cycle cut
short cannot hide a holder found later. Such a field must be covered
by a keyHolders case rendering the value that holds it, like a direct
one.

The newly flagged fields are covered: the issuers' deps (and the
shadows their Format methods print), the signer and ephemeral key
managers' maps, the client sealers' keyrings, and new cases for a
KeyManager built with DeclareCustody and for the interactioncookie and
sessioncookie Cookies' jars. None of them prints its key.
TestKeyMaterialIndexFollowsNestedTypes checks the detection itself on
a synthetic package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The harness's authorization endpoint approves every interaction at
once, so a test of what an embedding application's UI does with the
interaction had to build that UI by hand.

Harness.EmbedderUI returns an http.Handler in front of the harness's
server: a sign-in that sets the UI's own session cookie, an
authorization endpoint that keeps the interaction in a cookie
server/interactioncookie seals and renders a consent page carrying its
tag, and a consent submission that completes the interaction for the
signed-in subject, granting what it requested, and answers 303 to the
client's redirect URI. A submission without a session the UI issued is
refused. Its POSTs refuse cross-origin requests and its pages carry
server.AuthorizationPageHeaders. It uses only the server's and
interactioncookie's public API, so an embedder can follow the pattern.

EmbedderUIOptions.OnInteraction hands a test each interaction begun,
as a leaked log line would, and UnsafeRawHandleCookie, for negative
tests only, keeps the raw handle in a plain cookie instead.

The UI holds its interaction cookie's key, so the key-material matrix
gains a case rendering one, and the redaction guard classifies the two
new types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The leak tests built their own embedder, with a plain-cookie and a
sealed-cookie bridge. They now use Harness.EmbedderUI, with
UnsafeRawHandleCookie for the plain cookie and OnInteraction for the
leaked handle, and sign the victim and the attacker in through its
sign-in. The scenarios and assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.07692% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fapitest/embedderui.go 83.07% 14 Missing and 8 partials ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@osanderson
osanderson merged commit 85f599b into main Nov 26, 2026
31 of 32 checks passed
@osanderson
osanderson deleted the test/key-guard-nested-and-login-helper branch November 26, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant