@nifrajs/auth 5.0.0 → 5.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,373 @@
1
+ # @nifrajs/auth
2
+
3
+ ## 5.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 9498cf8: The package ships its `CHANGELOG.md`, so the installed package has the notes for every version, as the GitHub release does. Before, the tarball held only the code, `README.md`, `LICENSE` and `package.json`.
8
+
9
+ ## 5.1.0
10
+
11
+ ### Patch Changes
12
+
13
+ - efd2102: `createSessions` no longer accepts a session cookie signed in the pre-5.0 form (without the cookie name in the signature) unless you pass the new `acceptLegacyCookies: true`. Before, that fallback was always on, so any value the app signed with the session secret through `@nifrajs/core`'s `signValue` that parsed as a cookie-mode session (a signed preference cookie built from a form field, say) read as a session of the attacker's choosing, with an expiry of its own. A cookie-mode session's expiry is now also capped at `now + maxAge` on load, so no cookie can name a longer life. Migration: if you are upgrading from 4.x, or from 5.0 with sessions that have not been committed since, set `acceptLegacyCookies: true` to keep those users signed in, and remove it once one `maxAge` (7 days by default) has passed; each such session is re-signed in the current form on its next commit. Without it, those users are signed out once.
14
+
15
+ ## 5.0.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 7a169c9: The session guards take `unauthenticated: { status, body, headers }` to set the response they deny a missing session with, in place of the default `401` JSON: `requireSession` and `requireUser` in `@nifrajs/auth`, `requireSession`, `requirePrincipal` and `authed` in `@nifrajs/better-auth`, and `requireAuthUser` in `@nifrajs/authjs`. The status must be 400-599, and a guard given both `redirectTo` and `unauthenticated` throws. `UnauthenticatedResponse` is exported from each package.
20
+
21
+ ### Patch Changes
22
+
23
+ - 2e331b1: Session cookies are now signed together with their cookie name, so when two session managers share a secret, a cookie issued by one no longer verifies as the other's. Cookies signed by earlier versions still load and are re-signed on their next commit, so upgrading signs no one out.
24
+ - 8606fa4: `csrf()` (middleware and auth) accepts a same-origin HTML form POST sent under `Referrer-Policy: no-referrer`, which `securityHeaders()` sets by default. Such a form arrives with `Origin: null`, and every one was refused with 403. A request with `Origin: null` now passes only when the browser's own `Sec-Fetch-Site` header says `same-origin`, and only in the default same-origin mode; an explicit `origins` allowlist still refuses it.
25
+ - Updated dependencies [a0a02f4]
26
+ - Updated dependencies [0aed425]
27
+ - Updated dependencies [eaf030b]
28
+ - Updated dependencies [7de0397]
29
+ - Updated dependencies [4199ff3]
30
+ - Updated dependencies [90d9ee6]
31
+ - Updated dependencies [364a234]
32
+ - Updated dependencies [c06cba5]
33
+ - Updated dependencies [f4d3852]
34
+ - Updated dependencies [4a82ae0]
35
+ - Updated dependencies [0ff867a]
36
+ - Updated dependencies [e7391bf]
37
+ - Updated dependencies [0b80a59]
38
+ - Updated dependencies [c64db12]
39
+ - Updated dependencies [3753104]
40
+ - Updated dependencies [4b3b1fa]
41
+ - Updated dependencies [3562557]
42
+ - Updated dependencies [53087f3]
43
+ - Updated dependencies [2def6c7]
44
+ - Updated dependencies [b5b5bc3]
45
+ - Updated dependencies [22e1777]
46
+ - Updated dependencies [3a483cd]
47
+ - Updated dependencies [35f52c7]
48
+ - Updated dependencies [343cb81]
49
+ - Updated dependencies [d91fd44]
50
+ - Updated dependencies [b13e071]
51
+ - Updated dependencies [077657f]
52
+ - Updated dependencies [a5963cb]
53
+ - Updated dependencies [05aac0e]
54
+ - Updated dependencies [1a6616f]
55
+ - Updated dependencies [7775c2b]
56
+ - Updated dependencies [846e2f6]
57
+ - Updated dependencies [aadd9fc]
58
+ - Updated dependencies [ea16748]
59
+ - Updated dependencies [fc0284a]
60
+ - Updated dependencies [5b22f4d]
61
+ - Updated dependencies [1b94593]
62
+ - Updated dependencies [9f58295]
63
+ - Updated dependencies [b9608ac]
64
+ - Updated dependencies [7a165de]
65
+ - Updated dependencies [4064f36]
66
+ - Updated dependencies [48aad8c]
67
+ - Updated dependencies [41050ed]
68
+ - Updated dependencies [fc837cb]
69
+ - Updated dependencies [b80ce77]
70
+ - Updated dependencies [9b1acc9]
71
+ - Updated dependencies [740109f]
72
+ - Updated dependencies [e0a25fe]
73
+ - Updated dependencies [3630b6e]
74
+ - Updated dependencies [1290c6d]
75
+ - Updated dependencies [d0a7d58]
76
+ - @nifrajs/core@5.0.0
77
+
78
+ ## 4.0.2
79
+
80
+ ## 4.0.1
81
+
82
+ ## 4.0.0
83
+
84
+ ### Patch Changes
85
+
86
+ - 6daaa05: Each guard you build is its own plugin: `bearer()`, `basicAuth()`, `jwt()`, `ipRestriction()`, `rateLimit()`, `csrf()` and `bodyLimit()`. A second, stricter one before later routes or inside a `group()` applies alongside the first. The same instance passed to `use()` twice still applies once.
87
+ - 8e52704: fix(middleware, auth): CSRF behind TLS proxies, CORS caching, and token parsing
88
+
89
+ The CSRF same-origin default in `csrf()` from both packages accepts an `https:` Origin on an `http:`
90
+ request URL, which is what a TLS-terminating proxy presents. A downgrade or another host is still
91
+ rejected.
92
+
93
+ `cors()` with an allowlist or predicate sends `Vary: Origin` on every response, including ones that
94
+ carry no `Access-Control-Allow-Origin`. An existing `Origin` member is not repeated, and `Vary: *` is
95
+ kept as it is.
96
+
97
+ `jwt()` and `verifyCsrfToken()` accept only canonical base64url signatures. `jwt()` and `bearer()`
98
+ match the `Bearer` auth-scheme case-insensitively.
99
+
100
+ - Updated dependencies [dde125b]
101
+ - Updated dependencies [72b62fa]
102
+ - Updated dependencies [aa44e93]
103
+ - Updated dependencies [4a3ee60]
104
+ - Updated dependencies [aad6297]
105
+ - Updated dependencies [dad0d41]
106
+ - Updated dependencies [538adc2]
107
+ - Updated dependencies [f47edd1]
108
+ - Updated dependencies [df9530a]
109
+ - Updated dependencies [3e6973f]
110
+ - Updated dependencies [25e8edf]
111
+ - Updated dependencies [2b5e5fc]
112
+ - Updated dependencies [3b090de]
113
+ - Updated dependencies [da7d792]
114
+ - Updated dependencies [612a296]
115
+ - Updated dependencies [fb14dfa]
116
+ - Updated dependencies [8ae97f6]
117
+ - Updated dependencies [4af6f39]
118
+ - Updated dependencies [ca8b50d]
119
+ - Updated dependencies [b00a889]
120
+ - Updated dependencies [b53d64f]
121
+ - Updated dependencies [66fd712]
122
+ - Updated dependencies [9c3d524]
123
+ - Updated dependencies [738e7a1]
124
+ - Updated dependencies [4801cac]
125
+ - Updated dependencies [1b2d53a]
126
+ - Updated dependencies [25fe13d]
127
+ - Updated dependencies [0852290]
128
+ - Updated dependencies [0589dbe]
129
+ - Updated dependencies [2e2d8c0]
130
+ - Updated dependencies [856f5ce]
131
+ - Updated dependencies [18aa5aa]
132
+ - Updated dependencies [cfd86b3]
133
+ - Updated dependencies [8ff96c9]
134
+ - Updated dependencies [4c46199]
135
+ - Updated dependencies [eef4932]
136
+ - Updated dependencies [6de8686]
137
+ - Updated dependencies [d7892ea]
138
+ - Updated dependencies [4936309]
139
+ - Updated dependencies [ff5a779]
140
+ - Updated dependencies [bbdc5a1]
141
+ - Updated dependencies [10bc446]
142
+ - Updated dependencies [e8270d9]
143
+ - Updated dependencies [ff4a062]
144
+ - Updated dependencies [43ba944]
145
+ - Updated dependencies [46c741a]
146
+ - Updated dependencies [7bfa25e]
147
+ - Updated dependencies [4936309]
148
+ - Updated dependencies [6e257a6]
149
+ - Updated dependencies [4a03d30]
150
+ - Updated dependencies [8e30090]
151
+ - Updated dependencies [28f3aaf]
152
+ - Updated dependencies [6d20355]
153
+ - Updated dependencies [6907cbe]
154
+ - Updated dependencies [b64c3ee]
155
+ - Updated dependencies [bda9637]
156
+ - Updated dependencies [81c720e]
157
+ - Updated dependencies [ed60b23]
158
+ - Updated dependencies [a158b74]
159
+ - Updated dependencies [ff25d68]
160
+ - @nifrajs/core@4.0.0
161
+
162
+ ## 3.5.0
163
+
164
+ ### Patch Changes
165
+
166
+ - d5b7c22: Harden request boundaries, error handling, resource limits, signing, and cross-runtime adapters for safer production releases.
167
+
168
+ ## 3.4.0
169
+
170
+ ## 3.3.0
171
+
172
+ ## 3.2.0
173
+
174
+ ### Patch Changes
175
+
176
+ - 7551709: Harden runtime boundaries and defaults: clean up subprocess abort listeners, support short Cloudflare
177
+ KV sessions, bound and incrementally sweep the default memory cache, make image reads and cancellation
178
+ safe, emit content-derived image validators, require trusted forwarded hosts, avoid caching dynamic SSR
179
+ metadata, and reject invalid upload or image limits.
180
+
181
+ ## 3.1.0
182
+
183
+ ## 3.0.0
184
+
185
+ ### Minor Changes
186
+
187
+ - 99fc683: A thrown `status(...)` now costs close to what a returned one costs, and the guards throw one.
188
+
189
+ `status(...)` is meant to be **returned** - from a `beforeHandle`, from a `derive`, from the handler. The one place a return cannot work is a helper called for effect: `requireSession(c)` decides the request is over from inside a call the handler makes, and only unwinding gets out of a half-finished handler. That is the whole remaining use of `throw`, and it now runs on the same lane as the return:
190
+
191
+ - The lifecycle error path is synchronous again. It was `async`, so a thrown `status(...)` - which needs no `await` at all - still allocated a promise and resumed a microtask later. The `onError` hook loop moved to its own async method, so only routes that registered a hook pay for one.
192
+ - The two remaining sites that turned a thrown `status(...)` into a `Response` before rendering it (the bare and contextless fast paths) now render it as the plain data it is, through the request's own finalizer.
193
+ - `requireSession` / `requireUser` / `requireAuthorization` throw a `status(...)` render instead of building a `Response`. The bytes on the wire are unchanged - a 401 JSON envelope, or a 302 with a `location` - and on Node they now carry a `content-length` instead of being drained back out as a stream.
194
+
195
+ **Behavior change:** what the guards throw is a `status(...)` render, not a `Response`. Code that catches a guard and tests `err instanceof Response` needs to stop doing that; nifra itself treats the two identically as control flow, so a guard thrown through a route behaves exactly as before.
196
+
197
+ Measured on the Linux rig (4 server cores, 50 connections, medians of 5 x 2s; a `derive` that rejects, returning vs throwing the same `status(401, ...)`). Only within-runtime deltas are readable - the host was under other load, and the return arm is included in both columns as the control:
198
+
199
+ | runtime | return | throw, before | throw, after |
200
+ | ------- | ------ | ------------- | ------------ |
201
+ | node | 85904 | 74471 | 80136 |
202
+ | deno | 139477 | 85970 | 90355 |
203
+
204
+ On Node a throw now lands within the run's own spread of a return. On Deno it does not: a throw still costs ~35%, and it costs the same whether the thrown value is a `status(...)` render or a `Response` - so what remains there is the unwind itself, not the rendering.
205
+
206
+ That remainder is the runtime's, not the framework's. The same arms with no framework at all - a bare `Deno.serve` / `Bun.serve` / `node:http` handler answering identical bytes, one returning its payload and one throwing it - reproduce it, in CPU-microseconds per request:
207
+
208
+ | | return | throw | throw across await |
209
+ | ---- | ------ | ----- | ------------------ |
210
+ | node | 49.35 | +3.85 | +2.85 |
211
+ | bun | 22.55 | +1.83 | +3.99 |
212
+ | deno | 18.89 | +7.62 | +11.03 |
213
+
214
+ Against that, nifra's own rejection arms cost +3.35 (node), +3.41 (bun), +15.59 (deno). On node and bun the framework's entire remaining throw penalty _is_ the runtime's throw. On deno the runtime's throw-across-await alone accounts for ~70% of it, and the percentage reads worse than the others only because deno's baseline request is the cheapest of the three. Two candidate explanations were tested and ruled out: `Error.stackTraceLimit = 0` changes nothing (so it is not stack capture), and throwing three frames below the handler is no cheaper (so it is not proximity to the runtime boundary).
215
+
216
+ ### Patch Changes
217
+
218
+ - f0fd370: The same-origin check behind `redirect()` and the guards' `redirectTo` now rejects the paths a URL parser resolves onto another origin, and lives in one place.
219
+
220
+ A leading `/` that is not `//` is not sufficient to keep a destination on this origin. Under a special scheme a backslash parses as a path separator, and tab, CR and LF are stripped from the input before parsing, so `/\evil.example` and `/<TAB>/evil.example` both pass a `//` test and then resolve to the host `evil.example` - an open redirect reachable from any unvalidated `?next=` parameter. Both forms are now refused: `redirect()` throws as it already did for `//host`, and an auth guard falls back to its configured destination instead of honouring the value.
221
+
222
+ New export `isSameOriginPath` from `@nifrajs/core/server`, which is the single implementation the three gates now share - a security predicate kept in three copies is three chances for one of them to be hardened alone. It answers about a path, so an absolute URL is false even when it names the current origin: the point of the gate is that the value never got to name a host at all.
223
+
224
+ A percent-encoded backslash (`/%5Cevil.example`) is still a same-origin path, because that is what it resolves to.
225
+
226
+ - Updated dependencies [f3d2a35]
227
+ - Updated dependencies [6e43c15]
228
+ - Updated dependencies [f0fd370]
229
+ - Updated dependencies [86a555b]
230
+ - Updated dependencies [8c5f4cf]
231
+ - Updated dependencies [f0fd370]
232
+ - Updated dependencies [381bbf3]
233
+ - Updated dependencies [36801ae]
234
+ - Updated dependencies [9acadba]
235
+ - Updated dependencies [99fc683]
236
+ - Updated dependencies [73d894d]
237
+ - @nifrajs/core@3.0.0
238
+
239
+ ## 2.14.1
240
+
241
+ ## 2.14.0
242
+
243
+ ## 2.13.0
244
+
245
+ ## 2.12.1
246
+
247
+ ## 2.12.0
248
+
249
+ ### Minor Changes
250
+
251
+ - dbc0b79: Signing-secret rotation. `signValue`/`unsignValue` (and the new `CookieSecret` type), session `secret`, and CSRF `secret` now also accept a rotation list: the first secret signs, any listed secret verifies, so keys rotate without invalidating live cookies, sessions, or CSRF tokens. Every listed secret must meet the 32-byte floor and an empty list throws; the single-secret path is unchanged.
252
+
253
+ ### Patch Changes
254
+
255
+ - 023891a: `destroy(c)` called without a `Session` object now revokes the stored record addressed by the request's
256
+ signed session cookie, instead of only clearing the cookie. A logout handler that had not first loaded
257
+ the session cleared the browser's copy while the server-side record stayed valid for its full TTL, so a
258
+ copy of the cookie taken before logout still authenticated. The id comes from the signed cookie, so
259
+ only a session the caller actually presented can be deleted.
260
+
261
+ ## 2.11.0
262
+
263
+ ## 2.10.0
264
+
265
+ ## 2.9.1
266
+
267
+ ## 2.9.0
268
+
269
+ ## 2.8.2
270
+
271
+ ### Patch Changes
272
+
273
+ - f7d68e8: Numeric limit options (body/payload byte caps, TTLs, cache sizes, concurrency, ISR revalidate windows) are now validated at construction and throw a `RangeError` on non-finite or out-of-range values instead of silently disabling the bound - a `NaN` cap previously made `size > max` comparisons fail open. JWT `requiredClaims` now checks own properties only, so inherited names like `toString` no longer satisfy a required claim. `@nifrajs/mcp-db` gates multi-statement input with a real tokenizer, bounds `run_query` materialization to `maxRows + 1` via a wrapping subquery, and skips SQLite planner pseudo-nodes when verifying the table allowlist. `nifra scaffold` refuses to write through symlinked route directories.
274
+
275
+ ## 2.8.1
276
+
277
+ ## 2.8.0
278
+
279
+ ## 2.7.1
280
+
281
+ ## 2.7.0
282
+
283
+ ## 2.6.1
284
+
285
+ ## 2.6.0
286
+
287
+ ## 2.5.0
288
+
289
+ ## 2.4.0
290
+
291
+ ## 2.3.0
292
+
293
+ ## 2.2.0
294
+
295
+ ## 2.1.0
296
+
297
+ ## 2.0.0
298
+
299
+ ### Patch Changes
300
+
301
+ - ade0c7a: Add a curated `@nifrajs/core/server` entry for the common HTTP runtime and dedicated subpaths for
302
+ contracts, classification, cookies, logging, routing, Standard Schema, SEO, SSE, and webhooks. The
303
+ package root remains backwards compatible, while new scaffolds and first-party runtime packages avoid
304
+ eagerly parsing opt-in causality, invariant, manifest, reflection, capability, and assurance tooling.
305
+ - Updated dependencies [a7b1d60]
306
+ - Updated dependencies [eaac3d7]
307
+ - Updated dependencies [ade0c7a]
308
+ - Updated dependencies [82676e0]
309
+ - Updated dependencies [1522d06]
310
+ - Updated dependencies [a7b1d60]
311
+ - Updated dependencies [a7b1d60]
312
+ - @nifrajs/core@2.0.0
313
+
314
+ ## 1.13.0
315
+
316
+ ## 1.12.0
317
+
318
+ ## 1.11.0
319
+
320
+ ## 1.10.0
321
+
322
+ ## 1.9.1
323
+
324
+ ## 1.9.0
325
+
326
+ ## 1.8.0
327
+
328
+ ## 1.7.0
329
+
330
+ ## 1.6.0
331
+
332
+ ## 1.5.0
333
+
334
+ ## 1.4.0
335
+
336
+ ## 1.3.1
337
+
338
+ ## 1.3.0
339
+
340
+ ## 1.2.2
341
+
342
+ ## 1.2.1
343
+
344
+ ## 1.2.0
345
+
346
+ ## 1.1.0
347
+
348
+ ## 1.0.0
349
+
350
+ ### Patch Changes
351
+
352
+ - Updated dependencies [f1f0e18]
353
+ - Updated dependencies [3efb7cd]
354
+ - Updated dependencies [de9675b]
355
+ - @nifrajs/core@1.0.0
356
+
357
+ ## 1.0.0-beta.4
358
+
359
+ ### Patch Changes
360
+
361
+ - @nifrajs/core@1.0.0-beta.4
362
+
363
+ ## 1.0.0-beta.3
364
+
365
+ ### Patch Changes
366
+
367
+ - @nifrajs/core@1.0.0-beta.3
368
+
369
+ ## 0.1.0-beta.2
370
+
371
+ ### Patch Changes
372
+
373
+ - @nifrajs/core@0.1.0-beta.2
package/dist/session.d.ts CHANGED
@@ -59,6 +59,14 @@ export interface SessionOptions {
59
59
  readonly cookie?: SessionCookieOptions;
60
60
  /** Clock (ms) - injected for testability; production passes `() => Date.now()` (the default). */
61
61
  readonly now?: () => number;
62
+ /**
63
+ * Also accept a session cookie signed by `@nifrajs/auth` before 5.0, whose signature does not cover
64
+ * the cookie name, so upgrading from 4.x signs no one out. Off by default: while it is on, any
65
+ * value the app signs with this secret through `@nifrajs/core`'s `signValue` (a signed preference
66
+ * cookie, say) and that parses as a session reads as one. Turn it on for one `maxAge` after the
67
+ * upgrade, then remove it; each such session is re-signed in the current form on its next commit.
68
+ */
69
+ readonly acceptLegacyCookies?: boolean;
62
70
  }
