@adonis-agora/authkit-poppy 1.0.0-rc.6 → 1.0.0-rc.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @adonis-agora/authkit-poppy
2
2
 
3
+ ## 1.0.0-rc.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0c4c958`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/0c4c95895572969cd6dc915a3a2b862a75c834fb) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Poppy's default in-memory rate limiter now has a hard cap (100 000 windows, oldest evicted first) and drops expired windows as it goes, so a stream of new identifiers on Mediated Sign-In can no longer grow it without bound.
8
+
9
+ The unauthenticated OAuth endpoints agents call server-to-server now sit behind a per-IP throttle by default (new `agentToken` bucket, 120/min, plain 429; off with the existing `rateLimit: { enabled: false }`): Poppy's `{prefix}/oauth/token`, `oauth/device`, `oauth/par` and `oauth/revoke`, and authkit-server's personal-agents `{personalAgents.prefix}/oauth/token` and `oauth/device_authorization`. Personal-agent extensions get the bucket as `kit.throttle.token(route)`.
10
+
11
+ The OIDC provider's own machine endpoints get the same treatment: inside the `${mountPath}/*` catch-all, only the POSTs to token, dynamic registration, device authorization, PAR, revocation, introspection and CIBA (paths read from the provider via `pathFor`, so custom `routes` and the issuer mount apply; disabled features are skipped) go through a new per-IP `oidcToken` bucket (120/min, plain 429). Authorize, userinfo, JWKS, discovery, end-session and the device code screen are never throttled. Poppy's `POST {prefix}/browser-session` now uses the login bucket, like its page. All of it is off with `rateLimit: { enabled: false }`.
12
+
3
13
  ## 1.0.0-rc.6
4
14
 
5
15
  ### Minor Changes
@@ -42,11 +42,14 @@ function registerRoutes(router, prefix, kit) {
42
42
  router
43
43
  .get(`${prefix}/.well-known/oauth-authorization-server`, [PoppyController, 'metadata'])
44
44
  .as('authkit.poppy.metadata_under_issuer');
45
- router.post(`${prefix}/oauth/token`, [PoppyController, 'token']).as('authkit.poppy.token');
46
- router.post(`${prefix}/oauth/revoke`, [PoppyController, 'revoke']).as('authkit.poppy.revoke');
47
- router
45
+ // Os endpoints OAuth de máquina não têm sessão e o registro de client não é obrigatório:
46
+ // throttle por IP (antes do limite por agente, que é por identificador — um e-mail novo por
47
+ // pedido nunca bateria nele).
48
+ kit.throttle.token(router.post(`${prefix}/oauth/token`, [PoppyController, 'token']).as('authkit.poppy.token'));
49
+ kit.throttle.token(router.post(`${prefix}/oauth/revoke`, [PoppyController, 'revoke']).as('authkit.poppy.revoke'));
50
+ kit.throttle.token(router
48
51
  .post(`${prefix}/oauth/par`, [PoppyController, 'pushedAuthorization'])
49
- .as('authkit.poppy.par');
52
+ .as('authkit.poppy.par'));
50
53
  router.get(`${prefix}/tasks`, [PoppyController, 'tasks']).as('authkit.poppy.tasks');
51
54
  router.post(`${prefix}/feedback`, [PoppyController, 'feedback']).as('authkit.poppy.feedback');
52
55
  router
@@ -55,16 +58,17 @@ function registerRoutes(router, prefix, kit) {
55
58
  router
56
59
  .get(`${prefix}/versions/:file`, [PoppyController, 'versionDocument'])
57
60
  .as('authkit.poppy.version_document');
58
- router
61
+ kit.throttle.token(router
59
62
  .post(`${prefix}/oauth/device`, [PoppyController, 'deviceAuthorization'])
60
- .as('authkit.poppy.device_authorization');
63
+ .as('authkit.poppy.device_authorization'));
61
64
  // A página grava um pedido sem autenticação: throttle por IP.
62
65
  kit.throttle.login(router
63
66
  .get(`${prefix}/browser-session`, [PoppyController, 'browserSessionPage'])
64
67
  .as('authkit.poppy.browser_session_page'));
65
- router
68
+ // O navegador submete o código sem sessão: o mesmo throttle por IP da página (bucket de login).
69
+ kit.throttle.login(router
66
70
  .post(`${prefix}/browser-session`, [PoppyController, 'browserSession'])
67
- .as('authkit.poppy.browser_session');
71
+ .as('authkit.poppy.browser_session'));
68
72
  router
69
73
  .post(`${prefix}/browser-session/authorize`, [PoppyController, 'browserSessionAuthorize'])
70
74
  .as('authkit.poppy.browser_session_authorize');
@@ -20,8 +20,18 @@ table?: (name: string) => string, options?: {
20
20
  export declare function redisReplayStore(redis: {
21
21
  set: (...args: any[]) => Promise<unknown>;
22
22
  }): PoppyReplayStore;
23
- /** Janelas fixas em memória, por processo: `sessionsPerMinute` por agente, `mediatedPerHour` por (agente, usuário). */
23
+ /**
24
+ * Janelas fixas em memória, por processo: `sessionsPerMinute` por agente, `mediatedPerHour` por
25
+ * (agente, usuário). Só serve com uma instância — com várias, passe um `rateLimit` próprio.
26
+ *
27
+ * A chave do Mediated Sign-In vem do identificador que o agente digita, então cada e-mail novo é
28
+ * uma entrada nova: o mapa tem teto (`max`, default 100 000). Janelas vencidas saem aos poucos e,
29
+ * no teto, a mais antiga sai primeiro — como no `memoryReplayStore`.
30
+ */
24
31
  export declare function memoryLimiter(limits: {
25
32
  sessionsPerMinute: number;
26
33
  mediatedPerHour: number;
27
- }, now?: () => number): PoppyLimiter;
34
+ }, options?: {
35
+ max?: number;
36
+ now?: () => number;
37
+ }): PoppyLimiter;
@@ -81,24 +81,41 @@ export function redisReplayStore(redis) {
81
81
  },
82
82
  };
