@chidchanun/bcp 0.2.5 → 0.2.6

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
@@ -1,14 +1,14 @@
1
1
  # BCP Framework
2
2
 
3
- BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, database access, validation, uploads, storage and standalone Node.js production deployment.
3
+ BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, authorization, database access, validation, uploads, storage and standalone Node.js production deployment.
4
4
 
5
- > **Development target:** `0.2.5Authentication Platform v2`
5
+ > **Development target:** `0.2.6Authorization & Security v2`
6
6
  >
7
- > `0.2.5` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.6` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
8
8
 
9
9
  ## 0.2 platform
10
10
 
11
- `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, and `0.2.5` adds optional revocable authentication sessions and guest-aware route guards without intentionally removing the existing stateless JWT-cookie model.
11
+ `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, `0.2.5` added Authentication Platform v2, and `0.2.6` adds permission/policy authorization plus CSRF and same-origin request protection without intentionally removing the existing public application model.
12
12
 
13
13
  Machine-readable platform contracts:
14
14
 
@@ -31,8 +31,9 @@ docs/api-manifest.json
31
31
  | Routing | Static, dynamic, catch-all, optional catch-all and route groups |
32
32
  | Server data | Route `loader.ts`, request-scoped server APIs |
33
33
  | Mutations | Route-owned `actions.ts` and `<Form>` |
34
- | Authorization | `guard.ts`, `requireAuth()`, `requireGuest()`, `requireRole()` |
35
34
  | Authentication | JWT cookie sessions, optional server-side session stores, revocation, logout-all, idle timeout and rotation |
35
+ | Authorization | Auth/guest/role/permission route guards, flat permissions and resource-aware policies |
36
+ | Request security | Same-origin validation and signed CSRF tokens for unsafe mutations |
36
37
  | Middleware | Middleware System v2 with onion execution |
37
38
  | Validation | Typed validators and structured validation errors |
38
39
  | Error handling | HTTP error helpers and consistent error responses |
@@ -155,8 +156,6 @@ await db.connect();
155
156
  await db.disconnect();
156
157
  ```
157
158
 
158
- `db.close()` remains available for backward-compatible shutdown handling.
159
-
160
159
  Migration CLI:
161
160
 
162
161
  ```bash
@@ -166,8 +165,6 @@ bcp db status
166
165
  bcp db rollback
167
166
  ```
168
167
 
169
- BCP makes framework migration bookkeeping provider-aware. Application migration SQL itself is not automatically translated between SQL dialects.
170
-
171
168
  Read more:
172
169
 
173
170
  - [Database](docs/database.md)
@@ -175,7 +172,7 @@ Read more:
175
172
 
176
173
  ## Application Packaging — 0.2.4
177
174
 
178
- Create a fresh production build and convert it into a deployment-oriented package:
175
+ Create a fresh production build and deployment package:
179
176
 
180
177
  ```bash
181
178
  bcp package
@@ -200,8 +197,6 @@ Output:
200
197
  └─ README.md
201
198
  ```
202
199
 
203
- The package layer creates production-only dependency metadata, deployment/environment manifests, SHA-256 file integrity metadata and a Node 24 Alpine Docker starter.
204
-
205
200
  Read more:
206
201
 
207
202
  - [Application Packaging](docs/application-packaging.md)
@@ -209,7 +204,7 @@ Read more:
209
204
 
210
205
  ## Authentication Platform v2 — 0.2.5
211
206
 
212
- The existing stateless JWT-cookie mode remains available:
207
+ Stateless signed JWT-cookie authentication remains supported:
213
208
 
214
209
  ```ts
215
210
  import {
@@ -232,49 +227,149 @@ const sessionStore =
232
227
 
233
228
  export const appAuth =
234
229
  createAuth({
235
- store:
236
- sessionStore,
237
- idleTimeout:
238
- 60 * 30,
230
+ store: sessionStore,
231
+ idleTimeout: 60 * 30,
239
232
  });
240
233
  ```
241
234
 
242
- With a store configured, authentication requires both a valid signed JWT cookie and an active `sid` record.
235
+ With a store configured, authentication requires both a valid signed JWT cookie and an active `sid` record. The built-in memory store is intended for development/tests; production multi-instance deployments should implement `AuthSessionStore` with shared storage.
236
+
237
+ Read more:
238
+
239
+ - [Authentication](docs/authentication.md)
240
+ - [Auth Session Stores](docs/auth-session-store.md)
241
+ - [Auth Route Guards](docs/auth-route-guards.md)
242
+
243
+ ## Authorization & Security v2 — 0.2.6
243
244
 
