@nifrajs/auth 5.1.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.
Files changed (2) hide show
  1. package/CHANGELOG.md +373 -0
  2. package/package.json +4 -3
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/auth",
3
- "version": "5.1.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.1.0"
44
+ "@nifrajs/core": "^5.2.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@nifrajs/core": "workspace:*"