83
83
  }
84
- /** Janelas fixas em memória, por processo: `sessionsPerMinute` por agente, `mediatedPerHour` por (agente, usuário). */
85
- export function memoryLimiter(limits, now = Date.now) {
84
+ /**
85
+ * Janelas fixas em memória, por processo: `sessionsPerMinute` por agente, `mediatedPerHour` por
86
+ * (agente, usuário). Só serve com uma instância — com várias, passe um `rateLimit` próprio.
87
+ *
88
+ * A chave do Mediated Sign-In vem do identificador que o agente digita, então cada e-mail novo é
89
+ * uma entrada nova: o mapa tem teto (`max`, default 100 000). Janelas vencidas saem aos poucos e,
90
+ * no teto, a mais antiga sai primeiro — como no `memoryReplayStore`.
91
+ */
92
+ export function memoryLimiter(limits, options = {}) {
93
+ const max = options.max ?? 100_000;
94
+ if (!Number.isInteger(max) || max < 1) {
95
+ throw new Error(`[authkit-poppy] memoryLimiter: max must be a positive integer (got ${max}).`);
96
+ }
97
+ const now = options.now ?? Date.now;
98
+ // Ordem de inserção = ordem de abertura da janela (uma janela nova é reinserida no fim).
86
99
  const windows = new Map();
100
+ let calls = 0;
87
101
  return async ({ action, key }) => {
88
102
  const [limit, windowMs] = action === 'session'
89
103
  ? [limits.sessionsPerMinute, 60_000]
90
104
  : [limits.mediatedPerHour, 3_600_000];
91
105
  const t = now();
106
+ if (++calls % 1000 === 0 || windows.size >= max) {
107
+ for (const [k, v] of windows)
108
+ if (t - v.start >= v.windowMs)
109
+ windows.delete(k);
110
+ }
92
111
  const id = `${action}:${key}`;
93
112
  let w = windows.get(id);
94
113
  if (!w || t - w.start >= windowMs) {
95
- w = { start: t, count: 0 };
114
+ windows.delete(id);
115
+ while (windows.size >= max)
116
+ windows.delete(windows.keys().next().value);
117
+ w = { start: t, windowMs, count: 0 };
96
118
  windows.set(id, w);
97
- if (windows.size > 50_000) {
98
- for (const [k, v] of windows)
99
- if (t - v.start >= 3_600_000)
100
- windows.delete(k);
101
- }
102
119
  }
103
120
  if (w.count >= limit)
104
121
  return Math.ceil((w.start + windowMs - t) / 1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-poppy",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.7",
4
4
  "description": "Personal Agent Protocol (\"Poppy\") for AuthKit: discovery, signed Poppy-Session agent sessions, Direct/Device/Mediated sign-in, MCP and browser sessions — an optional extension of @adonis-agora/authkit-server.",
5
5
  "license": "MIT",
6
6
  "author": "dudousxd",
@@ -40,7 +40,7 @@
40
40
  "node": ">=24"
41
41
  },
42
42
  "peerDependencies": {
43
- "@adonis-agora/authkit-server": "^1.0.0-rc.52",
43
+ "@adonis-agora/authkit-server": "^1.0.0-rc.54",
44
44
  "@adonisjs/core": "^7.5.0",
45
45
  "@adonisjs/session": "^8.1.0",
46
46
  "@adonisjs/shield": "^9.0.0"
@@ -49,11 +49,11 @@
49
49
  "jose": "6.2.18"
50
50
  },
51
51
  "devDependencies": {
52
- "@adonis-agora/authkit-server": "1.0.0-rc.52",
52
+ "@adonis-agora/authkit-server": "1.0.0-rc.54",
53
53
  "@adonisjs/core": "7.6.0",
54
54
  "@adonisjs/lucid": "22.4.2",
55
55
  "@adonisjs/session": "8.3.0",
56
- "@adonisjs/shield": "9.0.0",
56
+ "@adonisjs/shield": "9.0.1",
57
57
  "@adonisjs/tsconfig": "2.0.0",
58
58
  "@japa/assert": "4.2.0",
59
59
  "@japa/runner": "5.4.0",