244
- New lifecycle APIs:
245
+ ### Permissions
246
+
247
+ Use flat permissions directly from `bcp/auth`:
245
248
 
246
249
  ```ts
247
- await appAuth.logout();
248
- await appAuth.logoutAll();
249
- await appAuth.revokeSession(sid);
250
- await appAuth.revokeUserSessions(userId);
251
- await appAuth.rotateSession();
252
- ```
250
+ import {
251
+ hasPermission,
252
+ requirePermission,
253
+ } from "bcp/auth";
253
254
 
254
- `idleTimeout` is enforced only when a server-side store is configured. BCP rejects the option in stateless-only mode rather than silently pretending to enforce inactivity expiration.
255
+ hasPermission(
256
+ user,
257
+ "users.read"
258
+ );
259
+
260
+ await requirePermission(
261
+ [
262
+ "users.read",
263
+ "users.write",
264
+ ],
265
+ {
266
+ match: "all",
267
+ }
268
+ );
269
+ ```
255
270
 
256
- Guest-only login/register routes can use:
271
+ Route trees can use a permission guard:
257
272
 
258
273
  ```ts
259
274
  import {
260
- createGuestGuard,
275
+ createPermissionGuard,
261
276
  } from "bcp/auth";
262
277
 
263
278
  export const guard =
264
- createGuestGuard({
265
- redirectTo:
266
- "/dashboard",
267
- });
279
+ createPermissionGuard(
280
+ "admin.access"
281
+ );
268
282
  ```
269
283
 
270
- The built-in memory session store is intended for development/tests and process-local prototypes. Production applications running multiple processes or containers should implement `AuthSessionStore` with shared durable storage such as Redis or a database.
284
+ The default permission field is `permissions`. Applications can select another field such as `scopes`.
271
285
 
272
- Read more:
286
+ ### Resource policies
273
287
 
274
- - [Authentication](docs/authentication.md)
275
- - [Auth Session Stores](docs/auth-session-store.md)
276
- - [Auth Route Guards](docs/auth-route-guards.md)
277
- - [JWT Sessions](docs/session-auth.md)
288
+ For ownership, tenant or resource-state rules:
289
+
290
+ ```ts
291
+ import {
292
+ authorize,
293
+ defineAuthorizationPolicy,
294
+ } from "bcp/auth";
295
+
296
+ const updateProject =
297
+ defineAuthorizationPolicy(
298
+ ({
299
+ user,
300
+ resource,
301
+ }) =>
302
+ resource.ownerId ===
303
+ user.id
304
+ );
305
+
306
+ await authorize(
307
+ updateProject,
308
+ {
309
+ user,
310
+ resource: project,
311
+ }
312
+ );
313
+ ```
314
+
315
+ Available policy helpers:
316
+
317
+ ```text
318
+ can()
319
+ cannot()
320
+ authorize()
321
+ AuthorizationError
322
+ ```
323
+
324
+ ### Same-origin and CSRF protection
325
+
326
+ Request-security helpers are exposed from `bcp/server`:
327
+
328
+ ```ts
329
+ import {
330
+ createCsrfToken,
331
+ requireCsrfRequest,
332
+ requireSameOriginRequest,
333
+ } from "bcp/server";
334
+ ```
335
+
336
+ Protect an unsafe API/action mutation with origin validation:
337
+
338
+ ```ts
339
+ await requireSameOriginRequest();
340
+ ```
341
+
342
+ For signed CSRF protection:
343
+
344
+ ```ts
345
+ const csrfToken =
346
+ await createCsrfToken();
347
+
348
+ // Render/send csrfToken through the trusted application UI.
349
+
350
+ await requireCsrfRequest({
351
+ token: submittedToken,
352
+ });
353
+ ```
354
+
355
+ Default CSRF header/cookie:
356
+
357
+ ```text
358
+ X-BCP-CSRF
359
+ bcp_csrf
360
+ ```
361
+
362
+ Secret resolution:
363
+
364
+ ```text
365
+ explicit options.secret
366
+
367
+ BCP_CSRF_SECRET
368
+
369
+ BCP_SESSION_SECRET
370
+ ```
371
+
372
+ Read more: [Authorization & Security v2](docs/authorization-security.md)
278
373
 
279
374
  ## Public entrypoints
280
375
 
@@ -337,16 +432,14 @@ bcp generate middleware
337
432
  bcp generate migration create_users
338
433
  ```