63
71
  export interface SessionManager<Data extends Record<string, unknown> = Record<string, unknown>> {
64
72
  /** Load the session from the request cookie (verified + un-expired), or a fresh anonymous one. */
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAA;AAE7D;qDACqD;AACrD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAClD,gFAAgF;IAChF,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,GAAG,EAAE;QACZ,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;QAClE,YAA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AE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChE,8EAA8E;IAC9E,OAAO,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClE;gFAC4E;IAC5E,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACzC;AAsCD,wBAAgB,cAAc,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3F,OAAO,EAAE,cAAc,GACtB,cAAc,CAAC,IAAI,CAAC,CAqLtB"}
package/dist/session.js CHANGED
@@ -60,6 +60,7 @@ export function createSessions(options) {
60
60
  }
61
61
  const rolling = options.rolling ?? true;
62
62
  const now = options.now ?? (() => Date.now());
63
+ const acceptLegacy = options.acceptLegacyCookies === true;
63
64
  // Annotated (not just `?? {}`) so `cookieOpts.path`/`.domain` stay typed - `?? {}` alone widens the
64
65
  // type to include the empty-object literal, which the package's build tsconfig rejects on access.
65
66
  const cookieOpts = options.cookie ?? {};
@@ -111,8 +112,9 @@ export function createSessions(options) {
111
112
  const named = await unsignValue(`${bound}${raw}`, secret);
112
113
  if (named !== null)
113
114
  return named.slice(bound.length);
114
- // Signed before names were bound: still accepted, so upgrading signs no one out, and re-signed
115
- // bound on its next commit. Such a cookie lives at most `maxAge` past the upgrade.
115
+ if (!acceptLegacy)
116
+ return null;
117
+ // Signed before names were bound; re-signed bound on its next commit.
116
118
  const legacy = await unsignValue(raw, secret);
117
119
  return legacy === null || legacy.includes("\n") ? null : legacy;
118
120
  };
@@ -135,7 +137,10 @@ export function createSessions(options) {
135
137
  const payload = parsePayload(unsigned);
136
138
  if (payload === null || payload.expiresAt <= now())
137
139
  return make({});
138
- return make({ data: payload.data, expiresAt: payload.expiresAt });
140
+ // At most a fresh session's life: a legacy cookie, or any other value signed with this secret,
141
+ // must not name its own expiry, which a non-rolling commit would keep.
142
+ const expiresAt = Math.min(payload.expiresAt, now() + maxAge * 1000);
143
+ return make({ data: payload.data, expiresAt });
139
144
  };
140
145
  const sessionCookie = (c) => c.request !== undefined && hasDuplicateCookie(c.request.headers.get("cookie"), cookieName)
141
146
  ? undefined
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAEL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAoE9B,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,gGAAgG;AAChG,kGAAkG;AAClG,uDAAuD;AACvD,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAC3B,MAAM,cAAc,GAAG,IAAI,WAAW,EAAE,CAAA;AAExC,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAU,EAAE;IACpD,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IACpD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC7E,CAAC,CAAA;AAED,sGAAsG;AACtG,MAAM,QAAQ,GAAG,GAAW,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAO1F,2GAA2G;AAC3G,MAAM,YAAY,GAAG,CAAC,IAAY,EAAkB,EAAE;IACpD,IAAI,KAAc,CAAA;IAClB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAA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K,SAAS,EAAE,CAAC;YACxB,IAAI,EAAsB,CAAA;YAC1B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,CAAA;YAC9B,CAAC;iBAAM,CAAC;gBACN,wFAAwF;gBACxF,0FAA0F;gBAC1F,MAAM,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;gBAC5B,IAAI,GAAG,KAAK,SAAS;oBAAE,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,SAAS,CAAA;YAC9D,CAAC;YACD,IAAI,EAAE,KAAK,SAAS;gBAAE,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC9C,CAAC;QACD,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,UAAU,EAAE;YAC7B,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,GAAG;YAC5B,GAAG,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1E,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,CAAC,OAAsB,EAAQ,EAAE;QAClD,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,UAAU,GAAG,IAAI,CAAA;IAClD,CAAC,CAAA;IAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;AACnD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/auth",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "Session primitives for nifra - signed-cookie + server-store sessions, CSRF, and route guards. Bring your own identity (Better Auth / Lucia / OAuth); nifra owns the session.",
5
5
  "keywords": [
6
6
  "bun",
@@ -29,7 +29,8 @@
29
29
  },
30
30
  "files": [
31
31
  "dist",
32
- "src"
32
+ "src",
33
+ "CHANGELOG.md"
33
34
  ],
34
35
  "sideEffects": false,
35
36
  "scripts": {
@@ -40,7 +41,7 @@
40
41
  "access": "public"
41
42
  },
42
43
  "peerDependencies": {
43
- "@nifrajs/core": "^5.0.0"
44
+ "@nifrajs/core": "^5.2.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@nifrajs/core": "workspace:*"
package/src/session.ts CHANGED
@@ -66,6 +66,14 @@ export interface SessionOptions {
66
66
  readonly cookie?: SessionCookieOptions
67
67
  /** Clock (ms) - injected for testability; production passes `() => Date.now()` (the default). */
68
68
  readonly now?: () => number
69
+ /**
70
+ * Also accept a session cookie signed by `@nifrajs/auth` before 5.0, whose signature does not cover
71
+ * the cookie name, so upgrading from 4.x signs no one out. Off by default: while it is on, any
72
+ * value the app signs with this secret through `@nifrajs/core`'s `signValue` (a signed preference
73
+ * cookie, say) and that parses as a session reads as one. Turn it on for one `maxAge` after the
74
+ * upgrade, then remove it; each such session is re-signed in the current form on its next commit.
75
+ */
76
+ readonly acceptLegacyCookies?: boolean
69
77
  }
70
78
 
71
79
  export interface SessionManager<Data extends Record<string, unknown> = Record<string, unknown>> {
@@ -141,6 +149,7 @@ export function createSessions<Data extends Record<string, unknown> = Record<str
141
149
  }
142
150
  const rolling = options.rolling ?? true
143
151
  const now = options.now ?? (() => Date.now())
152
+ const acceptLegacy = options.acceptLegacyCookies === true
144
153
  // Annotated (not just `?? {}`) so `cookieOpts.path`/`.domain` stay typed - `?? {}` alone widens the
145
154
  // type to include the empty-object literal, which the package's build tsconfig rejects on access.
146
155
  const cookieOpts: SessionCookieOptions = options.cookie ?? {}
@@ -206,8 +215,8 @@ export function createSessions<Data extends Record<string, unknown> = Record<str
206
215
  const unsign = async (raw: string): Promise<string | null> => {
207
216
  const named = await unsignValue(`${bound}${raw}`, secret)
208
217
  if (named !== null) return named.slice(bound.length)
209
- // Signed before names were bound: still accepted, so upgrading signs no one out, and re-signed
210
- // bound on its next commit. Such a cookie lives at most `maxAge` past the upgrade.
218
+ if (!acceptLegacy) return null
219
+ // Signed before names were bound; re-signed bound on its next commit.
211
220
  const legacy = await unsignValue(raw, secret)
212
221
  return legacy === null || legacy.includes("\n") ? null : legacy
213
222
  }
@@ -229,7 +238,10 @@ export function createSessions<Data extends Record<string, unknown> = Record<str
229
238
 
230
239
  const payload = parsePayload(unsigned)
231
240
  if (payload === null || payload.expiresAt <= now()) return make({})
232
- return make({ data: payload.data, expiresAt: payload.expiresAt })
241
+ // At most a fresh session's life: a legacy cookie, or any other value signed with this secret,
242
+ // must not name its own expiry, which a non-rolling commit would keep.
243
+ const expiresAt = Math.min(payload.expiresAt, now() + maxAge * 1000)
244
+ return make({ data: payload.data, expiresAt })
233
245
  }
234
246
 
235
247
  const sessionCookie = (c: SessionContext): string | undefined =>