Registry Mirror
Skip to content

Conversation

@lakhansamani

@lakhansamani lakhansamani commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Authorizer signs asymmetric tokens (RS256/ES256) without a kid header, while /.well-known/jwks.json publishes its keys under a kid. JWKS consumers that select the verification key by kid reject the tokens outright. SurrealDB is one (DEFINE ACCESS ... WITH JWT URL):

Request authentication failed: Incorrect arguments for function token(). Missing token header 'kid'

So Authorizer currently cannot be used as a SurrealDB authentication provider, unlike Auth0 and AWS Cognito, which SurrealDB documents. Auth0, Okta and Cognito always set kid.

Fix

  • kid = the key's RFC 7638 JWK thumbprint (crypto.KeyID), used by both the signer (token.signJWTToken) and the JWKS handler, so the header and the JWKS entry agree by construction.
  • Derived from the key, not a label. Previously the JWKS used <client_id> for the primary key and <client_id>-secondary for the secondary. With label kids, demoting the old key during a rotation would give pre-rotation tokens a kid that now names the new key, and kid-strict verifiers would reject them until expiry. A thumbprint keeps the key's kid through the rotation.
  • HMAC tokens get no kid: their key is never published.

Behaviour change (release as a minor: v2.5.0)

JWKS kid values change from <client_id> / <client_id>-secondary to key thumbprints, and the docs promised the old values (oauth2-oidc.md, client-registry.md). Effect of upgrading:

Verifier Effect
Fetches /.well-known/jwks.json (most libraries, gateways, the Go example) No change. At most one extra JWKS fetch on the first new kid.
Strict-kid verifiers (SurrealDB) Start working; today they reject every token.
Pinned JWKS copy, or hard-coded kid == client_id Old tokens keep working; tokens issued after the upgrade are rejected until the verifier fetches the endpoint.
Another Authorizer trusting this one's client assertions No gap: it now refetches on an unknown kid (second commit).

Nothing changes inside Authorizer: it never reads the header kid when verifying its own tokens, so no session, refresh token or login is affected.

Release note: Tokens now carry a kid header, and JWKS kids are RFC 7638 key thumbprints instead of the client ID. If you pinned a copy of the JWKS or hard-coded the client ID as the kid, switch to fetching /.well-known/jwks.json before upgrading.

Docs: authorizerdev/docs#99 (draft; merge with the release).

Unknown-kid refetch (second commit)

The client-assertion verifier cached a trusted issuer's JWKS for 10 minutes with no refetch, so an issuer that rotated or re-labelled its keys was rejected until expiry. An unknown kid now triggers one cache-bypassing refetch, rate-limited to one per issuer per 60s via SetCacheNX, because anyone can send a made-up kid.

Tests

  • TestJWTHeaderKidMatchesJWKS (RS256, ES256): the header kid exists and equals the published key's kid.
  • TestJWTKidSurvivesKeyRotation: after new key → primary and old key → secondary, a token signed before the rotation still names a published key.
  • TestJWTHMACHasNoKid.
  • TestClientAssertion_UnknownKidRefetchesJWKS: models an issuer re-labelling its keys while cached. Accepted after exactly one refetch, and the refreshed set is cached.
  • TestClientAssertion_UnknownKidRefetchIsRateLimited: 20 bogus kids cost one extra fetch; legitimate assertions still verify.
  • All new tests failed before their fix. All existing JWKS tests pass unchanged.
  • make test, make smoke, go vet ./..., make lint-go: all pass.

End-to-end check with SurrealDB 4.0.1

Authorizer (this branch) with a custom access token script adding ns/db/ac, and SurrealDB with DEFINE ACCESS authorizer ... WITH JWT URL "<authorizer>/.well-known/jwks.json":

  • Works: a signed-in user's token authenticates and $auth resolves to their record. Table permissions isolate users, and permissions on the roles claim work.
  • Rejected: tampered signature, edited claims, alg=none, and an HS256 forgery reusing the real kid.
  • Unpatched main: every request is refused with the missing-kid error above.

lakhansamani added a commit to authorizerdev/docs that referenced this pull request Nov 20, 2026
… v2.5.0)