339
434
 
340
- Page/API/middleware generators require `--force` before replacing an existing scaffold target.
341
-
342
435
  ## Application model
343
436
 
344
437
  ```text
345
438
  Browser
346
439
 
347
- Security / middleware / cache
440
+ Origin / CSRF / middleware / cache
348
441
 
349
- Route guard
442
+ Authentication + authorization guard
350
443
 
351
444
  Loader / action / API route
352
445
 
@@ -355,24 +448,6 @@ React SSR
355
448
  Hydration / SPA navigation
356
449
  ```
357
450
 
358
- Typical route structure:
359
-
360
- ```text
361
- app/
362
- ├─ layout.tsx
363
- ├─ page.tsx
364
- ├─ dashboard/
365
- │ ├─ guard.ts
366
- │ └─ users/
367
- │ └─ [id]/
368
- │ ├─ loader.ts
369
- │ ├─ actions.ts
370
- │ └─ page.tsx
371
- └─ api/
372
- └─ upload/
373
- └─ route.ts
374
- ```
375
-
376
451
  ## Production build
377
452
 
378
453
  Raw standalone build:
@@ -388,7 +463,7 @@ Deployment package:
388
463
  bcp package
389
464
  ```
390
465
 
391
- Both current targets remain Node.js `standalone-node` applications. Production hardening includes configurable request/header/keep-alive/shutdown timeouts, trusted-proxy handling and graceful `SIGTERM` / `SIGINT` shutdown.
466
+ Both current targets remain Node.js `standalone-node` applications.
392
467
 
393
468
  ## Documentation Platform
394
469
 
@@ -402,8 +477,6 @@ docs/platform-manifest.json
402
477
  docs/api-manifest.json
403
478
  ```
404
479
 
405
- The manifests provide navigation order, routes, Markdown sources, version/release state, public entrypoints and API guide ownership.
406
-
407
480
  ## Release validation
408
481
 
409
482
  Framework releases must pass:
@@ -418,7 +491,7 @@ npm run test:e2e
418
491
  npm run rc:check
419
492
  ```
420
493
 
421
- `0.2.5` adds Authentication Platform v2 unit and prepared-package smoke checks covering session-store registration, revocation, logout-all, idle timeout, rotation and guest guards.
494
+ `0.2.6` adds Authorization & Security v2 unit and prepared-package smoke checks covering permission matching, policy authorization, permission route guards, same-origin mutation validation and signed CSRF tokens.
422
495
 
423
496
  Do not tag or publish until the final release commit passes the complete RC sequence.
424
497
 
@@ -438,12 +511,13 @@ Do not tag or publish until the final release commit passes the complete RC sequ
438
511
  | `0.2.3` | Database Platform v2 |
439
512
  | `0.2.4` | Application Packaging |
440
513
  | `0.2.5` | Authentication Platform v2 |
514
+ | `0.2.6` | Authorization & Security v2 |
441
515
 
442
516
  ## Roadmap
443
517
 
444
- `0.2.5Authentication Platform v2` establishes optional revocable server-side auth state while preserving the original stateless JWT-cookie path.
518
+ `0.2.6Authorization & Security v2` establishes the permission/policy and browser-mutation security layer on top of Authentication Platform v2.
445
519
 
446
- A later security/authorization milestone can build on this session contract for broader permission and security policy features. Native `.exe`, desktop and mobile compilation remain later roadmap work.
520
+ The next `0.2.x` milestone can build on the existing runtime, database, auth, security and packaging contracts. Native `.exe`, desktop and mobile compilation remain later roadmap work.
447
521
 
448
522
  ## License
449
523
 
package/docs/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `docs/` directory is the documentation source of truth for BCP Framework and is organized for **`bcp-docs-web`**.
4
4
 
5
- > **Documentation target:** BCP Framework `0.2.5Authentication Platform v2`
5
+ > **Documentation target:** BCP Framework `0.2.6Authorization & Security v2`
6
6
  >
7
7
  > **Release state:** unreleased development target until RC validation, tagging and npm publication complete.
8
8
 
@@ -51,62 +51,67 @@ Framework source and tests remain authoritative for runtime behavior.
51
51
  | `0.2.3` | Database Platform v2 |
52
52
  | `0.2.4` | Application Packaging |
53
53
  | `0.2.5` | Authentication Platform v2 |
54
+ | `0.2.6` | Authorization & Security v2 |
54
55
 
55
- ## 0.2.5Authentication Platform v2
56
+ ## 0.2.6Authorization & Security v2
56
57
 
57
- `0.2.5` keeps stateless signed JWT-cookie authentication as the default and adds optional server-side session state for revocation and inactivity policy.
58
+ `0.2.6` adds server-side permission checks, resource-aware authorization policies, permission route guards, same-origin mutation validation and signed CSRF protection.
58
59
 
59
60
  New/updated documentation sources:
60
61
 
61
62
  | Source | Purpose |
62
63
  | --- | --- |
63
- | `authentication.md` | Auth core, revocation, logout-all, rotation and idle timeout |
64
- | `auth-session-store.md` | `AuthSessionStore`, memory adapter and production-store guidance |
65
- | `auth-route-guards.md` | Auth, guest and role route guards |
66
- | `api-reference.md` | Public Authentication Platform v2 exports |
67
- | `platform-manifest.json` | Authentication v2 capability flags |
68
- | `api-manifest.json` | `bcp/auth` guide ownership |
69
- | `releases/0.2.5.md` | Authentication Platform v2 release notes |
64
+ | `authorization-security.md` | Permissions, policies, permission guards, same-origin validation and CSRF APIs |
65
+ | `auth-route-guards.md` | Auth/guest/role/permission route guard guidance |
66
+ | `api-reference.md` | Public authorization and request-security exports |
67
+ | `platform-manifest.json` | Authorization/security capability flags |
68
+ | `api-manifest.json` | `bcp/auth` and `bcp/server` guide ownership |
69
+ | `releases/0.2.6.md` | Authorization & Security v2 release notes |
70
70
 
71
- Primary public entrypoint:
71
+ Primary authorization APIs:
72
72
 
73
73
  ```ts
