@astratra/saas-kit 1.3.0 → 1.4.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/README.md +9 -6
- package/package.json +2 -2
- package/src/app.js +15 -0
- package/src/index.d.ts +11 -0
package/README.md
CHANGED
|
@@ -53,12 +53,15 @@ app.listen(3000);
|
|
|
53
53
|
- `GET /dashboard/summary`
|
|
54
54
|
|
|
55
55
|
Toutes les routes protégées suivent le même ordre de middlewares de
|
|
56
|
-
sécurité que la mini-app de démo : request id,
|
|
57
|
-
(`
|
|
58
|
-
`
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
sécurité que la mini-app de démo : request id, journal d'événements de
|
|
57
|
+
sécurité (`options.securityAudit`, actif par défaut), parseur de cookies,
|
|
58
|
+
amorçage CSRF, CSP (`default-src 'none'` par défaut, adapté à une API JSON
|
|
59
|
+
— surchargeable via `options.csp`), en-têtes de sécurité standard
|
|
60
|
+
(`options.securityHeaders` — X-Frame-Options, X-Content-Type-Options,
|
|
61
|
+
Referrer-Policy, Permissions-Policy, HSTS en production), parseur JSON, WAF
|
|
62
|
+
heuristique, limiteur API, limiteur de login pour `/auth`, auth JWT (cookie
|
|
63
|
+
ou `Authorization: Bearer`) pour les modules protégés, CSRF pour les routes
|
|
64
|
+
mutantes, puis 404 et gestion d'erreurs.
|
|
62
65
|
|
|
63
66
|
`jwtAlgorithms` vaut `['HS256']` par defaut. `jwtIssuer` et `jwtAudience` sont
|
|
64
67
|
optionnels, mais recommandes des qu'une app sort du simple developpement local.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astratra/saas-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Reusable backend starter kit that assembles Astratra core, security, and AI packages.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@astratra/ai": "^1.0.0",
|
|
28
28
|
"@astratra/core": "^1.0.0",
|
|
29
|
-
"@astratra/security": "^1.
|
|
29
|
+
"@astratra/security": "^1.4.0",
|
|
30
30
|
"express": "^4.18.3",
|
|
31
31
|
"express-validator": "^7.3.2",
|
|
32
32
|
"jsonwebtoken": "^9.0.2"
|
package/src/app.js
CHANGED
|
@@ -15,6 +15,8 @@ const {
|
|
|
15
15
|
createCsrfMiddleware,
|
|
16
16
|
createLoginLimiter,
|
|
17
17
|
createMemoryRevocationStore,
|
|
18
|
+
createSecurityAuditLogger,
|
|
19
|
+
createSecurityHeadersMiddleware,
|
|
18
20
|
createWafMiddleware,
|
|
19
21
|
DEFAULT_SESSION_COOKIE_NAME
|
|
20
22
|
} = require('@astratra/security');
|
|
@@ -87,6 +89,16 @@ function createSaasApp(options = {}) {
|
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
app.use(requestIdMiddleware);
|
|
92
|
+
// Every request that ends in 401/403/429 (failed auth, CSRF/WAF block,
|
|
93
|
+
// rate limit) gets a structured log line — none of those layers logged
|
|
94
|
+
// anything anywhere before this, so an attack attempt was invisible
|
|
95
|
+
// until it succeeded. Mounted early so req.id is already set; observes
|
|
96
|
+
// the response rather than hooking each layer individually, so where
|
|
97
|
+
// exactly it sits in the stack otherwise doesn't matter. Pass
|
|
98
|
+
// options.securityAudit: false to disable.
|
|
99
|
+
if (normalized.securityAudit !== false) {
|
|
100
|
+
app.use(createSecurityAuditLogger(normalized.securityAudit === true ? {} : normalized.securityAudit));
|
|
101
|
+
}
|
|
90
102
|
app.use(cookieParserMiddleware());
|
|
91
103
|
// Seeds the CSRF cookie on every safe request (GET/HEAD/OPTIONS), globally,
|
|
92
104
|
// before any route — including custom routes mounted via extendRoutes.
|
|
@@ -95,6 +107,9 @@ function createSaasApp(options = {}) {
|
|
|
95
107
|
// validated, so the client's first mutating request always fails.
|
|
96
108
|
app.use(createCsrfCookiePrimer(normalized.csrf));
|
|
97
109
|
app.use(createCspMiddleware(normalized.csp));
|
|
110
|
+
// Every option here has a safe universal default (unlike CORS, nothing
|
|
111
|
+
// needs a project-specific decision), so this is unconditional like CSP.
|
|
112
|
+
app.use(createSecurityHeadersMiddleware(normalized.securityHeaders));
|
|
98
113
|
app.use(express.json());
|
|
99
114
|
app.use(createWafMiddleware(normalized.waf));
|
|
100
115
|
app.use(createApiLimiter(normalized.apiRateLimit));
|
package/src/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type {
|
|
|
7
7
|
RateLimitOptions,
|
|
8
8
|
RequestHandler,
|
|
9
9
|
RevocationStore,
|
|
10
|
+
SecurityAuditLoggerOptions,
|
|
11
|
+
SecurityHeadersOptions,
|
|
10
12
|
SessionCookieOptions,
|
|
11
13
|
WafOptions,
|
|
12
14
|
WebauthnOptions,
|
|
@@ -110,6 +112,15 @@ export interface CreateSaasAppOptions {
|
|
|
110
112
|
* default behavior).
|
|
111
113
|
*/
|
|
112
114
|
cors?: CorsMiddlewareOptions | true;
|
|
115
|
+
/** X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, HSTS. Every option has a safe default; mounted unconditionally like csp. */
|
|
116
|
+
securityHeaders?: SecurityHeadersOptions;
|
|
117
|
+
/**
|
|
118
|
+
* Structured logging for any request ending in 401/403/429 (failed auth,
|
|
119
|
+
* CSRF/WAF block, rate limit). Mounted by default — pass `false` to
|
|
120
|
+
* disable, `true` or an options object to customize (custom `log` sink,
|
|
121
|
+
* different `statusCodes`).
|
|
122
|
+
*/
|
|
123
|
+
securityAudit?: SecurityAuditLoggerOptions | boolean;
|
|
113
124
|
webauthnStore?: WebauthnStore;
|
|
114
125
|
webauthn?: WebauthnOptions;
|
|
115
126
|
waf?: WafOptions;
|