New integrations/surrealdb page: custom access token script for the
ns/db/ac claims, DEFINE ACCESS ... WITH JWT URL against Authorizer's
JWKS, per-user and role-based permissions, SDK and HTTP usage, and the
allow-net / revocation / rotation caveats. Depends on the kid header
from authorizerdev/authorizer#904.

Also keeps the guide drafted for SurrealDB's own docs under
specs/surrealdb-integration until it is submitted upstream.
Tokens were signed without a kid header while /.well-known/jwks.json
published keys under a kid. JWKS consumers that select the key by kid
reject such tokens; SurrealDB's DEFINE ACCESS ... WITH JWT URL fails
every request with "Missing token header 'kid'", so Authorizer could
not be used as a SurrealDB authentication provider.

The kid is now the key's RFC 7638 thumbprint (crypto.KeyID), used by
both the signer and the JWKS handler, so they agree by construction.
It is derived from the key rather than a label (previously client_id /
client_id-secondary), so a key keeps its kid through a primary ->
secondary rotation and tokens signed before the rotation still name a
published key. HMAC tokens get no kid: their key is never published.

Tests: kid present and matching JWKS for RS256 and ES256; a
pre-rotation token's kid is still published after rotation; HMAC has
no kid. Existing JWKS tests unchanged and passing; make test and
make smoke pass. Verified end to end against SurrealDB 4.0.1.
The client-assertion verifier cached an issuer's JWKS for 10 minutes and
rejected any assertion whose kid the cached set lacked. An issuer that
re-labels its keys (Authorizer itself, with the thumbprint kids in this
PR) or rotates them was therefore rejected until the cache expired.

An unknown kid now triggers one refetch that bypasses the cache. The
refetch is attacker-triggerable, so it is rate-limited to one per issuer
per 60s via SetCacheNX (shared across replicas, like jti replay).

Also corrects the BC1 comment on schemas.Client: JWKS kids no longer key
on the client ID.
@lakhansamani
lakhansamani merged commit ac55cda into main Nov 24, 2026
5 checks passed
@lakhansamani
lakhansamani deleted the fix/jwt-kid-header branch November 24, 2026 08:27
lakhansamani added a commit to authorizerdev/docs that referenced this pull request Nov 24, 2026
…storage + integration (#99)

* docs: JWKS kid is the key thumbprint and is stamped on tokens (v2.5.0)

Documents authorizerdev/authorizer#904: every RSA/ECDSA token carries a
kid header equal to its signing key's RFC 7638 thumbprint, which is also
the key's kid in /.well-known/jwks.json (previously the client ID, and
tokens had no kid). Adds an upgrade note for verifiers that pinned a JWKS
copy or hard-coded the client ID as the kid, and explains why rotation
now keeps working for kid-strict verifiers.