74
74
  import {
75
- auth,
76
- createAuth,
77
- createMemoryAuthSessionStore,
78
- login,
79
- logout,
80
- logoutAll,
81
- requireAuth,
82
- requireGuest,
83
- requireRole,
75
+ authorize,
76
+ can,
77
+ createPermissionGuard,
78
+ defineAuthorizationPolicy,
79
+ hasPermission,
80
+ requirePermission,
84
81
  } from "bcp/auth";
85
82
  ```
86
83
 
87
- ## Authentication security model
84
+ Primary browser-mutation security APIs:
88
85
 
89
- Default mode:
90
-
91
- ```text
92
- signed HttpOnly JWT cookie
93
-
94
- signature + expiry validation
95
-
96
- authenticated session
86
+ ```ts
87
+ import {
88
+ createCsrfToken,
89
+ requireCsrfRequest,
90
+ requireSameOriginRequest,
91
+ } from "bcp/server";
97
92
  ```
98
93
 
99
- Optional revocable mode:
94
+ ## Security model
95
+
96
+ The `0.2.6` server model separates concerns:
100
97
 
101
98
  ```text
102
- signed HttpOnly JWT cookie
103
- +
104
- server-side sid store
105
-
106
- revocable authenticated session
99
+ authentication
100
+ -> identify a signed/revocable session
101
+
102
+ authorization
103
+ -> permissions + policies + route guards
104
+
105
+ request security
106
+ -> Origin/Referer validation + signed CSRF token
107
+
108
+ input validation
109
+ -> application schema/domain checks
107
110
  ```
108
111
 
109
- The built-in memory store is intended for development/tests. Multi-process production systems should implement `AuthSessionStore` using shared durable storage.
112
+ All authorization decisions must remain server-side. Client UI permission checks may improve presentation but do not replace route/action/API enforcement.
113
+
114
+ CSRF tokens use `BCP_CSRF_SECRET` when configured and otherwise fall back to `BCP_SESSION_SECRET`. Security secrets must contain at least 32 UTF-8 bytes.
110
115
 
111
116
  ## Update rule
112
117
 
