@ultimat3/auth 31.42.1 → 31.43.0

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/README.md CHANGED
@@ -660,7 +660,9 @@ zero. Registration asks `attestation: 'none'` and trusts no statement. Which che
660
660
  OAuth 2.1 server: authorization code + PKCE (S256 only), refresh rotation with replay revocation,
661
661
  `client_credentials`, the device grant, RFC 7009/7662/7591/8414/8707/9207. `routes` go in
662
662
  `runtime.routes`; the consent and device pages are the app's (`readRequest`/`approve`/`deny`,
663
- `readDevice`/`approveDevice`/`denyDevice`). `oauthBearerResolver(server, { actor, resource? })` is
663
+ `readDevice`/`approveDevice`/`denyDevice`); the consent page reads with
664
+ `readRequest(url, { callerKey })` — every metadata-document fetch is metered, and an absent
665
+ `callerKey` shares one bucket with every other unkeyed read. `oauthBearerResolver(server, { actor, resource? })` is
664
666
  the `resolveToken`. Stores: `memoryAuthServerStore()`, `postgresAuthServerStore({ executor })`
665
667
  over `SQL_AUTH_SERVER_TABLES`, which the boot applies. A code is spent only by a request that could
666
668
  redeem it: client, PKCE verifier, `redirect_uri` and `resource` are checked on `getCode` before
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/auth",
3
- "version": "31.42.1",
3
+ "version": "31.43.0",
4
4
  "description": "Sessions, passwords, OAuth, MFA and api keys — resolved to one Actor",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -50,8 +50,8 @@
50
50
  "test": "bun test"
51
51
  },
52
52
  "dependencies": {
53
- "@ultimat3/core": "31.42.1",
54
- "@ultimat3/db": "31.42.1",
55
- "@ultimat3/schema": "31.42.1"
53
+ "@ultimat3/core": "31.43.0",
54
+ "@ultimat3/db": "31.43.0",
55
+ "@ultimat3/schema": "31.43.0"
56
56
  }
57
57
  }
@@ -24,6 +24,11 @@ const CLIENT_METADATA_CACHE_MAX = 1_000;
24
24
  * is waiting. A retry would also multiply every metered fetch by the vendor's attempt count.
25
25
  */
26
26
  const ONE_ATTEMPT = Object.freeze({ attempts: 1, base: 0, max: 0, jitter: 'none' as const });
27
+ /**
28
+ * The bucket every fetch naming no caller shares: leaving `callerKey` out is metered, never free —
29
+ * one key for all of them, so an unkeyed consent page is throttled as one caller.
30
+ */
31
+ const UNKEYED_CALLER = 'unkeyed';
27
32
  const LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]']);
28
33
 
29
34
  /**
@@ -69,9 +74,10 @@ function clientFromDocument(clientId: string, body: unknown, at: Date): AuthServ
69
74
 
70
75
  export interface ClientDirectory {
71
76
  /**
72
- * `callerKey` (the caller's address) meters metadata fetches through `config.limiter`: an
73
- * unauthenticated POST naming `https://<anyone>/<path>` would otherwise be one outbound GET per
74
- * path. Rejects with `X_ACCOUNT_LOCKED` once the caller is over the limit.
77
+ * Every metadata fetch is metered through `config.limiter`: an unauthenticated request naming
78
+ * `https://<anyone>/<path>` would otherwise be one outbound GET per path. `callerKey` (the
79
+ * caller's address) is the bucket; absent, every unkeyed fetch shares ONE bucket. Rejects with
80
+ * `X_ACCOUNT_LOCKED` once the bucket is over the limit.
75
81
  */
76
82
  find(clientId: string, callerKey?: string): Promise<AuthServerClient | null>;
77
83
  }
@@ -97,7 +103,7 @@ export function clientDirectory(config: ResolvedAuthServerConfig): ClientDirecto
97
103
  const nowMs = config.clock.now().getTime();
98
104
  const hit = cache.get(clientId);
99
105
  if (hit !== undefined && hit.untilMs > nowMs) return hit.client;
100
- if (callerKey !== undefined) await config.limiter.reserve(`oauth-client-metadata:${callerKey}`);
106
+ await config.limiter.reserve(`oauth-client-metadata:${callerKey ?? UNKEYED_CALLER}`);
101
107
  let client: AuthServerClient | null = null;
102
108
  try {
103
109
  const answer = await outbound(
@@ -37,8 +37,9 @@ export interface AuthorizationServer {
37
37
  readonly metadata: Readonly<Record<string, unknown>>;
38
38
  /**
39
39
  * The consent page's read of its own URL: what to show, or the refusal to show instead.
40
- * `callerKey` (the request's address) meters a metadata-document fetch per caller, as the token
41
- * route does — a page load naming `https://<anyone>/<path>` is otherwise one outbound GET each.
40
+ * Call it as `readRequest(url, { callerKey: <the request's address> })`: a metadata-document
41
+ * fetch is metered per caller, as the token route does. Left out, every unkeyed read shares ONE
42
+ * bucket — still metered, but one visitor's burst locks the consent page for all of them.
42
43
  */
43
44
  readRequest(url: string | URL, options?: ReadRequestOptions): Promise<ReadRequestResult>;
44
45
  /** The consent action's approval: the redirect URL carrying `code`, `state` and `iss`. */
@@ -78,7 +79,7 @@ export interface AuthorizationServer {
78
79
  }
79
80
 
80
81
  export interface ReadRequestOptions {
81
- /** The caller's address: the limiter key for a metadata-document fetch. */
82
+ /** The caller's address: the limiter key for a metadata-document fetch. Absent: one shared key. */
82
83
  readonly callerKey?: string | undefined;
83
84
  }
84
85