Skip to content

Add Laravel for Go support - #158

Draft
entity wants to merge 226 commits into
feat/laravel-rust-supportfrom
feat/laravel-go-support
Draft

entity wants to merge 226 commits into
feat/laravel-rust-supportfrom
feat/laravel-go-support

Conversation

@entity

@entity entity commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

A Go port of Keyring for Laravel for Go (go/keyring, on go.laravel.com v0.1.1). It uses the same tables, stored data and JSON as the PHP package, so one database works with both. Also in this PR:

  • a contract app (go/contract-app), which contract/bin/run-go holds to the HTTP contract;
  • a testing package (go/keyring/keyringtest);
  • a React + Inertia starter kit (go/starter-kit), mirroring rust/starter-kit;
  • the docs in docs/go.

Stacked on #154, so the base is feat/laravel-rust-support. Retarget to main once that merges. The base is merged in up to its latest commit (which brought #157, #159 and #160 from main). No PHP or JS package code changes on this branch.

What's in: all 14 steps of the port

  • Password sign in, the session registry, logout, the security log and its alerts
  • Sessions:
    • ending one session or the others;
    • freshness (423) and the confirm page;
    • the session, owner and user-row locks;
    • PHP's overlapping-requests handling.
  • Second factors and passkeys:
  • Devices, trust and remember me
  • Registration, email verification, password rules, resets, changes and password holds
  • Managing authenticators, including the freeze and its proofs
  • Pages for browsers and Inertia, and pages that also serve guests
  • Policies, AllowSignInWhen and the pipeline steps
  • Risk signals, locations, risk locks and step-ups
  • Single sign-on over OIDC (generic, Google, Microsoft, GitHub), with jose and hosts leaf packages
  • Account changes and impersonation:
    • email changes, with both addresses confirming, undo, reserved addresses and protected attributes;
    • impersonation.
  • Signing in from the app's own routes (Attempt, AttemptSSO, SignInAs, LinkedSSO, LinkNewAccount), and primary factors of the app's own at /login/{factor}
  • Console commands: keyring:prune, keyring:sweep, keyring:sign-out, keyring:import and keyring:install, with the keep-for settings, scheduling, and EndUnsavedSignIns
  • keyringtest:
    • the factor fake;
    • acting as a user with proofs, and authenticator factories;
    • virtual passkeys;
    • a fake identity provider;
    • the conformance checks.

State

  • contract/bin/run-go passes every contract file: 292 tests in 27 files, nothing pending, also with --randomize. contract/bin/run-php passes the same 292.
  • Stored rows were compared against the PHP contract app at each step.
  • go test ./... passes in all three modules, on SQLite and on Postgres. gofmt, vet and go mod tidy -diff are clean.
  • Each step was reviewed for correctness and for security, and the fixes are in, each with a test that fails without it. A final cross-feature review of both kinds found nothing left that needs fixing.
  • CI has go and go (pgsql) jobs, and the js job builds the Go starter kit. Like the rest of CI they skip on drafts, so they've only run locally.

Not ported: security keys and attestation formats other than none, activity(), recordIpsUsing(), translations and Argon2. Some session and step-up services can't be called from the app's own code yet. docs/go/differences.md lists everything.

Running the tests

cd go/keyring && go test ./...
KEYRING_TEST_DATABASE_URL='postgres://postgres:password@127.0.0.1:5432/keyring_go_test?sslmode=disable' go test ./...
cd go/contract-app && go test ./...
cd go/starter-kit && go test ./... && bun install && bun run types && bun run build   # after building ../../js
contract/bin/run-go            # and contract/bin/run-php for the PHP side
bin/ci go go-databases js

Decisions for Charlie

These are calls made while working alone. Each takes the option closest to the PHP package, or to the Rust crate where PHP doesn't apply. A few of them (the step-up idle fix, the hold loop fix, the end_parked lock gap) are worth taking back to PHP and Rust as well.

All decisions (140)