@@ -130,7 +135,7 @@ Current sections:
130
135
  ```text
131
136
  Getting Started
132
137
  Routing & Data
133
- Authentication
138
+ Authentication & Authorization
134
139
  Database
135
140
  Runtime & Infrastructure
136
141
  Storage & Uploads
@@ -147,10 +152,11 @@ Important current routes:
147
152
  | `/docs/authentication` | `authentication.md` |
148
153
  | `/docs/auth-session-store` | `auth-session-store.md` |
149
154
  | `/docs/auth-route-guards` | `auth-route-guards.md` |
155
+ | `/docs/authorization-security` | `authorization-security.md` |
150
156
  | `/docs/application-packaging` | `application-packaging.md` |
151
157
  | `/docs/database` | `database.md` |
152
158
  | `/docs/api-reference` | `api-reference.md` |
153
- | `/releases/0.2.5` | `releases/0.2.5.md` |
159
+ | `/releases/0.2.6` | `releases/0.2.6.md` |
154
160
 
155
161
  Every route/source pair is validated by unit tests.
156
162
 
@@ -229,7 +235,7 @@ synchronize CMS/search/navigation
229
235
 
230
236
  ## Release validation
231
237
 
232
- Before publishing `0.2.5`:
238
+ Before publishing `0.2.6`:
233
239
 
234
240
  ```bash
235
241
  npm run typecheck
@@ -240,16 +246,16 @@ npm run test:e2e
240
246
  npm run rc:check
241
247
  ```
242
248
 
243
- Authentication Platform v2 validation covers:
249
+ Authorization & Security v2 validation covers:
244
250
 
245
- - stateless JWT backward compatibility,
246
- - session-store registration and lookup,
247
- - session revocation,
248
- - logout-all,
249
- - idle timeout,
250
- - rotation with old-session revocation,
251
- - guest route guards,
252
- - public `bcp/auth` exports,
251
+ - permission normalization and any/all matching,
252
+ - permission route guards,
253
+ - sync/async authorization policies,
254
+ - `AuthorizationError` denial behavior,
255
+ - same-origin mutation checks,
256
+ - signed CSRF tokens,
257
+ - malformed/cross-origin rejection,
258
+ - public `bcp/auth` and `bcp/server` exports,
253
259
  - prepared npm package contents,
254
260
  - docs/platform/API version parity.
255
261
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
5
5
  "releaseState": "unreleased",
6
6
  "coverage": "public-entrypoints",
7
7
  "entrypoints": [
@@ -85,11 +85,12 @@
85
85
  "source": "packages/client/src/auth.ts",
86
86
  "environment": "server",
87
87
  "route": "/docs/api-reference#bcp-auth",
88
- "summary": "Authentication Platform v2 with JWT cookies, optional revocable session stores, idle timeout, logout-all and auth/guest/role route guards.",
88
+ "summary": "Authentication Platform v2 plus permission checks, authorization policies and auth/guest/role/permission route guards.",
89
89
  "guides": [
90
90
  "/docs/authentication",
91
91
  "/docs/auth-session-store",
92
92
  "/docs/auth-route-guards",
93
+ "/docs/authorization-security",
93
94
  "/docs/session-auth"
94
95
  ]
95
96
  },
@@ -98,9 +99,10 @@
98
99
  "source": "packages/client/src/server.ts",
99
100
  "environment": "server",
100
101
  "route": "/docs/api-reference#bcp-server",
101
- "summary": "Request context, cookies, logging, production hardening, upload, storage, response and session APIs.",
102
+ "summary": "Request context, cookies, CSRF/same-origin protection, logging, production hardening, upload, storage, response and session APIs.",
102
103
  "guides": [
103
104
  "/docs/server-request-apis",
105
+ "/docs/authorization-security",
104
106
  "/docs/file-upload",
105
107
  "/docs/storage",
106
108
  "/docs/storage-ecosystem",
@@ -164,23 +164,33 @@ Related guides: [Database](database.md), [Database Migrations](database-migratio
164
164
 
165
165
  ## `bcp/auth`
166
166
 
167
- Server-only Authentication Platform v2 APIs.
167
+ Server-only authentication and authorization APIs.
168
168
 
169
169
  ```ts
