@happyvertical/smrt-users 0.62.4 → 0.62.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -18,6 +18,7 @@ are not prerequisites for unrelated user-package work.
18
18
  | `src/services/PasswordCredentialService.ts`, `src/sveltekit/password-handlers.ts` | email + password sign-in and password lifecycle (#3274); shared scrypt in `credential-hash.ts` | this file, "Security boundaries"; README "Password sign-in" |
19
19
  | `src/services/PasskeyCredentialService.ts`, `src/sveltekit/passkey-handlers.ts`, `src/svelte/passkey.ts` | passkey (WebAuthn) sign-in and passkey lifecycle (#3275); library does all verification | this file, "Security boundaries"; README "Passkey sign-in" |
20
20
  | `src/services/TenantInvitationService.ts`, `src/services/MailboxAuthenticationService.ts` | exact-role invitations, preserved identity, one-use generations and embedded transaction send budgets | [agents/family-invitations.md](agents/family-invitations.md) |
21
+ | `src/services/oauth-cimd.ts`, `src/services/oauth-cimd-fetch.ts` | opt-in Client ID Metadata Documents for the SDK OAuth server (#5081): required origin policy, SSRF-pinned fetch, cache | [agents/oauth-authorization.md](agents/oauth-authorization.md#client-id-metadata-documents-5081) |
21
22
  | `src/retention.ts` | expired session/token/CLI-auth reaping and retention sweep wiring | [agents/retention.md](agents/retention.md) |
22
23
 
23
24
  ## Models and authority
package/README.md CHANGED
@@ -731,7 +731,7 @@ generated RLS helpers:
731
731
 
732
732
  - `smrt.tenant_id`
733
733
  - `smrt.user_id`
734
- - `smrt.session_id`
734
+ - `smrt.session_id` (only for a loaded session; stays empty for principal runs, whose `sessionId` is an unverified label)
735
735
  - `smrt.permissions`
736
736
  - `smrt.super_admin_bypass`
737
737
  - `smrt.system_context`
@@ -2008,6 +2008,29 @@ never silently drops PRAGMAs or temporary state. PostgreSQL does not require
2008
2008
  this option. The [transaction notes](agents/oauth-authorization.md#recoverable-local-sqlite-connections)
2009
2009
  show the factory contract.
2010
2010
 
2011
+ ### Client ID Metadata Documents
2012
+
2013
+ To let hosts such as MCP clients connect with an HTTPS-URL `client_id` and no
2014
+ prior registration, create the server with `createCimdAuthorizationServer`
2015
+ (opt-in; omit `clientIdMetadataDocuments` and it is the plain SDK server):
2016
+
2017
+ ```typescript
2018
+ import { createCimdAuthorizationServer } from '@happyvertical/smrt-users';
2019
+
2020
+ const server = createCimdAuthorizationServer({
2021
+ /* ...the same options as createAuthorizationServer... */
2022
+ clientIdMetadataDocuments: {
2023
+ // Required. Deny by default: there is no implicit allow-all.
2024
+ allowClientOrigin: (origin) => ['https://chatgpt.com'].includes(origin),
2025
+ },
2026
+ });
2027
+ ```
2028
+
2029
+ Metadata is fetched through an SSRF-guarded, DNS-pinned, size- and time-bounded
2030
+ fetch, validated (public client, exact `redirect_uris`, no secrets), cached per
2031
+ its HTTP cache headers, and advertised as `client_id_metadata_document_supported`.
2032
+ See [OAuth authorization](agents/oauth-authorization.md#client-id-metadata-documents-5081).
2033
+
2011
2034
  ### HTTP CLI collection action discovery
2012
2035
 
2013
2036
  `createResourceListHandler` can discover custom actions on registered typed
@@ -44,6 +44,45 @@ by the SDK. Grant revocation POST has the same origin check and takes `grantId`.
44
44
  All account/consent responses use private, no-store. No handler authenticates a
45
45
  session from OAuth client identity or accepts a browser-submitted user/tenant.
46
46
 
47
+ ## Client ID Metadata Documents (#5081)
48
+
49
+ Opt-in, off by default, like `dynamicClientRegistration`. The SDK server
50
+ resolves clients only through `storage.getClient`, so
51
+ `createCimdAuthorizationServer({ ...sdkOptions, clientIdMetadataDocuments })`
52
+ (`src/services/oauth-cimd.ts`) wraps the storage and subclasses the server to
53
+ add `client_id_metadata_document_supported: true` to RFC 8414 metadata. Without
54
+ the option it returns the plain SDK server: https client_ids stay unknown,
55
+ nothing is fetched, nothing is advertised. `withClientIdMetadataDocuments`
56
+ composes the same decorator onto a storage directly.
57
+
58
+ - `allowClientOrigin(origin, clientId)` is REQUIRED; construction throws
59
+ without it (there is no implicit allow-all; pass `() => true` explicitly).
60
+ It runs on every request before the cache, so a policy change is immediate;
61
+ a throw or non-`true` result denies.
62
+ - client_id must be the canonical `https://` URL with a path, default port, no
63
+ credentials/fragment/query/dot segments, and a public DNS-style host (literal IPs,
64
+ single-label and `.local/.internal/.localhost`-style names are refused before
65
+ any network I/O).
66
+ - Fetch (`oauth-cimd-fetch.ts`): DNS resolved once, every address must be
67
+ public (non-global-unicast IPv6, private/loopback/link-local/CGNAT/metadata
68
+ IPv4 refused), connection pinned to the vetted address, redirects never
69
+ followed, 5 s deadline covering DNS and the request (also enforced around any injected fetcher), 16 KiB cap, at most 8 concurrent cache-miss fetches (`maxConcurrentFetches`; excess is refused as unknown client, not failure-cached), `application/json` or `+json` only,
70
+ identity encoding. content's `safe-remote-url` is not reused: users cannot
71
+ depend on content (heavy graph, content dev-depends on users).
72
+ - Document: `client_id` equals the URL; `redirect_uris` 1-10 https (loopback
73
+ http only with `allowLoopbackRedirects`); the authorization request's
74
+ `redirect_uri` must equal one entry exactly; `token_endpoint_auth_method`
75
+ absent or `none`; any `client_secret*` rejects; grant/response types limited
76
+ to `authorization_code`/`refresh_token`/`code`. Allowed scopes are the
77
+ document's `scope` intersected with the server's (all server scopes if
78
+ absent).
79
+ - Cache: in-memory, honours `s-maxage`/`max-age`/`Age`, clamped to 60 s..24 h
80
+ (so `no-store` still gets the floor, bounding outbound fetches), 1 h default,
81
+ 30 s negative cache, 1000 entries, concurrent lookups share one fetch. It is
82
+ per-process; replicas fetch independently.
83
+ - Every failure is "unknown client" to the requester; `onRejected(clientId,
84
+ reason)` is for operator logs only. Tests: `src/__tests__/oauth-cimd.test.ts`.
85
+
47
86
  ## Transaction invariants
48
87
 
49
88
  Code consume uses a conditional write. Refresh rotation and revocation lock a
@@ -249,3 +249,16 @@ custom-action receiver resolution and paths are unchanged. The existing resource
249
249
  handler suite retains positive and refusal coverage, and its fresh-Node published
250
250
  entry guard rejects Vite route-emitter/activation-generator loads. No SQL executor,
251
251
  transaction, authentication or tenant-boundary behavior changes in this import fix.
252
+
253
+ ## Agent users (#5086)
254
+
255
+ There is no agent column on `User`. A user is an agent when its linked
256
+ `Profile` has the `bot` profile type (`resolveAgentProfile` /
257
+ `AGENT_PROFILE_TYPE_SLUG` in `@happyvertical/smrt-profiles`); give it a
258
+ membership with a limited custom role like any member. MCP classifies the
259
+ principal from that live profile (`kind: 'agent'`), the default MCP policy
260
+ accepts the kind only when `principalKinds` lists it, and the role's
261
+ permissions cap what its tokens can do on every request. The profile models
262
+ refuse an unprivileged principal changing whether a profile is `bot` typed
263
+ (including by create or natural-key upsert) or creating/renaming the type, so an agent cannot relabel itself. See
264
+ `packages/app-runtime/agents/self-issuer-mcp.md`.