* docs: SurrealDB integration (Authorizer as SurrealDB's auth provider, v2.5.0)

New integrations/surrealdb page: custom access token script for the
ns/db/ac claims, DEFINE ACCESS ... WITH JWT URL against Authorizer's
JWKS, per-user and role-based permissions, SDK and HTTP usage, and the
allow-net / revocation / rotation caveats. Depends on the kid header
from authorizerdev/authorizer#904.

Also keeps the guide drafted for SurrealDB's own docs under
specs/surrealdb-integration until it is submitted upstream.

* docs: SurrealDB storage backend (v2.5.0)

databases: SurrealDB entry (flags, 4.0+, http(s) recommended, namespace
and credential levels, own migrations, --fga-store). server-config: type
list and --surrealdb-namespace. helm-chart, introduction: lists.
integrations/surrealdb: Authorizer can store its own data in the same
SurrealDB.

* docs: client_id in access tokens (RFC 9068) and azp in ID tokens (v2.5.0)

authorizerdev/authorizer#913. Token claims table, discovery claims_supported,
client_credentials client_id/aud, standards table, and the testing checklist.

* docs: these changes ship in 2.4.8, not 2.5.0

* docs(surrealdb): allowed-origins and MFA notes from an end-to-end re-run on 2.4.8

Re-ran the guide against SurrealDB 4.0.1 and Authorizer main (c83107c8).
Upstream guide moves to position 14 (11 is Auth0).

* docs(surrealdb): correct rotation, allowed-origins and signing-key statements

Re-verified against Authorizer 2.4.8 and SurrealDB 4.0.1:
- SurrealDB's JWKS cache refuses a new key's tokens for up to 5 minutes
  after a rotation and keeps a removed key for up to 12 hours.
- With --allowed-origins=* only Authorizer's own origin may sign in.
- --jwt-type has no default; RS256/ES256 is required for SurrealDB.
- Access token lifetime is a fixed 30 minutes; the JWKS failure reason is
  logged at WARN.
The specs copy of the upstream guide matches surrealdb/docs.surrealdb.com#2231.
lakhansamani added a commit that referenced this pull request Nov 27, 2026
Black-box, against the real binary:
- GHSA-p7g3-2258-8wmp: org A's SCIM PATCH of a shared user's userName,
  emails, phoneNumbers (and a mixed PatchOp) is refused with 400/mutability
  and writes nothing; the reset cannot reach the attacker's mailbox;
  case-only and single-org changes still sync.
- #904: RS256/ES256 tokens carry a kid equal to the RFC 7638 thumbprint of
  a JWKS key that verifies them, including a pre-rotation token after a
  primary-to-secondary rotation; HS256 tokens have no kid.
- #913: client_id on access tokens and azp == aud on ID tokens from the
  authorization_code, refresh_token and client_credentials grants.
- #903: list_permissions with cap+1 grants returns cap results and
  truncated=true on GraphQL, REST and gRPC; under the cap, false.
lakhansamani added a commit that referenced this pull request Nov 27, 2026
* test(e2e): smoke coverage for 2.4.9 fixes

Black-box release smoke tests against the real binary for the 2.4.9 fixes:

- GHSA-rpv7-grw6-r2jv: a wrong-password login to an unverified account
  arms an MFA session that skip_mfa_setup, lock_mfa, totp/email OTP setup
  and webauthn registration options must all reject on GraphQL, REST and
  gRPC; the emailed OTP (read from an in-test SMTP sink) still completes
  login via verify_otp.
- #922: restart on the same DB with a role removed from --roles; login,
  validate_jwt_token on an old token and the refresh grant stop honouring it.
- #924/#932: a fake Redis that errors after the startup PING; revoke returns
  a masked internal error with an error_id on every surface, and that id is
  logged next to the original error.
- #927: admin users sort/filter return identical ordered results on
  GraphQL, REST and gRPC.

startServer gains a startServerWithLog variant that returns the log path.

* test(e2e): smoke coverage for 2.4.7 and 2.4.8 fixes

Black-box, against the real binary:
- GHSA-p7g3-2258-8wmp: org A's SCIM PATCH of a shared user's userName,
  emails, phoneNumbers (and a mixed PatchOp) is refused with 400/mutability
  and writes nothing; the reset cannot reach the attacker's mailbox;
  case-only and single-org changes still sync.
- #904: RS256/ES256 tokens carry a kid equal to the RFC 7638 thumbprint of
  a JWKS key that verifies them, including a pre-rotation token after a
  primary-to-secondary rotation; HS256 tokens have no kid.
- #913: client_id on access tokens and azp == aud on ID tokens from the
  authorization_code, refresh_token and client_credentials grants.
- #903: list_permissions with cap+1 grants returns cap results and
  truncated=true on GraphQL, REST and gRPC; under the cap, false.

* test(e2e): opt-in make smoke-db for SereneDB, SurrealDB and SQL Server

`make smoke-db DB=serenedb|surrealdb|sqlserver` starts the database in
Docker and runs TestReleaseSmokeDB against the real binary: signup, login,
session, refresh grant, admin users list, forgot_password and
resend_verify_email twice with the superseding link redeemed, and MFA
enrollment twice plus a concurrent burst. The repeated forgot_password
fails with INTERNAL on SQL Server without the 2.4.7 conflict-target fix.

Skipped unless SMOKE_DB_ARGS is set, so `make smoke` stays SQLite-only
and needs no Docker.

* test(e2e): build the smoke binary once; unique smoke-db run ids; review nits
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