170
170
  import {
171
+ AuthorizationError,
172
+ assertPermission,
171
173
  auth,
174
+ authorize,
175
+ can,
176
+ cannot,
172
177
  createAuth,
173
178
  createAuthGuard,
174
179
  createGuestGuard,
175
180
  createMemoryAuthSessionStore,
181
+ createPermissionGuard,
176
182
  createRoleGuard,
183
+ defineAuthorizationPolicy,
177
184
  getGuardAuth,
178
185
  getSession,
186
+ getUserPermissions,
187
+ hasPermission,
179
188
  login,
180
189
  logout,
181
190
  logoutAll,
182
191
  requireAuth,
183
192
  requireGuest,
193
+ requirePermission,
184
194
  requireRole,
185
195
  revokeSession,
186
196
  revokeUserSessions,
@@ -192,45 +202,71 @@ import {
192
202
  type AuthSessionStore,
193
203
  type AuthSessionStoreRecord,
194
204
  type AuthUser,
205
+ type AuthorizationContext,
206
+ type AuthorizationMatch,
207
+ type AuthorizationPolicy,
195
208
  type MemoryAuthSessionStore,
209
+ type PermissionCheckOptions,
210
+ type PermissionRequirement,
211
+ type RequirePermissionOptions,
196
212
  } from "bcp/auth";
197
213
  ```
198
214
 
199
- The default mode remains stateless signed JWT-cookie authentication.
215
+ The default authentication mode remains stateless signed JWT-cookie authentication.
200
216
 
201
217
  Configure `AuthOptions.store` to enable server-side session revocation and `idleTimeout`. `createMemoryAuthSessionStore()` is provided for development/testing; production multi-instance applications should implement `AuthSessionStore` with shared durable storage.
202
218
 
203
- `logoutAll()`, `revokeSession()`, and `revokeUserSessions()` require server-side session state. `requireGuest()` / `createGuestGuard()` support login/register routes that should redirect already-authenticated users.
219
+ Authorization & Security v2 adds permission checks, permission route guards and resource-aware policy functions:
204
220
 
205
- Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [JWT Sessions](session-auth.md).
221
+ - `hasPermission()` / `assertPermission()` for flat permission or scope fields,
222
+ - `requirePermission()` / `createPermissionGuard()` for route protection,
223
+ - `defineAuthorizationPolicy()` for application policy definitions,
224
+ - `can()` / `cannot()` for policy checks,
225
+ - `authorize()` for throwing `AuthorizationError` when a policy denies access.
226
+
227
+ Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [Authorization & Security v2](authorization-security.md), [JWT Sessions](session-auth.md).
206
228
 
207
229
  ## `bcp/server`
208
230
 
209
231
  Server request/runtime APIs.
210
232
 
211
- This entrypoint includes request context, cookies, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
233
+ This entrypoint includes request context, cookies, CSRF and same-origin protection, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
212
234
 
213
235
  ```ts
214
236
  import {
215
237
  clientIp,
216
238
  cookies,
239
+ createCsrfToken,
217
240
  createLocalStorage,
218
241
  createLogger,
219
242
  createS3Storage,
220
243
  createStorageResponse,
244
+ destroyCsrfToken,
221
245
  getProductionHardeningConfig,
222
246
  headers,
247
+ isSafeHttpMethod,
248
+ isSameOriginRequest,
223
249
  json,
224
250
  redirect,
225
251
  registerShutdownHook,
226
252
  requestId,
227
253
  requestMethod,
228
254
  requestUrl,
255
+ requireCsrfRequest,
256
+ requireSameOriginRequest,
229
257
  storeMultipartFile,
258
+ verifyCsrfRequest,
259
+ verifyCsrfToken,
260
+ RequestSecurityError,
261
+ type CsrfTokenOptions,
262
+ type SameOriginOptions,
263
+ type VerifyCsrfRequestOptions,
230
264
  } from "bcp/server";
231
265
  ```
232
266
 
233
- Related guides: [Server Request APIs](server-request-apis.md), [File Upload](file-upload.md), [Storage](storage.md), [Storage Ecosystem](storage-ecosystem.md), [Production Hardening](production-hardening.md).
267
+ `requireSameOriginRequest()` protects unsafe cookie-authenticated mutations by validating `Origin`/`Referer`. `createCsrfToken()` and `requireCsrfRequest()` provide signed double-submit style CSRF protection. `BCP_CSRF_SECRET` is preferred when configured and falls back to `BCP_SESSION_SECRET`.
268
+
269
+ Related guides: [Server Request APIs](server-request-apis.md), [Authorization & Security v2](authorization-security.md), [File Upload](file-upload.md), [Storage](storage.md), [Storage Ecosystem](storage-ecosystem.md), [Production Hardening](production-hardening.md).
234
270
 
235
271
  ## `bcp/server-only`
236
272