oficina / home Public

Record ID guard mutations and preserve authentication proof times

Paul Campbell pushed by paul@keymail.dev 2f9862e76bbeba4621c4952ca4fe46e2f11cc9e7 parent d4506ad
10 files changed, +953 −100
  • implementation/oficina-id-slice1-mutations.json +644 −0
  • implementation/oficina-id-slice1-validation.md +20 −0
  • internal/home/assertion_intent.go +3 −0
  • internal/home/id_exchange_test.go +85 −0
  • internal/home/id_recovery.go +6 −16
  • internal/home/id_recovery_test.go +45 −2
  • internal/home/passkey.go +14 −54
  • internal/home/signin.go +6 −2
  • internal/home/signout.go +5 −26
  • scripts/check-id-mutations.py +125 −0

CI failed — run details

diff --git a/implementation/oficina-id-slice1-mutations.json b/implementation/oficina-id-slice1-mutations.json
new file mode 100644
index 0000000..254cd92
--- /dev/null
+++ b/implementation/oficina-id-slice1-mutations.json
@@ -0,0 +1,644 @@
+[
+ {
+ "guard": "continue gesture",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDContinueBeforeMinting",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDContinueBeforeMinting (0.26s)"
+ ],
+ "seconds": 1.95
+ },
+ {
+ "guard": "link new session",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDLinkAlwaysRequiresNewGesture",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDLinkAlwaysRequiresNewGesture (0.27s)"
+ ],
+ "seconds": 1.99
+ },
+ {
+ "guard": "link transaction start",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDLinkRejectsProofBeforeTransactionStart",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDLinkRejectsProofBeforeTransactionStart (0.29s)"
+ ],
+ "seconds": 1.97
+ },
+ {
+ "guard": "passive Keymail issuance",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDLinkRejectsPassiveMintedSession",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDLinkRejectsPassiveMintedSession (0.29s)"
+ ],
+ "seconds": 2.12
+ },
+ {
+ "guard": "live issuance session",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDRevokedCachedSessionCannotMint",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRevokedCachedSessionCannotMint (0.42s)"
+ ],
+ "seconds": 2.15
+ },
+ {
+ "guard": "audience",
+ "file": "internal/home/exchange.go",
+ "test": "TestHomeDirectoryExchangeAndPrivacy",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestHomeDirectoryExchangeAndPrivacy (0.28s)"
+ ],
+ "seconds": 2.15
+ },
+ {
+ "guard": "nonce",
+ "file": "internal/home/exchange.go",
+ "test": "TestHomeDirectoryExchangeAndPrivacy",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestHomeDirectoryExchangeAndPrivacy (0.27s)"
+ ],
+ "seconds": 2.0
+ },
+ {
+ "guard": "assertion lifetime",
+ "file": "internal/home/exchange.go",
+ "test": "TestHomeDirectoryExchangeAndPrivacy",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestHomeDirectoryExchangeAndPrivacy (0.30s)"
+ ],
+ "seconds": 2.08
+ },
+ {
+ "guard": "cookie ambiguity",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDChallengeBrowserCookiesAndExpiry/duplicate",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry (0.15s)",
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry/duplicate (0.15s)"
+ ],
+ "seconds": 1.87
+ },
+ {
+ "guard": "clock rollback",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDChallengeBrowserCookiesAndExpiry/clock",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry (0.16s)",
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry/clock (0.16s)"
+ ],
+ "seconds": 1.89
+ },
+ {
+ "guard": "future enrollment time",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDEnrollmentRejectsFutureAndPassiveAuthentication/future",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDEnrollmentRejectsFutureAndPassiveAuthentication (0.14s)",
+ "--- FAIL: TestIDEnrollmentRejectsFutureAndPassiveAuthentication/future (0.14s)"
+ ],
+ "seconds": 1.94
+ },
+ {
+ "guard": "passive enrollment",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDEnrollmentRejectsFutureAndPassiveAuthentication/passive",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDEnrollmentRejectsFutureAndPassiveAuthentication (0.14s)",
+ "--- FAIL: TestIDEnrollmentRejectsFutureAndPassiveAuthentication/passive (0.14s)"
+ ],
+ "seconds": 1.84
+ },
+ {
+ "guard": "challenge capacity",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDChallengeBrowserCookiesAndExpiry/capacity",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry (0.20s)",
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry/capacity (0.20s)"
+ ],
+ "seconds": 1.94
+ },
+ {
+ "guard": "challenge lifetime",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDChallengeBrowserCookiesAndExpiry/ttl",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry (0.14s)",
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry/ttl (0.14s)"
+ ],
+ "seconds": 1.82
+ },
+ {
+ "guard": "challenge browser",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDChallengeBrowserCookiesAndExpiry/other-browser",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry (0.16s)",
+ "--- FAIL: TestIDChallengeBrowserCookiesAndExpiry/other-browser (0.16s)"
+ ],
+ "seconds": 1.89
+ },
+ {
+ "guard": "challenge subject",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDRegistrationChallengeSubjectAndLiveSession/subject",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRegistrationChallengeSubjectAndLiveSession (0.15s)",
+ "--- FAIL: TestIDRegistrationChallengeSubjectAndLiveSession/subject (0.15s)"
+ ],
+ "seconds": 1.94
+ },
+ {
+ "guard": "challenge purpose",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDPasskeyRejectsBadProofs/purpose",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDPasskeyRejectsBadProofs (0.15s)",
+ "--- FAIL: TestIDPasskeyRejectsBadProofs/purpose (0.15s)"
+ ],
+ "seconds": 1.88
+ },
+ {
+ "guard": "challenge expiry",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDPasskeyRejectsBadProofs/expired",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDPasskeyRejectsBadProofs (0.16s)",
+ "--- FAIL: TestIDPasskeyRejectsBadProofs/expired (0.16s)"
+ ],
+ "seconds": 1.91
+ },
+ {
+ "guard": "challenge single use",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDDirectPasskey",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDDirectPasskey (0.16s)"
+ ],
+ "seconds": 1.95
+ },
+ {
+ "guard": "strict ceremony JSON",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDCeremonyRejectsAmbiguousJSON",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDCeremonyRejectsAmbiguousJSON (0.31s)",
+ "--- FAIL: TestIDCeremonyRejectsAmbiguousJSON/trailing (0.15s)",
+ "--- FAIL: TestIDCeremonyRejectsAmbiguousJSON/duplicate (0.16s)"
+ ],
+ "seconds": 2.15
+ },
+ {
+ "guard": "credential collision",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDEnrollmentCannotTransferCredential",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDEnrollmentCannotTransferCredential (0.17s)"
+ ],
+ "seconds": 1.95
+ },
+ {
+ "guard": "credential enrollment bound",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDEnrollmentBound",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDEnrollmentBound (0.65s)"
+ ],
+ "seconds": 2.48
+ },
+ {
+ "guard": "credential owner",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDGateBindsCredentialOwner",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDGateBindsCredentialOwner (0.20s)"
+ ],
+ "seconds": 1.96
+ },
+ {
+ "guard": "discoverable admission",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDLegacyCredentialCannotSignInDirectly",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDLegacyCredentialCannotSignInDirectly (0.16s)"
+ ],
+ "seconds": 2.01
+ },
+ {
+ "guard": "WebAuthn verification",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDPasskeyRejectsBadProofs/(origin|rp|uv|signature)",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDPasskeyRejectsBadProofs (0.73s)",
+ "--- FAIL: TestIDPasskeyRejectsBadProofs/origin (0.15s)",
+ "--- FAIL: TestIDPasskeyRejectsBadProofs/rp (0.15s)",
+ "--- FAIL: TestIDPasskeyRejectsBadProofs/uv (0.14s)",
+ "--- FAIL: TestIDPasskeyRejectsBadProofs/signature (0.15s)"
+ ],
+ "seconds": 2.53
+ },
+ {
+ "guard": "recovery entropy",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryEntropy",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryEntropy (0.16s)"
+ ],
+ "seconds": 1.96
+ },
+ {
+ "guard": "account attempt budget",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryAttemptLimitSurvivesReconstruction",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryAttemptLimitSurvivesReconstruction (0.33s)"
+ ],
+ "seconds": 2.39
+ },
+ {
+ "guard": "IP attempt budget",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryIPLimitAcrossAccounts",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryIPLimitAcrossAccounts (0.80s)"
+ ],
+ "seconds": 3.08
+ },
+ {
+ "guard": "attempt increment",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryAttemptLimitSurvivesReconstruction",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryAttemptLimitSurvivesReconstruction (0.23s)"
+ ],
+ "seconds": 1.97
+ },
+ {
+ "guard": "attempt persistence",
+ "file": "internal/home/app.go",
+ "test": "TestIDRecoveryAttemptLimitSurvivesReconstruction",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryAttemptLimitSurvivesReconstruction (0.26s)"
+ ],
+ "seconds": 1.97
+ },
+ {
+ "guard": "mailbox freshness",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryRequiresFreshMailboxGesture",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryRequiresFreshMailboxGesture (0.17s)"
+ ],
+ "seconds": 1.83
+ },
+ {
+ "guard": "recovery code person",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryCodePersonBindingAndReplay",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryCodePersonBindingAndReplay (0.28s)"
+ ],
+ "seconds": 2.09
+ },
+ {
+ "guard": "recovery code single use",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryCodePersonBindingAndReplay",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryCodePersonBindingAndReplay (0.39s)"
+ ],
+ "seconds": 2.09
+ },
+ {
+ "guard": "recovery proof expiry",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDReplacementProofBinding/expired",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDReplacementProofBinding (0.26s)",
+ "--- FAIL: TestIDReplacementProofBinding/expired (0.26s)"
+ ],
+ "seconds": 2.02
+ },
+ {
+ "guard": "recovery proof capacity",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryProofCapacity",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryProofCapacity (0.32s)"
+ ],
+ "seconds": 2.09
+ },
+ {
+ "guard": "mailbox memory capacity",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDMailboxMemoryBoundAndExpiry",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDMailboxMemoryBoundAndExpiry (0.00s)"
+ ],
+ "seconds": 1.75
+ },
+ {
+ "guard": "mailbox memory expiry",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDMailboxMemoryBoundAndExpiry",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDMailboxMemoryBoundAndExpiry (0.00s)"
+ ],
+ "seconds": 1.73
+ },
+ {
+ "guard": "notice outcome",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDNoticeFailureSurvivesRestartWithoutAddress",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDNoticeFailureSurvivesRestartWithoutAddress (0.29s)"
+ ],
+ "seconds": 2.07
+ },
+ {
+ "guard": "SMTP log privacy",
+ "file": "internal/home/signin.go",
+ "test": "TestIDSMTPFailureDoesNotLeak",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDSMTPFailureDoesNotLeak (0.17s)"
+ ],
+ "seconds": 2.11
+ },
+ {
+ "guard": "limiter address blinding",
+ "file": "internal/home/id_limiter.go",
+ "test": "TestIDSigninLimiterUsesBlindedAddress",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDSigninLimiterUsesBlindedAddress (0.16s)"
+ ],
+ "seconds": 2.44
+ },
+ {
+ "guard": "local signout",
+ "file": "internal/home/directory.go",
+ "test": "TestIDLocalSignoutWithHangingIssuer",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDLocalSignoutWithHangingIssuer (0.45s)"
+ ],
+ "seconds": 2.19
+ },
+ {
+ "guard": "sealed link storage",
+ "file": "internal/home/links.go",
+ "test": "TestFullSigninLeavesNoReadableAddress",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestFullSigninLeavesNoReadableAddress (0.18s)"
+ ],
+ "seconds": 2.01
+ },
+ {
+ "guard": "closed authorize fields",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDClosedAuthorize",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDClosedAuthorize (0.38s)"
+ ],
+ "seconds": 2.15
+ },
+ {
+ "guard": "authorize consumer uniqueness",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDClosedAuthorize",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDClosedAuthorize (0.36s)"
+ ],
+ "seconds": 2.14
+ },
+ {
+ "guard": "authorize nonce uniqueness",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDClosedAuthorize",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDClosedAuthorize (0.35s)"
+ ],
+ "seconds": 2.09
+ },
+ {
+ "guard": "CSRF for sensitive posts",
+ "file": "internal/home/app.go",
+ "test": "TestIDAllSensitivePostsRequireOrigin",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDAllSensitivePostsRequireOrigin (0.37s)"
+ ],
+ "seconds": 2.46
+ },
+ {
+ "guard": "replacement revokes sessions",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.34s)"
+ ],
+ "seconds": 2.16
+ },
+ {
+ "guard": "replacement revokes passkey_credentials",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.30s)"
+ ],
+ "seconds": 2.11
+ },
+ {
+ "guard": "replacement revokes passkey_recovery_codes",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.31s)"
+ ],
+ "seconds": 2.21
+ },
+ {
+ "guard": "replacement revokes passkey_pending",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.34s)"
+ ],
+ "seconds": 2.2
+ },
+ {
+ "guard": "replacement revokes passkey_challenges",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.34s)"
+ ],
+ "seconds": 2.05
+ },
+ {
+ "guard": "replacement revokes home_id_ceremonies",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.36s)"
+ ],
+ "seconds": 2.21
+ },
+ {
+ "guard": "replacement revokes home_id_recovery_proofs",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDRecoveryReplacementRevokesEverything",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDRecoveryReplacementRevokesEverything (0.31s)"
+ ],
+ "seconds": 2.08
+ },
+ {
+ "guard": "recovery proof subject",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDReplacementProofBinding/wrong-person",
+ "result": "survived",
+ "failures": [],
+ "seconds": 2.04,
+ "explanation": "Independent in-memory mailbox subject check still refuses. The paired mutation removes both checks and must fail the same regression."
+ },
+ {
+ "guard": "recovery subject defenses together",
+ "file": "internal/home/id_recovery.go",
+ "test": "TestIDReplacementProofBinding/wrong-person",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDReplacementProofBinding (0.20s)",
+ "--- FAIL: TestIDReplacementProofBinding/wrong-person (0.20s)"
+ ],
+ "seconds": 1.98
+ },
+ {
+ "guard": "registered authorize consumer",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDClosedAuthorize",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDClosedAuthorize (0.26s)"
+ ],
+ "seconds": 2.01
+ },
+ {
+ "guard": "authorize nonce format",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDClosedAuthorize",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDClosedAuthorize (0.26s)"
+ ],
+ "seconds": 2.01
+ },
+ {
+ "guard": "authorize max age",
+ "file": "internal/home/exchange.go",
+ "test": "TestIDClosedAuthorize",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDClosedAuthorize (0.24s)"
+ ],
+ "seconds": 1.97
+ },
+ {
+ "guard": "replacement rollback",
+ "file": "internal/home/id_passkey.go",
+ "test": "TestIDReplacementRollback",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDReplacementRollback (1.12s)",
+ "--- FAIL: TestIDReplacementRollback/sessionsDELETE (0.19s)",
+ "--- FAIL: TestIDReplacementRollback/passkey_recovery_codesDELETE (0.19s)",
+ "--- FAIL: TestIDReplacementRollback/home_id_recovery_proofsDELETE (0.19s)",
+ "--- FAIL: TestIDReplacementRollback/passkey_credentialsINSERT (0.18s)",
+ "--- FAIL: TestIDReplacementRollback/home_id_discoverableINSERT (0.19s)"
+ ],
+ "seconds": 2.87
+ },
+ {
+ "guard": "email authentication time",
+ "file": "internal/home/signin.go",
+ "test": "TestIDEmailMintPreservesVerificationTime",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDEmailMintPreservesVerificationTime (0.13s)"
+ ],
+ "seconds": 1.84
+ },
+ {
+ "guard": "codes after enrollment",
+ "file": "internal/home/passkey.go",
+ "test": "TestIDCodesRequireEnrolledPasskey",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDCodesRequireEnrolledPasskey (0.14s)"
+ ],
+ "seconds": 1.98
+ },
+ {
+ "guard": "fresh intent start provenance",
+ "file": "internal/home/assertion_intent.go",
+ "test": "TestIDFreshIntentRequiresStartTime",
+ "result": "killed",
+ "failures": [
+ "--- FAIL: TestIDFreshIntentRequiresStartTime (0.29s)"
+ ],
+ "seconds": 2.12
+ }
+]
diff --git a/implementation/oficina-id-slice1-validation.md b/implementation/oficina-id-slice1-validation.md
index 5b2ef78..0cf67f9 100644
--- a/implementation/oficina-id-slice1-validation.md
+++ b/implementation/oficina-id-slice1-validation.md
@@ -57,3 +57,23 @@ Pending.
and GET minting). Fixtures now reauthenticate the original identity and POST
Continue; operator fixtures have explicit larger mail budgets for repeated
independent test ceremonies. Production mail limits are unchanged.
+
+## Mutation result
+
+`scripts/check-id-mutations.py` ran 62 guard-removal checks. 61 were killed by
+behavioral regressions. Removing only the SQL recovery-subject predicate
+survived because the independent mailbox subject check still refused the proof;
+removing both checks was killed. The JSON record names every guard, test and
+result. This is a recorded redundant defense, not a claim of zero survivors.
+
+The checks include every replacement revocation table, rollback, WebAuthn
+origin/RP/UV/signature rejection, replay, challenge and cookie binding, limits,
+expiry, clock rollback, entropy, mail/limiter/storage privacy, Continue/CSRF,
+closed authorize parsing, audience, nonce, lifetime and authentication-time
+provenance. Original source was restored after each check.
+
+Additional red/green tests reject old fresh-intent cookies without a start time,
+preserve email verification time rather than session-mint time, and require an
+enrolled passkey before issuing codes. Recovery proofs have a hard row bound.
+Hosted CI's race pass found two concurrent ResponseRecorder.Result calls in
+fixtures; cookie snapshots now precede the goroutines. Targeted race tests pass.
diff --git a/internal/home/assertion_intent.go b/internal/home/assertion_intent.go
index f2eaab3..79d1b26 100644
--- a/internal/home/assertion_intent.go
+++ b/internal/home/assertion_intent.go
@@ -34,5 +34,8 @@ func (a *App) readAssertionIntent(r *http.Request, now time.Time) (assertionInte
if json.Unmarshal(plain, &intent, json.RejectUnknownMembers(true)) != nil || intent.Expires <= now.Unix() || intent.Expires > now.Unix()+600 || !handoff.ValidNonce(intent.Nonce) || (intent.MaxAge != 0 && intent.MaxAge != 300) || (intent.MaxAge == 0 && intent.Subject != "") {
return assertionIntent{}, false
}
+ if intent.MaxAge != 0 && intent.Consumer != operatorConfirmConsumer && (intent.Started <= 0 || intent.Started > now.Unix()) {
+ return assertionIntent{}, false
+ }
return intent, true
}
diff --git a/internal/home/id_exchange_test.go b/internal/home/id_exchange_test.go
index c1dfe88..f201db2 100644
--- a/internal/home/id_exchange_test.go
+++ b/internal/home/id_exchange_test.go
@@ -1,7 +1,11 @@
package home
import (
+ "amadan.net/rastrillo/rastrillo/assertion"
"amadan.net/rastrillo/rastrillo/sessions"
+ "encoding/base64"
+ "encoding/json"
+ "github.com/keymaildev/signin"
"net/http"
"net/http/httptest"
"net/url"
@@ -99,3 +103,84 @@ func TestIDLinkRejectsPassiveMintedSession(t *testing.T) {
t.Fatal("passive newly minted session satisfied linking")
}
}
+
+func TestIDClosedAuthorize(t *testing.T) {
+ p := newExchangePair(t)
+ nonce, _ := assertion.RandomID()
+ base := "consumer=directory&nonce=" + nonce
+ for _, query := range []string{base + "&consumer=directory", base + "&nonce=" + nonce, base + "&unexpected=1", "consumer=unknown&nonce=" + nonce, "consumer=directory&nonce=bad", base + "&max_age=301", base + "&max_age=300&max_age=300"} {
+ r := exchangeRequest(p.credential.App, "GET", Origin+"/authorize?"+query, "", nil)
+ if r.Code != 400 || len(r.Result().Cookies()) != 0 {
+ t.Fatal("ambiguous authorize accepted")
+ }
+ }
+}
+func TestIDAllSensitivePostsRequireOrigin(t *testing.T) {
+ p := newExchangePair(t)
+ for _, path := range []string{"/authorize/resume", "/passkey/direct/begin", "/passkey/direct/finish", "/passkey/register/begin", "/passkey/register/finish", "/passkey/signin/begin", "/passkey/signin/finish", "/passkey/signin/recovery", "/passkey/replace/begin", "/passkey/replace/finish", "/passkey/codes", "/passkey/notice"} {
+ r := exchangeRequest(p.credential.App, "POST", Origin+path, "https://evil.invalid", url.Values{})
+ if r.Code != 403 {
+ t.Fatal("cross-origin mutation admitted", path, r.Code)
+ }
+ }
+}
+
+func TestIDEmailMintPreservesVerificationTime(t *testing.T) {
+ a := newTestApp(t)
+ verified := time.Now().Add(-2 * time.Minute).UTC().Truncate(time.Second)
+ r := httptest.NewRequest("POST", Origin+linkPath, nil)
+ w := httptest.NewRecorder()
+ a.completeSignIn(w, r, signin.Identity{Address: sealtest.CanaryAddress, Method: signin.MethodMagicLink, At: verified})
+ c := sessionCookie(w)
+ if c == nil {
+ t.Fatal("email completion failed")
+ }
+ r.AddCookie(c)
+ s, ok := a.sessions.From(r)
+ if !ok || !s.AuthTime.Equal(verified) {
+ t.Fatal("email verification time was replaced with mint time")
+ }
+}
+
+func TestIDFreshIntentRequiresStartTime(t *testing.T) {
+ p := newExchangePair(t)
+ _, cookie := p.startFresh(t, nil)
+ req := httptest.NewRequest("GET", Origin+"/authorize/resume", nil)
+ req.AddCookie(cookie)
+ intent, ok := p.credential.readAssertionIntent(req, time.Now())
+ if !ok {
+ t.Fatal("fixture intent")
+ }
+ intent.Started = 0
+ raw, _ := json.Marshal(intent)
+ sealed, err := p.credential.secrets.Sealer.Seal("assertion.intent", raw)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cookie.Value = base64.RawURLEncoding.EncodeToString(sealed)
+ session := signInFully(t, p.credential, sealtest.CanaryAddress)
+ r := exchangeRequest(p.credential.App, "POST", Origin+"/authorize/resume", Origin, nil, cookie, session)
+ if r.Code != 400 {
+ t.Fatal("old freshness intent without transaction start was accepted", r.Code)
+ }
+}
+
+func TestIDEmailInAnotherBrowserCannotFinishOriginalHandoff(t *testing.T) {
+ p := newExchangePair(t)
+ _, intent := p.start(t)
+ form := exchangeRequest(p.credential.App, "GET", Origin+"/signin?return_to=%2Fauthorize%2Fresume", "", nil, intent)
+ navigation := namedCookie(t, form, returnCookie)
+ exchangeRequest(p.credential.App, "POST", Origin+"/signin", Origin, url.Values{"address": {sealtest.CanaryAddress}}, intent, navigation)
+ other := redeem(t, p.credential, capturedLink(t, p.credential))
+ if sessionCookie(other) == nil || other.Header().Get("Location") != "/" {
+ t.Fatal("other browser inherited original handoff")
+ }
+ original := exchangeRequest(p.credential.App, "GET", Origin+"/authorize/resume", "", nil, intent, navigation)
+ if original.Code != 303 || !strings.HasPrefix(original.Header().Get("Location"), "/signin") {
+ t.Fatal("original browser acquired another browser's authentication")
+ }
+ var n int
+ if err := p.directory.db.Writer().QueryRow("SELECT count(*) FROM sessions").Scan(&n); err != nil || n != 0 {
+ t.Fatal("other-browser email minted an app session")
+ }
+}
diff --git a/internal/home/id_recovery.go b/internal/home/id_recovery.go
index 66e6ec5..1e890d3 100644
--- a/internal/home/id_recovery.go
+++ b/internal/home/id_recovery.go
@@ -104,7 +104,7 @@ func (a *App) idGate(w http.ResponseWriter, r *http.Request, s sessions.Session,
if s.Method == string(signin.MethodKeymail) {
mailboxAt = s.AuthTime
}
- if !freshGesture(mailboxAt, time.Unix(now, 0).Add(time.Second), 5*time.Minute) {
+ if !freshGesture(mailboxAt, time.Now(), 5*time.Minute) {
mailboxAt = time.Time{}
}
mailboxUnix := int64(0)
@@ -146,21 +146,6 @@ func generateIDCodes(tx *sql.Tx, subject string, now int64) ([]string, error) {
}
return codes, nil
}
-func (a *App) regenerateRecoveryCodes(subject string) ([]string, error) {
- tx, now, err := a.idTransaction(context.Background())
- if err != nil {
- return nil, err
- }
- defer tx.Rollback()
- codes, err := generateIDCodes(tx, subject, now)
- if err != nil {
- return nil, err
- }
- if tx.Commit() != nil {
- return nil, errIDProof
- }
- return codes, nil
-}
func (a *App) idRecovery(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, 4096)
if r.ParseForm() != nil {
@@ -262,6 +247,11 @@ func (a *App) idRecovery(w http.ResponseWriter, r *http.Request) {
idRefuse(w)
return
}
+ var proofCount int
+ if tx.QueryRow("SELECT count(*) FROM home_id_recovery_proofs").Scan(&proofCount) != nil || proofCount >= 10000 {
+ idRefuse(w)
+ return
+ }
if _, err = tx.Exec("INSERT INTO home_id_recovery_proofs VALUES(?,?,?,?)", hash, subject, sessions.HashToken(token), exp.Unix()); err != nil {
idRefuse(w)
return
diff --git a/internal/home/id_recovery_test.go b/internal/home/id_recovery_test.go
index bb87665..37a10ea 100644
--- a/internal/home/id_recovery_test.go
+++ b/internal/home/id_recovery_test.go
@@ -78,10 +78,11 @@ func TestIDRecoveryAttemptLimitSurvivesReconstruction(t *testing.T) {
enrol(t, a, s)
codes := idCodes(t, a, s)
gated := redeemAfterSignIn(t, a, sealtest.CanaryAddress)
+ gatedCookies := gated.Result().Cookies()
var wg sync.WaitGroup
for i := 0; i < 16; i++ {
wg.Add(1)
- go func() { defer wg.Done(); idRecover(a, "bad-code", gated.Result().Cookies()...) }()
+ go func() { defer wg.Done(); idRecover(a, "bad-code", gatedCookies...) }()
}
wg.Wait()
app, err := New(a.secrets, a.db, a.logger)
@@ -289,6 +290,10 @@ func TestIDReplacementProofBinding(t *testing.T) {
a.db.Writer().Exec("UPDATE home_id_recovery_proofs SET expires_at=0")
case "wrong-person":
a.db.Writer().Exec("UPDATE home_id_recovery_proofs SET subject='another-person'")
+ if r := idJSON(t, a, "/passkey/replace/begin", nil, cookies...); r.Code == 200 {
+ t.Fatal("proof for another person began replacement")
+ }
+ return
case "bad-uv":
b := idJSON(t, a, "/passkey/replace/begin", nil, cookies...)
k, _ := authtest.New()
@@ -381,13 +386,14 @@ func TestIDRecoveryCodePersonBindingAndReplay(t *testing.T) {
t.Fatal("code crossed accounts")
}
gate := redeemAfterSignIn(t, a, sealtest.CanaryAddress)
+ gateCookies := gate.Result().Cookies()
var successes atomic.Int32
var wg sync.WaitGroup
for i := 0; i < 12; i++ {
wg.Add(1)
go func() {
defer wg.Done()
- r := exchangeRequest(a.App, "POST", Origin+"/passkey/signin/recovery", Origin, url.Values{"code": {codes[0]}}, gate.Result().Cookies()...)
+ r := exchangeRequest(a.App, "POST", Origin+"/passkey/signin/recovery", Origin, url.Values{"code": {codes[0]}}, gateCookies...)
if sessionCookie(r) != nil {
successes.Add(1)
}
@@ -418,3 +424,40 @@ func TestIDRecoveryCannotRegenerateCodesOrSatisfyPasskeyOnlyStepup(t *testing.T)
t.Fatal("recovery satisfied passkey-only operator stepup")
}
}
+
+func TestIDMailboxMemoryBoundAndExpiry(t *testing.T) {
+ m := mailboxMemory{entries: map[string]mailboxProof{}}
+ for i := 0; i < 1000; i++ {
+ m.entries[fmt.Sprint(i)] = mailboxProof{"person", sealtest.CanaryAddress, time.Now().Unix() + 300}
+ }
+ if m.put("overflow", mailboxProof{"person", sealtest.CanaryAddress, time.Now().Unix() + 300}) {
+ t.Fatal("mailbox memory exceeded hard bound")
+ }
+ m.entries["expired"] = mailboxProof{"person", sealtest.CanaryAddress, time.Now().Unix() - 1}
+ if _, ok := m.get("expired"); ok {
+ t.Fatal("expired mailbox proof retained")
+ }
+}
+func TestIDRecoveryProofCapacity(t *testing.T) {
+ a := newTestApp(t)
+ s := signInFully(t, a, sealtest.CanaryAddress)
+ enrol(t, a, s)
+ codes := idCodes(t, a, s)
+ g := redeemAfterSignIn(t, a, sealtest.CanaryAddress)
+ if _, err := a.db.Writer().Exec("WITH RECURSIVE n(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM n WHERE x<10000) INSERT INTO home_id_recovery_proofs SELECT printf('%064x',x),'person','session',? FROM n", time.Now().Unix()+300); err != nil {
+ t.Fatal(err)
+ }
+ r := exchangeRequest(a.App, "POST", Origin+"/passkey/signin/recovery", Origin, url.Values{"code": {codes[0]}}, g.Result().Cookies()...)
+ if sessionCookie(r) != nil {
+ t.Fatal("recovery proof capacity exceeded")
+ }
+}
+
+func TestIDCodesRequireEnrolledPasskey(t *testing.T) {
+ a := newTestApp(t)
+ s := signInFully(t, a, sealtest.CanaryAddress)
+ r := exchangeRequest(a.App, "POST", Origin+"/passkey/codes", Origin, url.Values{}, s)
+ if r.Code == 200 {
+ t.Fatal("codes issued before passkey enrollment")
+ }
+}
diff --git a/internal/home/passkey.go b/internal/home/passkey.go
index 84d7958..7bb04c7 100644
--- a/internal/home/passkey.go
+++ b/internal/home/passkey.go
@@ -20,62 +20,13 @@ var staticFS embed.FS
// depend on a default in another package staying put.
const confirmPath = "/passkey/confirm"
-// codesFreshness is how recent a session must be to see recovery codes.
-//
-// Short, because the page shows ten codes once. Long enough to exceed a
-// passkey ceremony round trip, or enrolling and then being asked for
-// your codes would bounce straight back to a step-up.
-//
-// A FACT ABOUT RequireFresh THAT A LATER STEP MUST NOT ASSUME AWAY:
-// freshness is not the same as "a real assertion". passkey.SignInRecovery
-// mints its session with AuthTime: time.Now(), so redeeming a recovery
-// code produces a session that satisfies RequireFresh at any duration.
-// That is right here — somebody who just proved possession of a recovery
-// code should be able to replace the set — but §5.2 says recovery is
-// "sign-in only — step-up still demands a real assertion", and
-// RequireFresh alone does not deliver that. §14's owner write is
-// specified to sit behind step-up; if it is built on RequireFresh it
-// will accept a recovery code instead. Asserted in
-// TestRecoveryCodeProducesAFreshSession so the fact cannot change
-// silently.
-//
-// It must be at least enrolFreshness. static/passkey.js sends the
-// browser to /passkey/codes the instant registration finishes, so a
-// window shorter than the one that let them enrol bounces them to
-// re-authenticate at the exact moment they hold a passkey and zero
-// recovery codes — the worst possible moment, and precisely the outcome
-// the sentence above says this value was chosen to avoid. That sentence
-// was true until enrolFreshness was added at a larger value and did not
-// revisit it. TestFreshnessWindowsDoNotStrandAnEnroller pins the
-// ordering.
+// Code generation and enrollment share a freshness window, so a person who
+// just enrolled can save codes immediately. Recovery sessions may read the
+// count, but must replace their passkey and sign in with it before generating.
const codesFreshness = enrolFreshness
-// enrolFreshness is how recent a session must be to ADD a passkey.
-//
-// rastrillo's own RegisterBegin asks only for a valid session, and for
-// most apps that is right. It is not right here, because of what the
-// Gate plus §5.2 add up to: there is no operator reset, by design.
-//
-// The vector, spelled out because it is not obvious. Somebody with a
-// stolen session cookie — good for 30 days — visits /passkey/enrol and
-// enrols THEIR authenticator. From that moment the real owner's magic
-// link lands on the Gate and stops, because the Gate demands a passkey
-// they do not have; and they have no recovery codes, because they never
-// enrolled. A compromise that would have expired with the cookie becomes
-// a permanent lockout with nobody to appeal to.
-//
-// Requiring freshness costs a person who signed in a week ago one more
-// sign-in: RequireFresh redirects a stale GET to the sign-in page with
-// reauth=1, so it is a detour and not a dead end. It costs an attacker
-// the inbox, which is the whole point.
-//
-// Ten minutes: enrolling means reading a page, deciding, and completing
-// an authenticator gesture. The codes page runs on the same window and
-// not a shorter one — see codesFreshness, which is defined as this value
-// precisely because a shorter one stranded people mid-flow. An earlier
-// version of this sentence said "rather than the codes page's five",
-// which was true when written and stood falsely for two commits after
-// codesFreshness was redefined as this value.
+// Adding a passkey needs recent authentication: a stolen thirty-day cookie
+// must not become a permanent credential. Recovery uses explicit replacement.
const enrolFreshness = 10 * time.Minute
// passkeyConfig is the config the app builds.
@@ -201,6 +152,15 @@ func (a *App) handleRegenerateRecoveryCodes(w http.ResponseWriter, r *http.Reque
a.signinFailed(w, r)
return
}
+ var enrolled int
+ if tx.QueryRow("SELECT count(*) FROM passkey_credentials WHERE subject=?", sess.Subject).Scan(&enrolled) != nil {
+ a.serverError(w, r)
+ return
+ }
+ if enrolled == 0 {
+ http.Redirect(w, r, "/passkey/enrol", http.StatusSeeOther)
+ return
+ }
codes, err := generateIDCodes(tx, sess.Subject, now)
if err == nil {
err = tx.Commit()
diff --git a/internal/home/signin.go b/internal/home/signin.go
index 1977237..a0ef3d2 100644
--- a/internal/home/signin.go
+++ b/internal/home/signin.go
@@ -410,6 +410,10 @@ func (a *App) completeSignIn(w http.ResponseWriter, r *http.Request, id signin.I
At: id.At,
}
+ if id.Method == signin.MethodMagicLink {
+ sess.AuthTime = id.At
+ }
+
// The second factor, on BOTH sign-in paths — and on both because
// there is one place to put it, not because two call sites were
// remembered. handleVerify (the magic link) and handleCallback (the
@@ -419,8 +423,8 @@ func (a *App) completeSignIn(w http.ResponseWriter, r *http.Request, id signin.I
// the magic-link path is gated and a keymail-upgraded account walks
// in through the other one.
//
- // Gate redirects and reports true when it has taken over. An account
- // with no passkey passes through untouched.
+ // The gate either stores the pending factor or mints the email-only
+ // session under the same writer transaction as its credential check.
target := readReturn(r)
writeReturn(w, "/")
gated, err := a.idGate(w, requestWithReturn(r, target), sess, id.Address)
diff --git a/internal/home/signout.go b/internal/home/signout.go
index fc48d9b..2c3644c 100644
--- a/internal/home/signout.go
+++ b/internal/home/signout.go
@@ -8,31 +8,10 @@ import (
"amadan.net/rastrillo/rastrillo/csrf"
)
-// signoutPath is the same path on the credential origin, the directory
-// and every connected app. A consumer's POST /signout (the directory's,
-// or an app's through home/connect's Routes.Signout) ends its own session
-// and answers 307 to the credential origin's POST /signout, which ends
-// the id.* session and lands the browser on that consumer's /signed-out.
-//
-// Both halves are needed. The directory session is only the app list;
-// the credential session is what /authorize reads, and it lives 30 days.
-// Ending just the first (as sign-out did until polish-audit B2) made
-// "You are signed out" a promise the next click broke: Sign in, from the
-// directory or from any app, passed straight back through /authorize
-// with no prompt. Round 2 chains each app's own Sign out the same way
-// (spec shared-chrome §9.5).
-//
-// 307 rather than 303 so the hop stays a POST. A GET sign-out is one any
-// page can trigger with a link or an <img>; a POST is not. See
-// signoutReturn for how the credential side tells a consumer's hand-off
-// from anyone else's POST.
-//
-// What this does NOT end: sessions an app instance minted from an
-// earlier assertion. Those are the instance's own sessions on its own
-// host, and the home keeps no list of where it has handed an assertion
-// (a hibernating fleet would not hear a revocation anyway). Each app's
-// own Sign out ends its session; what this guarantees is that no app can
-// get a NEW assertion for this browser without the email or passkey step.
+// Each origin revokes and lands locally. A consumer may separately offer
+// this credential-origin POST as an optional sign-out hop; existing callers
+// using that hop remain admitted by exact registration and origin evidence.
+// There is no cross-origin or global session-revocation promise.
const signoutPath = "/signout"
// handleCredentialSignout ends the credential-origin session.
@@ -82,7 +61,7 @@ func (a *App) handleCredentialSignoutPage(w http.ResponseWriter, r *http.Request
// nothing else: not an unregistered team instance on the same site, not
// any other origin, not a request with no evidence. It returns the origin
// the browser goes back to, which is always the matched registration
-// (the directory, for this origin's own button), and never anything the
+// (this credential origin for its own button), and never anything the
// request supplied. So there is no open redirect to close.
//
// HOME_CONSUMERS is the allowlist that already decides who may receive an
diff --git a/scripts/check-id-mutations.py b/scripts/check-id-mutations.py
new file mode 100755
index 0000000..31e9144
--- /dev/null
+++ b/scripts/check-id-mutations.py
@@ -0,0 +1,125 @@
+#!/usr/bin/env python3
+"""Remove one ID guard at a time, run its regression, and restore the source."""
+import json
+import os
+from pathlib import Path
+import subprocess
+import sys
+import time
+
+ROOT = Path(__file__).resolve().parent.parent
+HOME = ROOT / "internal/home"
+# Guard, file, exact source, replacement, test expression.
+CASES = [
+ ("continue gesture", "exchange.go", "if r.Method == http.MethodGet {", "if false && r.Method == http.MethodGet {", "TestIDContinueBeforeMinting"),
+ ("link new session", "exchange.go", "sameSession ||", "(sameSession && false) ||", "TestIDLinkAlwaysRequiresNewGesture"),
+ ("link transaction start", "exchange.go", "authTime.Unix() < intent.Started", "authTime.Unix() < 0", "TestIDLinkRejectsProofBeforeTransactionStart"),
+ ("passive Keymail issuance", "exchange.go", "|| keymailWithoutGesture(session)", "|| (false && keymailWithoutGesture(session))", "TestIDLinkRejectsPassiveMintedSession"),
+ ("live issuance session", "exchange.go", "session, _, err := a.idSession(tx, r, now.Unix())", "session, _ := sessions.Current(r)", "TestIDRevokedCachedSessionCannotMint"),
+ ("audience", "exchange.go", "Audience: target", "Audience: a.origins.Credential", "TestHomeDirectoryExchangeAndPrivacy"),
+ ("nonce", "exchange.go", "Nonce: intent.Nonce", "Nonce: id", "TestHomeDirectoryExchangeAndPrivacy"),
+ ("assertion lifetime", "exchange.go", "ExpiresAt: now.Unix() + 120", "ExpiresAt: now.Unix() + 121", "TestHomeDirectoryExchangeAndPrivacy"),
+ ("cookie ambiguity", "id_passkey.go", "count != 1 || len(value) > 4096", "count < 1 || len(value) > 4096", "TestIDChallengeBrowserCookiesAndExpiry/duplicate"),
+ ("clock rollback", "id_passkey.go", "err != nil || now < high", "err != nil || (now < high && false)", "TestIDChallengeBrowserCookiesAndExpiry/clock"),
+ ("future enrollment time", "id_passkey.go", "&& !at.After(now)", "&& (!at.After(now) || true)", "TestIDEnrollmentRejectsFutureAndPassiveAuthentication/future"),
+ ("passive enrollment", "id_passkey.go", "!keymailWithoutGesture(s) &&", "(!keymailWithoutGesture(s) || true) &&", "TestIDEnrollmentRejectsFutureAndPassiveAuthentication/passive"),
+ ("challenge capacity", "id_passkey.go", "n >= 10000", "n >= 100000", "TestIDChallengeBrowserCookiesAndExpiry/capacity"),
+ ("challenge lifetime", "id_passkey.go", "purpose, now+300", "purpose, now+600", "TestIDChallengeBrowserCookiesAndExpiry/ttl"),
+ ("challenge browser", "id_passkey.go", "WHERE challenge=? AND browser_hash=? AND", "WHERE challenge=? AND (? IS NOT NULL) AND", "TestIDChallengeBrowserCookiesAndExpiry/other-browser"),
+ ("challenge subject", "id_passkey.go", "AND subject=? AND purpose=?", "AND (? IS NOT NULL) AND purpose=?", "TestIDRegistrationChallengeSubjectAndLiveSession/subject"),
+ ("challenge purpose", "id_passkey.go", "AND purpose=? AND expires_at>? RETURNING", "AND (? IS NOT NULL) AND expires_at>? RETURNING", "TestIDPasskeyRejectsBadProofs/purpose"),
+ ("challenge expiry", "id_passkey.go", "AND expires_at>? RETURNING challenge", "AND (? IS NOT NULL) RETURNING challenge", "TestIDPasskeyRejectsBadProofs/expired"),
+ ("challenge single use", "id_passkey.go", "DELETE FROM home_id_ceremonies WHERE challenge=? AND browser_hash=? AND subject=? AND purpose=? AND expires_at>? RETURNING challenge", "SELECT challenge FROM home_id_ceremonies WHERE challenge=? AND browser_hash=? AND subject=? AND purpose=? AND expires_at>?", "TestIDDirectPasskey"),
+ ("strict ceremony JSON", "id_passkey.go", "strictjson.UnmarshalRead(http.MaxBytesReader(w, r.Body, 64<<10), &body, strictjson.RejectUnknownMembers(true))", "decodeLooseIDJSON(r, &body)", "TestIDCeremonyRejectsAmbiguousJSON"),
+ ("credential collision", "id_passkey.go", "INSERT INTO passkey_credentials(id,subject,public_key,sign_count,created_at)", "INSERT OR REPLACE INTO passkey_credentials(id,subject,public_key,sign_count,created_at)", "TestIDEnrollmentCannotTransferCredential"),
+ ("credential enrollment bound", "id_passkey.go", "count >= 100", "count >= 1000", "TestIDEnrollmentBound"),
+ ("credential owner", "id_passkey.go", '(subject != "" && owner != subject)', '(subject != "" && owner != subject && false)', "TestIDGateBindsCredentialOwner"),
+ ("discoverable admission", "id_passkey.go", " AND id IN (SELECT credential_id FROM home_id_discoverable)", " AND 1=1", "TestIDLegacyCredentialCannotSignInDirectly"),
+ ("WebAuthn verification", "id_passkey.go", "next, e := a.idWebAuthn().Verify(cred, challenge, cd, ad, sig)\n\t\tif e != nil {", "next, e := a.idWebAuthn().Verify(cred, challenge, cd, ad, sig)\n\t\te = nil\n\t\tif e != nil {", "TestIDPasskeyRejectsBadProofs/(origin|rp|uv|signature)"),
+ ("recovery entropy", "id_recovery.go", "rand.Read(raw)", "rand.Read(raw[:6])", "TestIDRecoveryEntropy"),
+ ("account attempt budget", "id_recovery.go", '{"account:" + subject, 5}', '{"account:" + subject, 500}', "TestIDRecoveryAttemptLimitSurvivesReconstruction"),
+ ("IP attempt budget", "id_recovery.go", 'blindIndex(a.secrets.Pepper, clientIP(r)), 20}', 'blindIndex(a.secrets.Pepper, clientIP(r)), 200}', "TestIDRecoveryIPLimitAcrossAccounts"),
+ ("attempt increment", "id_recovery.go", "failures=failures+1", "failures=failures+0", "TestIDRecoveryAttemptLimitSurvivesReconstruction"),
+ ("attempt persistence", "app.go", "a.signinLimiter = signin.NewMemoryLimiter(15 * time.Minute)", '_, _ = d.Writer().Exec("DELETE FROM home_id_attempts")\n a.signinLimiter = signin.NewMemoryLimiter(15 * time.Minute)', "TestIDRecoveryAttemptLimitSurvivesReconstruction"),
+ ("mailbox freshness", "id_recovery.go", "if mailboxAt <= 0 || mailboxAt > now || mailboxAt+300 <= now {", "if false && (mailboxAt <= 0 || mailboxAt > now || mailboxAt+300 <= now) {", "TestIDRecoveryRequiresFreshMailboxGesture"),
+ ("recovery code person", "id_recovery.go", "WHERE subject=? AND code_hash=? RETURNING subject", "WHERE (? IS NOT NULL) AND code_hash=? RETURNING subject", "TestIDRecoveryCodePersonBindingAndReplay"),
+ ("recovery code single use", "id_recovery.go", "DELETE FROM passkey_recovery_codes WHERE subject=? AND code_hash=? RETURNING subject", "SELECT subject FROM passkey_recovery_codes WHERE subject=? AND code_hash=?", "TestIDRecoveryCodePersonBindingAndReplay"),
+ ("recovery proof expiry", "id_recovery.go", "AND subject=? AND expires_at>?", "AND subject=? AND (? IS NOT NULL)", "TestIDReplacementProofBinding/expired"),
+ ("recovery proof subject", "id_recovery.go", "AND subject=? AND expires_at>?", "AND (? IS NOT NULL) AND expires_at>?", "TestIDReplacementProofBinding/wrong-person"),
+ ("recovery proof capacity", "id_recovery.go", "proofCount >= 10000", "proofCount >= 100000", "TestIDRecoveryProofCapacity"),
+ ("mailbox memory capacity", "id_recovery.go", "len(m.entries) >= 1000", "len(m.entries) >= 1001", "TestIDMailboxMemoryBoundAndExpiry"),
+ ("mailbox memory expiry", "id_recovery.go", "!ok || p.expires <= time.Now().Unix()", "!ok || (false && p.expires <= time.Now().Unix())", "TestIDMailboxMemoryBoundAndExpiry"),
+ ("notice outcome", "id_passkey.go", "a.replacementResult(w, !a.sendReplacementNotice(r.Context(), binding))", "a.sendReplacementNotice(r.Context(), binding); a.replacementResult(w, false)", "TestIDNoticeFailureSurvivesRestartWithoutAddress"),
+ ("SMTP log privacy", "signin.go", 'a.logger.Error("signin begin failed")', 'a.logger.Error("signin begin failed", "err", err)', "TestIDSMTPFailureDoesNotLeak"),
+ ("limiter address blinding", "id_limiter.go", 'key = "addr:" + blindIndex(l.pepper, address)', 'key = "addr:" + address', "TestIDSigninLimiterUsesBlindedAddress"),
+ ("local signout", "directory.go", 'http.Redirect(w, r, "/signed-out", http.StatusSeeOther)', 'http.Redirect(w, r, a.origins.Credential+signoutPath, http.StatusTemporaryRedirect)', "TestIDLocalSignoutWithHangingIssuer"),
+ ("sealed link storage", "links.go", "hash, sealed, purpose, expires.UTC()", "hash, append(sealed[:0], []byte(address)...), purpose, expires.UTC()", "TestFullSigninLeavesNoReadableAddress"),
+]
+CASES += [
+ ("closed authorize fields","exchange.go","len(q) != wantFields", "(len(q) != wantFields && false)", "TestIDClosedAuthorize"),
+ ("authorize consumer uniqueness","exchange.go", 'len(q["consumer"]) != 1', '(len(q["consumer"]) != 1 && false)', "TestIDClosedAuthorize"),
+ ("authorize nonce uniqueness","exchange.go", 'len(q["nonce"]) != 1', '(len(q["nonce"]) != 1 && false)', "TestIDClosedAuthorize"),
+ ("CSRF for sensitive posts","app.go", "csrf.Protect(a.origins.Credential)", 'csrf.Protect("https://evil.invalid")', "TestIDAllSensitivePostsRequireOrigin"),
+ ("recovery subject defenses together", "id_recovery.go", "AND subject=? AND expires_at>?", "AND (? IS NOT NULL) AND expires_at>?", "TestIDReplacementProofBinding/wrong-person"),
+]
+CASES += [
+ ("registered authorize consumer","exchange.go", 'a.consumers()[q.Get("consumer")] == ""', '(a.consumers()[q.Get("consumer")] == "" && false)', "TestIDClosedAuthorize"),
+ ("authorize nonce format","exchange.go", '!handoff.ValidNonce(q.Get("nonce"))', '(!handoff.ValidNonce(q.Get("nonce")) && false)', "TestIDClosedAuthorize"),
+ ("authorize max age","exchange.go", 'len(values) != 1 || values[0] != "300"', '(len(values) != 1 || values[0] != "300") && false', "TestIDClosedAuthorize"),
+ ("replacement rollback","id_passkey.go", 'defer tx.Rollback()\n\t\tsubject, binding, err :=', 'defer tx.Commit()\n\t\tsubject, binding, err :=', "TestIDReplacementRollback"),
+ ("email authentication time","signin.go", 'sess.AuthTime = id.At', 'sess.AuthTime = time.Time{}', "TestIDEmailMintPreservesVerificationTime"),
+ ("codes after enrollment","passkey.go", 'if enrolled == 0 {', 'if enrolled == 0 && false {', "TestIDCodesRequireEnrolledPasskey"),
+ ("fresh intent start provenance","assertion_intent.go", 'intent.Started <= 0 || intent.Started > now.Unix()', '(intent.Started <= 0 && false) || intent.Started > now.Unix()', "TestIDFreshIntentRequiresStartTime"),
+]
+for table in ("sessions", "passkey_credentials", "passkey_recovery_codes", "passkey_pending", "passkey_challenges", "home_id_ceremonies", "home_id_recovery_proofs"):
+ CASES.append(("replacement revokes " + table,"id_recovery.go",f'\n\t\t"DELETE FROM {table} WHERE subject=?",',f'\n\t\t"DELETE FROM {table} WHERE subject=? AND 0",',"TestIDRecoveryReplacementRevokesEverything"))
+
+results=[]
+selected=set(sys.argv[1:])
+out=ROOT/"implementation/oficina-id-slice1-mutations.json"
+previous=json.loads(out.read_text()) if selected and out.exists() else []
+for guard,file,old,new,test in CASES:
+ if selected and guard not in selected:
+ continue
+ path=HOME/file
+ original=path.read_text()
+ if original.count(old)!=1:
+ raise SystemExit(f"{guard}: expected one source match, got {original.count(old)}")
+ changed=original.replace(old,new)
+ if guard=="recovery subject defenses together":
+ changed=changed.replace("!ok || p.subject != subject", "!ok || (p.subject != subject && false)")
+ if guard=="strict ceremony JSON":
+ # Keep the strict import used while replacing its behavior for this mutant.
+ changed+='\nfunc decodeLooseIDJSON(r *http.Request, dst any) error { _ = strictjson.RejectUnknownMembers; return json.NewDecoder(r.Body).Decode(dst) }\n'
+ start=time.monotonic()
+ try:
+ path.write_text(changed)
+ proc=subprocess.run(["go","test","./internal/home","-count=1","-timeout=30s","-run",test],cwd=ROOT,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,timeout=75)
+ output=proc.stdout
+ if proc.returncode==0:
+ status="survived"
+ elif "[build failed]" in output:
+ status="invalid"
+ elif "--- FAIL:" in output:
+ status="killed"
+ else:
+ status="error"
+ failures=[line.strip() for line in output.splitlines() if "--- FAIL:" in line]
+ except subprocess.TimeoutExpired:
+ status="timeout";failures=[]
+ finally:
+ path.write_text(original)
+ row={"guard":guard,"file":"internal/home/"+file,"test":test,"result":status,"failures":failures,"seconds":round(time.monotonic()-start,2)}
+ if status=="survived" and guard=="recovery proof subject":
+ row["explanation"]="Independent in-memory mailbox subject check still refuses. The paired mutation removes both checks and must fail the same regression."
+ results.append(row)
+ snapshot=[r for r in previous if r["guard"] not in {v["guard"] for v in results}]+results
+ (ROOT/"implementation/oficina-id-slice1-mutations.json").write_text(json.dumps(snapshot,indent=2)+"\n")
+ print(f"{status}: {guard}",flush=True)
+ if status in ("invalid","error"):
+ print(output[-1200:],flush=True)
+out=ROOT/"implementation/oficina-id-slice1-mutations.json"
+if selected and out.exists():
+ results=[r for r in previous if r["guard"] not in selected]+results
+out.write_text(json.dumps(results,indent=2)+"\n")
+sys.exit(0 if all(r["result"]=="killed" or (r["guard"]=="recovery proof subject" and r["result"]=="survived") for r in results) else 1)