@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 +140 -66
- package/docs/README.md +54 -48
- package/docs/api-manifest.json +5 -3
- package/docs/api-reference.md +42 -6
- package/docs/auth-route-guards.md +58 -50
- package/docs/authorization-security.md +298 -0
- package/docs/docs-web-manifest.json +6 -4
- package/docs/platform-manifest.json +11 -4
- package/docs/releases/0.2.6.md +194 -0
- package/docs/security.md +55 -1
- package/package.json +1 -1
- package/packages/client/src/auth.ts +20 -0
- package/packages/client/src/server.ts +16 -0
- package/packages/server/src/auth-guard.ts +111 -15
- package/packages/server/src/authorization.ts +368 -0
- package/packages/server/src/request-security.ts +596 -0
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.
|
|
5
|
+
> **Development target:** `0.2.6 — Authorization & Security v2`
|
|
6
6
|
>
|
|
7
|
-
> `0.2.
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
+
### Permissions
|
|
246
|
+
|
|
247
|
+
Use flat permissions directly from `bcp/auth`:
|
|
245
248
|
|
|
246
249
|
```ts
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
await appAuth.rotateSession();
|
|
252
|
-
```
|
|
250
|
+
import {
|
|
251
|
+
hasPermission,
|
|
252
|
+
requirePermission,
|
|
253
|
+
} from "bcp/auth";
|
|
253
254
|
|
|
254
|
-
|
|
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
|
-
|
|
271
|
+
Route trees can use a permission guard:
|
|
257
272
|
|
|
258
273
|
```ts
|
|
259
274
|
import {
|
|
260
|
-
|
|
275
|
+
createPermissionGuard,
|
|
261
276
|
} from "bcp/auth";
|
|
262
277
|
|
|
263
278
|
export const guard =
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
});
|
|
279
|
+
createPermissionGuard(
|
|
280
|
+
"admin.access"
|
|
281
|
+
);
|
|
268
282
|
```
|
|
269
283
|
|
|
270
|
-
The
|
|
284
|
+
The default permission field is `permissions`. Applications can select another field such as `scopes`.
|
|
271
285
|
|
|
272
|
-
|
|
286
|
+
### Resource policies
|
|
273
287
|
|
|
274
|
-
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
440
|
+
Origin / CSRF / middleware / cache
|
|
348
441
|
↓
|
|
349
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
518
|
+
`0.2.6 — Authorization & Security v2` establishes the permission/policy and browser-mutation security layer on top of Authentication Platform v2.
|
|
445
519
|
|
|
446
|
-
|
|
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.
|
|
5
|
+
> **Documentation target:** BCP Framework `0.2.6 — Authorization & 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.
|
|
56
|
+
## 0.2.6 — Authorization & Security v2
|
|
56
57
|
|
|
57
|
-
`0.2.
|
|
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
|
-
| `
|
|
64
|
-
| `auth-
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
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
|
|
71
|
+
Primary authorization APIs:
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
import {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
+
Primary browser-mutation security APIs:
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
↓
|
|
96
|
-
authenticated session
|
|
86
|
+
```ts
|
|
87
|
+
import {
|
|
88
|
+
createCsrfToken,
|
|
89
|
+
requireCsrfRequest,
|
|
90
|
+
requireSameOriginRequest,
|
|
91
|
+
} from "bcp/server";
|
|
97
92
|
```
|
|
98
93
|
|
|
99
|
-
|
|
94
|
+
## Security model
|
|
95
|
+
|
|
96
|
+
The `0.2.6` server model separates concerns:
|
|
100
97
|
|
|
101
98
|
```text
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
249
|
+
Authorization & Security v2 validation covers:
|
|
244
250
|
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
-
|
|
248
|
-
-
|
|
249
|
-
-
|
|
250
|
-
-
|
|
251
|
-
-
|
|
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
|
|
package/docs/api-manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"framework": "bcp",
|
|
4
|
-
"version": "0.2.
|
|
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
|
|
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",
|
package/docs/api-reference.md
CHANGED
|
@@ -164,23 +164,33 @@ Related guides: [Database](database.md), [Database Migrations](database-migratio
|
|
|
164
164
|
|
|
165
165
|
## `bcp/auth`
|
|
166
166
|
|
|
167
|
-
Server-only
|
|
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
|
-
|
|
219
|
+
Authorization & Security v2 adds permission checks, permission route guards and resource-aware policy functions:
|
|
204
220
|
|
|
205
|
-
|
|
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
|
-
|
|
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
|
|