Calls made while working alone, each the option closest to the PHP package (or the Rust crate where PHP doesn't apply). Each is easy to revisit.

  • Pending contract tests (step 3). A contract file goes on run-go's list once every test in it that the steps so far can pass passes; the rest are named in run-go's pending list with the step that passes them, rather than the file waiting until step 7.

  • Alerts are shown to one sign in only (step 3). Marked seen only if still unseen, stricter than PHP, which can show the same alert to two sign ins at once.

  • noteRequest is global middleware (step 3). So entries from any route carry the request ID, IP and user agent, as PHP's request() does anywhere. Its db.Concurrent branch means a test that makes a request while holding a savepoint on the client's context hangs rather than failing at once.

  • Overlapping requests ported (step 4), though the Rust crate skips them, since they're PHP's default and without them a double click signs a browser out. It works around Laravel Go (a wrapped store, nameless cookies, Sec-Fetch-Site removed so the CSRF token decides); see What Laravel Go Lacks for what would make it clean.

  • The user's row lock waits 5 seconds (step 4), as the Rust crate, where PHP waits as long as the database does, and takes FOR NO KEY UPDATE on Postgres. A request that can't get it in time answers 500 (a confirm then signs the browser out). There's no setting to turn the row lock off for apps that don't share their database with PHP.

  • A failed device-trust cache mark still ends the trust and answers 500 (step 4), where PHP stops before the update.

  • The owner's right code clears an attacker's failures in a row with devices off (step 5), as PHP's FailureCounts::succeeded(): with devices off (the default) every browser counts in one failures, so someone with the password can guess four codes a minute indefinitely while the owner keeps signing in (about 1.7% a day with the window at 1). With devices on, the owner's browser clears only known_failures. Kept for parity; a product call for all three ports (e.g. not clearing failures in a row on a factor that can't start a sign in).

  • A right code is spent before the "unavailable" refusal (step 5), in PHP's order; the Rust crate refuses first.

  • The new-device email goes through the queue (step 6), as PHP's ShouldQueueAfterCommit. Laravel Go defaults to the database queue whenever DATABASE_URL is set, so an app without a worker (or QUEUE_CONNECTION=sync) sends nothing; the Notifications doc says so.

  • The email has PHP's lines without Laravel's notification layout (step 6), as the Rust crate; Laravel Go has no such template.

  • A 404 on someone else's device says Not Found (step 6), not PHP's "No query results for model [Keyring\Models\Device]", which names a PHP class.

  • A typed name ending in |known shares the known browser's limit keys (final review), in all three ports: anyone can post five wrong passwords as victim@example.com|known and the owner's first typo from their own device answers 429 (the right password still signs in, nothing is locked for good). The ports share cache keys, so the fix (e.g. the known flag before the name) needs the PHP package and the Rust crate changed together. Not changed.

  • DELETE /user/devices/{device} still 404s on a device already marked signed out (final review), as PHP's ->active(): after a sign out that failed part way, only the report link or the sessions list can finish it.

  • Limits.GuestForms is a new setting (final review), as the Rust crate's limits.guest_forms, so the contract app can raise guests' form limit without raising signed-in users'.

  • Go CI jobs added (final review), go and go (pgsql), mirroring rust/rust-databases; they've only run locally through bin/ci so far.

  • WebAuthn is our own leaf package, not go-webauthn (step 7). go/keyring/webauthn (~700 lines, standard library only) runs webauthn-lib's ceremony steps in their order with its readings of base64, client data and authenticator data, so what passes and what's refused matches the PHP package. go-webauthn's protocol would have been a dependency tree, its own credential and session types to convert from webauthn-lib's JSON at both edges (as the Rust crate had to with webauthn-rs), a clone reported as a flag rather than a refusal, and different strictness on base64 and client data. Our package also checks EdDSA, which the Rust crate couldn't.

  • Passkey records are written back as webauthn-lib writes them (step 7): its keys in its order, nulls left out, fields it doesn't know dropped, IDs re-encoded as unpadded base64url, the AAGUID lowercased, as PHP does on every sign in. The Rust crate keeps unknown fields and the stored order; PHP is the reference here.

  • Cross-origin answers are refused (step 7), as the Rust crate's audit fix: crossOrigin: true with no topOrigin, and a topOrigin of null, which webauthn-lib (with no top origin validator) lets through. Stricter than PHP.

  • Passkey settings are checked at boot (step 7): origins and the RP ID (the Rust audit's fix) and unknown algorithm names, where PHP throws a LogicException on the first ceremony.

  • A passkey alone's failures on an account are capped refusals (step 7), as the Rust crate's audit; PHP writes every one. FactorFailed gained Identifying to say so.

  • CloneSuspected is dispatched when the failure is counted (step 7), before FactorFailed, as the Rust crate; PHP dispatches it from inside the check. Same entries, same order.

  • A failed challenge answer doesn't save the attempt (steps 5 and 7), where PHP's VerifyFactor saves it: the passkey options it held are spent on the server anyway, so the outcome is the same.

  • Only /login/passkey and its options are routed (step 7), not PHP's /login/{factor} for any primary factor; the names are PHP's (keyring.login.options, keyring.login.factor). Other primary factors come with step 13.

  • Factors.Passkeys is on by default (step 7), as the Rust crate's factors.passkeys; PHP has whatever factors the app lists (its contract app lists passkeys).

  • A passkey alone loads its user with Find, not FindForLogin (step 7), as the PHP package (the authenticator's owner relation, no login scope) and the Rust crate do: an app that hides suspended users only from FindForLogin still lets them in with a passkey. Settled in step 10b: kept, as PHP, since AllowSignInWhen is where PHP keeps such users out of every factor, a passkey alone included (tested).

  • A user handle's oldest key is found by created_at, then id (step 7), a tie-break PHP's oldest() leaves to the database. An AAGUID is read only in RFC 4122 hex (Symfony's Uuid::fromString takes base32 and base58 too).

  • Registration and email verification start off (step 8a), as the Rust crate starts its four account features, where the PHP package's config turns them on: each needs something of the application's first (the action, or a user type and users that can verify).

  • A user type verifies its address only with Features.EmailVerification on (step 8a). PHP asks whether the model implements MustVerifyEmail; Laravel Go reads an EmailVerifiedAt field every new user type has, so taking that alone would stop every notice to unverified users of apps that never verify. With the feature on, the type must have the field and the users an auth.EmailVerifier, which Register checks. A Go app sharing users with a PHP app that verifies should turn it on.

  • The sign-in gate follows PHP's hidesRegisteredAddresses() (step 8a), registration on and RevealTaken off, where the Rust crate has a switch of its own (verified_before_sign_in, on by default) so it can hold unverified users back with registration off. A Go app sharing users with a PHP app that registers should turn registration on too.

  • CreatesNewUsers takes and gives maps (step 8a), as PHP's array and the Rust crate's Input: Validate(r) validates the request (passwords already in NFC) and returns what Create needs, and Keyring reads the address from it under Config.Email. Taken addresses are looked for in the user model's table, or through an optional Taken the action implements (the Rust crate's taken()), not the provider's FindForLogin, which may hide accounts that still hold their address.

  • Config.Email is new (step 8a), the PHP package's keyring.email, apart from Username, both email by default.

  • A unique violation from Create is looked at again (step 8a, review), as PHP: taken by then, it's answered as taken; otherwise it's some other index's, reported and answered the same with nothing sent where registration hides addresses, and a 500 where it reveals them. The Rust audit answered every violation as taken, which would hide a broken unique index of the application's behind "taken".

  • The verification email is Laravel's lines without its layout (step 8a), subject "Verify your email address" as PHP's Laravel sends it (the Rust crate says "Verify Email Address"), and already_registered's reset line is the Rust crate's plain "Forgotten your password? Reset it here: URL" where PHP's is Markdown. Notifications.AccountMail replaces either.

  • Mail after a hidden registration, and the reset link, go from r.Background (step 8a, review), as PHP's defer() and the Rust crate's task::background; sent there with the mailer, not queued (see the account emails below). r.OnFinish held the next request on a kept-alive connection until the mail and the Registered listeners were done, which showed a free address from a taken one.

  • A taken address is mailed at the address its account has, and only when it's the one typed (step 8a, review), stricter than PHP and the Rust crate, which mail the typed address. On a collation that ignores accents (MySQL's _ai_ci), victim@exämple.com finds victim@example.com's account, and the typed mailbox would learn that address is registered, with a notice allowance of its own. Now the account's row is loaded (Config.Email's column, or FindForLogin for an action with Taken), the notice is counted under its normalised address, and nothing is sent if that isn't the typed address normalised. An address the action's Taken says is taken with no account found for it gets nothing either, as there's no stored address to check it against.

  • registered and registration-received name the login page by its route (step 8a), wherever the application placed Keyring's routes, as the Rust crate's fix.

  • The 429 for another verification link uses the sign-in lockout's countdown (step 8a), "Too many login attempts. Please try again in N seconds." (countdownMessage, "1 second" for one), as the Rust crate; PHP's auth.throttle says "seconds" always. However long is left, as PHP's Throttle::exception(): never the lockout's "Reset your password" past Limits.LongestLock (review).

  • International hosts follow the URL Standard's bidi and joiner rules (step 7 review), as browsers do, where the lexbor PHP 8.5 ships skips them: a few hosts PHP takes (e.g. 1app.xn--6dbbec0c.co.il) stop Go at boot when passkeys are on. Passkeys need the host the browser hashes, so the browser's rules win.

  • Password resets and changes start off (step 8b), as the Rust crate starts them, each needing its action (ResetPasswordsWith, UpdatePasswordsWith), which Register checks; the PHP package's config turns them on. The actions take the input as a map, as CreatesNewUsers does, and save the password themselves.

  • sign_out_others: false still ends the other sessions' records (step 8b), as password_changed, as the Rust crate does: auth.Session signs out every session whose password fingerprint is of another hash, so they'd be signed out on their next request anyway, and ending their records now keeps them off the sessions list. The rest of signing out everywhere (a new remember token) waits for sign_out_others. The PHP package keeps them; the contract leaves it open.

  • The session that changed the password is signed in again with auth.Login (step 8b), so the guard's fingerprint is of the new hash, before it moves to a new record. Without it the guard would sign the browser out on its next request.

  • A browser the guard let go of, whose record had already ended, is logged as session_ended (step 8b), with the reason PHP's middleware gives (revoked after a change or reset), for the record's user if they're still there: the PHP log has that entry, as its guard keeps no fingerprint and its middleware finds the record ended.

  • A user with no remember token isn't given one when signed out everywhere (step 8b), where the PHP package's cycleRememberToken() gives one (Laravel's getRememberToken() casts a null to "", which passes its !== null): no cookie carries a token the user doesn't have, and saving one waits on the user's row with no limit when the PHP side holds it (user_row_test.go). So users.remember_token differs between the two after a reset or a change, for such a user alone.

  • The reset email's subject is "Reset your password" (step 8b), as the Laravel the PHP package runs on sends it; the Rust crate says "Reset Password Notification", Laravel's older wording. Laravel's lines, without its layout, as the other emails.

  • A reset link's address is found through FindForLogin when users sign in by it (step 8b), and otherwise by Config.Email's column, then Find, as Laravel's broker asks the provider by the keyring.email credential; the Rust crate always asks find_for_login, which can't find an address by another column.

  • The hold's exceptions are route names (step 8b), as PHP's routeIs(), so an application route with one of those names is let through too; the Rust crate matches Keyring's own handlers only.

  • A reset unlinks identity providers ahead of single sign-on (step 8b), as the PHP package does whether the factor is registered, with AuthenticatorRemoved, its log entry and its notice, which step 9a's removals share.

  • The checks Rust's audit moved ahead of the action stay ahead of it (step 8b): the current password again, the held one, and one bcrypt can't take (with every rule of the user's PasswordRules) are refused before the action runs, where the PHP package lets the action save and refuses after (unchanged) or leaves bcrypt's limits to the action's rules.

  • A change's write rolls back with the user's row lock (step 8b) on PostgreSQL and MySQL when the action fails, as the PHP package's RowLock::hold() transaction does, and then nothing that follows a save is done. On SQLite the write stands, and what follows it is done before the failure is returned, but only for a write the action made (never a hash another request stored meanwhile).

  • A reset runs under the owner's lock (step 8b), as the Rust crate's, so of two resets with one link only one goes through; Laravel's broker takes no lock.

  • RequirePasswordChange takes the reason as a string (step 8b), "" for none, kept as NULL.

  • /enrolled in the contract app answered without asking for a second factor (step 8b): the hold tests navigate to it; since step 9b it's behind RequireEnrollment, as the PHP app's.

  • Laravel's email|max:255 messages both show (step 8b): Laravel doesn't stop at the first rule a field breaks unless told to bail, so an address that's malformed and too long gets both, and one that isn't text "must be a string" and "a valid email address".

  • Keyring creates password_reset_tokens where it's missing (step 8b, review), in Laravel's schema (email primary, token, created_at nullable, whole seconds), from a Go-only migration, 2026_12_03_000001_create_password_reset_tokens_table_if_missing, a name no PHP migrations table has. A PHP app gets the table from Laravel's first migration, a Laravel Go app from nothing, and without it resets can't send links and a change fails after its save. An app migration of its own that sorts before it (as the contract app's 0001_01_01_000003_...) keeps the table it makes; one added later, sorting after, would fail on a database Keyring already gave the table. Rejected: failing Register, which can't look at the database.

  • A reset is refused once the account's address has changed since it was looked up (step 8b, review), read again under the owner's lock: stricter than PHP, whose broker checks the token against the address of the user it loaded and saves whatever the row is by then.

  • The password actions run with a deadline under the owner's lock (step 8b, review): 2s before the 10s lock lapses, and the breach checks (Laravel's 30s, Keyring's 10s) wait at most until a second before it. A check that runs out is one Have I Been Pwned couldn't be asked about, as in PHP once its timeout is up: let through, or refused with RefuseUnchecked. PHP waits the full timeout, under no lock for a reset and the user's row lock for a change.

  • A browser that changes the password isn't brought back by "remember me" afterwards (step 8b, review), as with the PHP package (checked with a throwaway Pest test: remember, change with sign_out_others true or false, lose the session, come back: signed out), whose guard cookie keeps the old password's hash and, the others signed out, the old remember token. The Go port signs the browser in again without "remember me", which takes the guard's cookie back to the same effect; Keyring's remembered_session moves to the new record as PHP's does.

  • The account emails are sent with the mailer from r.Background, not queued (step 8b, review), as PHP: Laravel's ResetPassword and VerifyEmail and Keyring's AlreadyRegistered aren't ShouldQueue, so PHP sends them in the request (or its defer()) and stores no link or token; only the security notices are queued (ShouldQueueAfterCommit). sendAccountMail uses mail.Send, so a reset link's token and a verification link never sit in jobs or failed_jobs. Every caller sends from r.Background, whose goroutine starts at the call and is never waited on for the answer (not after it, as PHP's defer() runs), the open registration's link and POST /email/verification-notification included (PHP sends those two in the request, where a mailer failure is a 500): a failure is reported and the answer is the same.

  • Beginning an enrollment counts against Limits.Forms (step 9a), as the Rust crate's audit counts it, where the PHP package's store() route has no keyring.throttle: beginning sends codes (9b) and does a key's work.

  • Changes to sign-in methods take the owner's lock as well as the user's row (step 9a), as the Rust crate's changes::holding(), where the PHP package takes the row lock alone: on SQLite, where there's no row lock, two changes would otherwise each find the account unfrozen.

  • Making the default the default again keeps it (step 9a), as the Rust crate does it. The PHP package's update() unsets every default, the authenticator's own fresh copy among them, then sets is_default on the model it loaded, which Eloquent finds unchanged and doesn't save, so the authenticator ends up not the default. A PHP fix (->filter(fn ($other) => $other->isNot($authenticator))) would bring the two together.

  • A posted credential whose id/rawId isn't the attested credential ID is refused (step 9a), stricter than webauthn-lib, which stores the attested ID whatever the browser posted.

  • A 404 for someone else's authenticator says Not Found (step 9a), as for a device (step 6), not PHP's "No query results for model [Keyring\Models\Authenticator] …".

  • Registration with managing sign-in methods and no email verification stops Register (step 9a), unless AllowEnrollmentWhen decides, where the PHP package throws EmailVerificationRequired at the first enrollment.

  • The QR code is rsc.io/qr's, drawn as one path of squares (step 9a), 192 pixels across with no margin as BaconQrCode's, not its markup; the module's one new dependency (BSD, by the Go authors, no dependencies of its own). Laravel Go has no QR renderer, and writing one (Reed–Solomon, masks, version tables) wasn't worth it.

  • Sign-in methods of factors Keyring for Go can't check aren't listed, renamed or removed (step 9a): a PHP app's sso link or emailed code is a 404 here until steps 9b and 12, as the PHP package's own routes are for a factor it doesn't register. They aren't left out of the rest, failing closed as PHP would see them (review fix): one that may be a factor (not recovery, email-code or sso; a security key, or a passkey with passkeys off) freezes the account for EstablishedAfter once added, and keeps the recovery codes when the last factor Go knows is removed.

  • A removal whose devices can't be distrusted isn't made (step 9a), as in the PHP package's transaction: nothing is removed, and nothing announced (review fix; it used to be announced with the failure returned).

  • Renaming or making the default one removed meanwhile is a 404 (step 9a), decided under the lock: the PHP package saves its stale copy, to no row, and answers that it did.

  • The first factor's recovery codes are decided and made under the lock (step 9a), where the PHP package makes them before: a set made meanwhile in another request is kept, rather than replaced by codes the user never saw saved, and the answer has no recoveryCodes then.

  • SignInMethods is the Rust crate's (step 9a): the PHP package leaves a settings page to read $user->keyring->all() and present() itself, which Go apps can't reach.

  • Codes are sent with the mailer in the request (step 9b), as the PHP package's VerificationCode (not ShouldQueue) and the Rust crate send them: the user is waiting, and a queued one would keep the code in the jobs table. A mailer's or sender's error is the request's 500, with the new code already kept, as in both.

  • An attempt a wrong code leaves out of guesses is saved (step 9b), an exception to steps 5 and 7's "a failed answer doesn't save the attempt": otherwise its page would carry on showing until the next answer. The guesses are counted on the server either way.

  • Register refuses what the PHP package refuses at first use (step 9b): verification_code in Notifications.Off with emailed codes on (PHP's MissingNotification as the first code is sent), and Limits.Codes under one or Limits.CodesPer under a second with a code factor on (PHP would refuse every send). Codes are capped at 18 digits, as in the Rust crate.

  • A code factor of the application's own is a struct with zero defaults (step 9b): CodeFactor[U]{...} given to AddCodeFactor, as the Rust crate's builder, its sender an interface and making the new method an optional second one. It proves possession, or the address with SentToAnAddress; the Rust crate's own limits and other categories, and a credential_id for the row, wait for an application that needs them.

  • Emailed codes are off unless set (step 9b), Factors.EmailCodes nil, as the PHP package has them only once registered (its contract app registers them, as the Go one now does).

  • RequireEnrollment fails closed without the session (step 9b), a 500 as RequireAssurance and RequireFreshVerification answer, where the PHP package's would find no user and let the request through.

  • RequireEnrollment saves the page with its own requirement alone (step 9b): Laravel Go doesn't tell a middleware the values of the route's others, so the docs say to give it the options of the route's RequireAssurance. Otherwise a user adds what this one asks and is sent back by the other, which saves the page again with its own.

  • A signed-in browser at a guest page goes where Laravel's RedirectIfAuthenticated sends it (step 10a): the dashboard route, the home route or the site's root, as the PHP package's guest middleware, where the Rust crate (and Go until now) sends it to home. Laravel's version also takes an unnamed GET route at /dashboard or /home, which Go can't look up, and an application changes it with redirectUsersTo(), which Laravel Go hasn't got: a Go app sharing users with a PHP app that calls it should name the route it points to dashboard.

  • A guest's redirect to log in from a signed-in route keeps Keyring's security headers (step 10a): Referrer-Policy, X-Frame-Options and the rest, which the PHP package's answer lacks because Laravel's middleware priority runs auth ahead of AddSecurityHeaders. Stricter, on a redirect with no body; left as it is.

  • Sessions.ContinueAsGuest refuses an empty route name at Register (step 10a), where the PHP package treats a list it can't read as no routes, which a typed setting can't be.

  • EndUnsavedSignIns waits for step 14 (step 10a): it's the Rust crate's own (the PHP package has none), about sessions that fail to save rather than pages, and needs every record move to say whether its session will be saved.

  • A held user is let through to PasswordChangeURL's page past RequireEnrollment (step 9b, review): the hold comes first. In the PHP package and the Rust crate, a held user with no second factor loops: keyring.enrolled sends the password page to enroll, and the hold sends the enrollment page back to the password page. A three-port fix: PHP's RequireEnrollment and the Rust crate's should let that page through while the user is held, as Go now does.

  • Wrong code guesses are read, compared, then counted (step 9b, review), as PHP's CodeFactor::check() and the Rust crate: two guesses at once can both be checked against a count of four. The session lock bounds it for one session (a sign in's attempt or a user's enrollment lives in one session), but copies of a session, or two sessions enrolling, could each get a guess past the limit. Counting first (hit, then compare) would need all three ports to change together, since they share the keyring:guesses: counts.

  • An enrollment's code can get about nine guesses (step 9b, review): the guesses are counted for EnrollmentsFor (15 minutes) from the first wrong one, which may have been at an earlier code, and a code lasts 10 minutes. A code begun again late in that window gets the guesses left in it, then, once the count lapses, five more: up to about twice MaxGuesses. Still nowhere near a 6-digit code's million. As PHP and the Rust crate, whose counts the Go port shares.

  • An application's own code factor's enrollment sends are limited per account only (step 9b, review), Limits.Codes in Limits.CodesPer in the |signed-in bucket, as PHP's Throttle::sending(): whoever is signed in chooses the destination (a phone number), so a paid SMS sender can be made to text other people's numbers, three every ten minutes per account. The docs should tell applications with paid SMS to limit by destination and IP in their Deliver.

  • The browser proof shares crypt.EncryptString with authenticator secrets, with no purpose tag (step 9b, review), as PHP's Crypt::encryptString(): the known_browser proof only reads JSON with an account and an integer at, which a decrypted secret never is, so one can't stand in for the other. A purpose tag would need the PHP package too.

  • r.FullURL() keeps the query string as sent (step 10a, review), where Laravel's fullUrl() sorts it: a signed-out browser at a page that serves guests is sent back to /welcome?b=1&a=2 in Go and /welcome?a=2&b=1 in PHP. The same page either way; docs/rust/differences.md notes it for the Rust crate.

  • The policy is a closure with the request's context (step 10b): Require(func(ctx, *U, Attempt) Requirement), as PHP's closure of the user and the attempt; the context is there for date.Now (Device.IsTrusted(ctx)). No fixed-requirement setting beside it (PHP's require(Requirement), the Rust crate's KeyringConfig::policy): a closure returning one does the same.

  • Requirements hang off Level (step 10b): keyring.AAL2.Requirement(), since AAL1–AAL3 were already RequireAssurance's level constants; RequireFactors/RequireSteps for PHP's factors()/steps(); NoDowngrade() and NoDowngradeExcept(...) for PHP's default argument. The zero Requirement is the default policy rather than a requirement of nothing.

  • A pipeline step is an interface value, Keyring's own fixed in code (step 10b), as the Rust crate: EnsureNotThrottled, VerifyFactor and CompleteAttempt can't be taken out even dangerously, and the application's steps only go between the last two. PHP lets a step go anywhere and replace any step dangerously.

  • The unregistered-factor refusal stays with DetermineRequirement, in PHP's order (step 10b), so an application's step after ResolveDevice runs first; with that step dangerously removed or replaced, Keyring still refuses such an account (stricter than PHP, where the refusal goes with the step).

  • ResolveDevice doesn't note trust (step 10b): Go keeps "don't ask again on this device" where it was (the first factor's form, a challenge answer), so removing or replacing the step doesn't lose it, where PHP's ResolveDevice is what notes it.

  • keepOut signs this browser out even when ending the others fails (step 10b), answering 500 with the error, where PHP throws before its own sign out.

  • AllowSignInWhen answers a bool (step 10b), as PHP's closure; the Rust crate's AuthorizesSignIn can fail. AllowsSignIn(nil, user) is allowed outside a request, a followed verification link then counting for nothing.

  • A minimal Risk type now (step 10b): Risk{Findings []Finding{Signal, Score, Reason}} with Has, so the policy API and the contract app's Wary policy are final; step 11 fills it and may add the level and score.

  • An Action is a struct of fields (step 11), keyring.Action{StepUp: true, Notify: true}, rather than the PHP package's builders, and LockFor a duration (zero locks nothing, where PHP's lockFor(0) names the action locked). DefaultRiskResponse gives critical Deny and Reauthenticate both, as PHP's deny(); an application's Action{Deny: true} is answered the same everywhere.

  • RespondToRisk takes the context (step 11), func(ctx, *Risk, Checkpoint) Action, as Require does; RiskSignals adds to the signals (PHP's push()), since a Go application sets them up once in code; there's no replacing signals().

  • Signals aren't generic (step 11): Assessment.User is any (a *U), so the built-in signals are plain values (keyring.NewDevice{}), as the Rust crate's dyn Any user. A built-in signal's zero field takes the PHP default, so a score of 0 can't be asked for (take the signal out instead).

  • Risk.Levels must be ordered, with a medium of at least 1 (step 11), refused at Register: PHP takes anything, and levels left at zero (cfg.Risk = keyring.RiskSettings{Store: ...}) would make every assessment critical and refuse every sign in. Risk.Store names a cache store as PHP's risk.store; one that isn't configured panics at the first lock (Laravel Go's cache.Named), a 500, as Register can't look.

  • A sign in's attempt always carries a risk once assessed (step 11), empty when no signal found anything (or none are set), as PHP's AssessRisk sets $attempt->risk every time: a policy's attempt.Risk is nil only outside a sign in (a confirm, a removal, a fresh verification). Step 10b's test that it was nil at sign in now asks for an empty one.

  • Countries are compared as text (step 11), as the Rust crate: PHP's contains() compares loosely, so "1" and "01" would be one country there. A location is an ordered list, kept in the locator's order as PHP's array keeps it; an empty one is unknown, where PHP would store [] for a locator that returned an empty array.

  • ImpossibleTravel's distance can differ from PHP's in the last bit (step 11): Go's math.Sin/Cos aren't the C library's. Only a distance a hair from a whole kilometre could print differently.

  • The new_device entry says "near" (step 11), as PHP's description() does, now that devices have places: entries from step 3 on said the name alone because there was nowhere to be near.

  • A failed stepped-up mark is ignored (step 11), as PHP's rescue(report: false): requests stepping up alongside then stay on their record, and their next request finds it ended.

  • A risk step-up's new record is used now (step 11, review), where the PHP package (swapRecord()'s $session->with([...])) and the Rust crate copy the old record's last_activity_at: a session stepped up near its idle limit otherwise idles out minutes later, since the request's use is noted on the record it moved on from. PHP and Rust should take this fix too.

  • ID tokens are checked by a leaf package of our own on the standard library (step 12), go/keyring/jose, PHP's SignedToken port, as webauthn is webauthn-lib's: a library (go-jose, lestrrat's jwx) would take alg values, key shapes, JSON and base64 PHP refuses, or refuse some it takes, and a parity port has to accept and refuse what PHP does. Checked token by token against PHP. One gap: Go's crypto/rsa refuses an RSA exponent over 2³¹−1, which OpenSSL takes; no provider publishes one.

  • Where a provider's URLs point is a leaf package too (step 12), go/keyring/hosts, PHP's filter_var(), parse_url() and the RFC 6890 tables ported line by line, with the Rust crate's two fixes kept, stricter than PHP: ::ffff:0:0/96 reaches its IPv4 address so it's inward, and a URL without a host or a known port is never the same host as anything.

  • Factors.SingleSignOn starts off (step 12), as the Rust crate's features.sso: it needs a provider. A link on an account with it off is unknown, as any factor Go doesn't have, and the account is refused at sign in with the unavailable 422, as PHP refuses one with a factor it doesn't register.

  • All four of the PHP package's drivers are ported (step 12), not only oidc: Google and Microsoft are OpenID Connect with their own issuer rules, and GitHub is small; links any of them made in PHP sign in here.

  • Providers are a slice, and a name given twice stops Register (step 12), where PHP's are an array's keys and can't repeat. Anything else wrong with one is found when it's built, reported and left off the login page, a 500 at its routes, as in PHP.

  • SSO.ResolveHosts is a setting (step 12), PHP's HostResolver::fake() for tests: nil asks DNS.

  • Linking refuses an account any row has already, confirmed or not (step 12), the Rust crate's taken(), before inserting: PHP inserts and turns the unique violation away the same, so only the order differs.

  • An application's driver's identity is held to the provider and request Keyring knows (step 12), the Rust crate's vouched(), where PHP takes what its driver says.

  • A callback's amr given as an object is read in key order (step 12): Go's decoded maps don't keep PHP's insertion order. It's the provider's say, kept for the application, and counts toward nothing.

  • Discovery documents are cached as their checked body and read again from the cache each time they're needed (step 12), where PHP keeps one per provider object for the request: the same answers, a few more cache reads.

  • The callback runs its middleware itself (step 12), as the PHP controller's through(): Guest and the login options' limit for a sign in, Authenticate, Config.ChangesMiddleware and the forms' limit for a link, Authenticate and the forms' limit for a confirm. The impersonation refusal joins them in step 13.

  • A gate that panics fails a start as a 500, and counts as a no while an impersonation runs (step 13a), as the PHP package throws the callback's exception at a start and rescues it in ending(). The previous draft refused both as not_allowed.

  • Every pending contract test left run-go's list in step 13a, not only the two impersonation entries: enrollment's, own-sign-out's and guest-pages' impersonation tests, and pages' and risk's, which the email changes (42144a7) already passed, and email-changes itself joined the list, which that commit had left off.

  • The impersonator's password is checked by a keyed hash of their hash (step 13a), as the Rust crate, where PHP keeps the guard's hashPasswordForCookie(): it's only kept in the session, which the two never share, so only the form differs.

  • Primary-factor keys are known process-wide (primaryRegistry, as the Rust crate's CLASSIFIED), so two apps in one process can't use one key differently. Threading config through a dozen helpers was the other option.

  • LinkNewAccount dispatches nothing, as PHP's documented sign-up inserts the row with no event (Rust dispatches AuthenticatorAdded). The events table matches PHP's.

  • GET /login/{factor}/options is one static, unnamed route per app factor: a generic one clashes with /login/challenge/{factor} in http.ServeMux. Only the passkey's keeps keyring.login.options.

  • Attempt and AttemptSSO return (*web.Response, error), refusals as the error, as PHP throws and Rust returns Result.

  • Starter kit has no security keys (not ported) and no unverified-sign-in setting (Go's Registration has only RevealTaken); it uses Laravel Go's auth.Authenticate and auth.RequireVerifiedEmail in place of Rust's hand-written RequireUser; DB_TIME_PRECISION=0 as the contract app.

  • Email-change review fixes:

    • Opting out: Config.GuardChangesManually is a code setting, not an env var, for users that aren't Laravel Go models. Without it, Register refuses a user type with no model.UpdatingHook while anything is protected; PHP's trait makes the protection automatic.
    • Columns it can't compare count as changed: with no user, a column missing from the model, db.Raw, or a missing row, GuardChanges refuses.
    • A nil user is refused a reserved address, and a context made with auth.WithUser counts as the bypass actor.
    • The reset link is forgotten before the write. Through the hook it rolls back with a failed save.
    • Laravel Go's own password rehash through model.Update is refused outside a flow while UpdatePasswords is on, as PHP would refuse its own Auth::attempt rehash. Keyring for Go doesn't rehash.
    • Cost: one small select per protected column on each guarded save.
  • EndUnsavedSignIns fires only on a 5xx that carries no session cookie (store unwritable or panic). Laravel Go saves the session whatever the handler answers, so Rust's "any 5xx" signed out browsers already on their new record and broke four tests. PHP has nothing like it.

  • Sessions.SweepEvery zero means off: Go can't tell zero from unset, where PHP warns on an explicit zero. Negative values are refused.

  • keyring:install prints cfg.Factors.Passkeys = false / cfg.Features.SecurityLog = false when not picked, since Go defaults them on and PHP leaves unpicked ones commented out.

  • keyring:import reads the table SessionUserType names, --table to override (as Rust), since Go can't see the app's model as PHP's Eloquent provider does.

  • Prune output names tables ("Pruned 1 [keyring_devices] records."), as Rust; PHP's model:prune names model classes.

  • SSO review fixes:

    • Callback query parsing matches PHP's parse_str in full: malformed escapes are kept as written, names cut at a NUL, spaces and dots before [ become _.
    • Keyring's SSO requests still go through the app's HTTP client, so httpclienttest fakes answer them. Keyring's own transport rebuilds each request from only what Keyring wrote, with retries off, so nothing the app adds reaches the provider. The app's BeforeSending/AfterResponse hooks and debug log still see the requests, client secret included.
    • Stricter than PHP: only a 2xx counts, as in Rust, where PHP accepts a 3xx. Provider answers are capped at 1 MiB.
    • A driver must report a freshness: a driver whose Freshness() is "" with none configured can't be built. An unrecognised value counts as never.
    • User-Agent: Laravel-Go/<version>.
  • keyringtest.New[U](t, client) is one helpers object rather than package functions taking t and client: laraveltest doesn't expose the test from a client, and Go can't add methods to laraveltest.Client.

  • Conformance builds a fresh app per check (PHP's one test per check on a fresh database) rather than Rust's one app and a report; Check still returns an Outcome.

  • Factory recovery codes aren't PHP's fixed aaaa-… codes: matching would need Keyring's code hashing exported. Worth adding if apps want PHP's constants.

  • Step 13b review fixes:

    • SignInAs refuses a row of a factor the app has turned off (PHP's UnknownFactor), with an unexported errUnknownFactor that answers 500.
    • Register refuses a primary factor that shares its key with another Keyring's code factor. The same primary factor in two Keyrings is still allowed, because the tests build many apps in one process.
    • The challenge-page test for a primary factor's answer pins only "4xx, nobody signed in", not Rust's exact 422.
  • keyringtest review fixes:

    • The fake identity provider's Register resolves every host to nothing, as PHP's HostResolver::fake(). A dotted host counts as outside the network and a single-label host as inside.
    • The begins-enrolling conformance check uses one user per factor, so it doesn't hit the default form limit with more than six factors.
    • A virtual authenticator's origin defaults to the app's first WebAuthn origin once AddTo runs, and to http://localhost before that. PHP always asks the container.
  • Impersonation review fixes:

    • Sign-ins while impersonating follow PHP: every Keyring sign in, SignInAs included, ends the impersonation first, as signed_out, together with the parked session. Rust refuses with a 403 instead.
    • The app's own auth.Login as someone else while impersonating ends the impersonation as PHP's register() does. So do its own auth.Logout and emptying the session.
    • Impersonation.ShowInSessions is now *bool (nil means on), as Passwords.Uncompromised is, so assigning the whole struct no longer hides the session. Anyone who wrote = false must now write = new(false). ShowInActivity *bool is a slot nothing reads yet.
    • After a stop that signs out, the guard still holds the impersonated user for the rest of that request. Laravel Go can't forget the user without auth.Logout, which would rotate their remember token. This is documented, not fixed.
    • Rust's end_parked has the gap Go's now closes: it decides under the cache lock alone, where it needs holding_user_row and a re-check after the end. Worth taking to Rust.
  • Console-command review fixes:

    • A zero keep-for means its default, for all four settings (as SweepLimit), so a struct set whole can't wipe a table. Negative values are still refused.
    • An unknown end_reason announces as revoked, using PHP's list, including account_deleted.
    • The replica tests use two SQLite files, because laraveltest's RefreshDatabase drops read hosts.
    • Correction to the EndUnsavedSignIns entry above: a panic is a 500 whose session still saves, so only an unwritable store leaves a record to end.
  • Final review fixes:

    • keyring:install always asks for the user model's Updating hook when update-passwords or email-changes is on. PHP asks only when the model lacks HasKeyring, but Go can't see the app's model.
    • Status answers work out page from route names, as PHP's StatusResponse does. With Config.Routes off and no route named login, page is left out rather than claimed.
    • Parked impersonations, password holds and open sessions are read from the writer. PasswordChangeReason and RequirePasswordChange's existence check still use the default connection; a missed hold there only hits the unique index.
    • The starter kit's profile route refuses changes while impersonating, as Keyring's own change routes do.
  • Base merge and the email code's sign-in link (PHP feat(email-code): add an opt-in sign-in link and make the code easier for mail apps to find #160):

entity added 30 commits December 2, 2026 19:52
entity added 30 commits December 3, 2026 19:00
…ties when linking and primary keys shared with code factors, with the rust crate's missing tests
…ers, answer every refused sign in at once and check setups as php does
… ends and refusals, and end it on the app's own sign ins and sign outs
…ation, offer impersonation, and print settings that boot
…nd once the overlap has taken its cookies off
…zero keep-for at its default, and match php's sweep and import edges
…feat/laravel-go-support

# Conflicts:
#	CHANGELOG.md
#	contract/README.md
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