@blamejs/core 0.13.45 → 0.13.46
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 +2 -0
- package/README.md +8 -11
- package/lib/app.js +57 -7
- package/lib/audit.js +1 -0
- package/lib/middleware/cookies.js +4 -0
- package/lib/middleware/csp-nonce.js +4 -0
- package/lib/middleware/csrf-protect.js +29 -1
- package/lib/middleware/fetch-metadata.js +3 -0
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.13.x
|
|
10
10
|
|
|
11
|
+
- v0.13.46 (2026-05-29) — **`createApp` now wires the documented security middleware ON by default — CSRF, CSP nonce, cookie parser, fetch-metadata, and body parser.** The README has long described a security middleware stack as "wired by createApp", but createApp only mounted request-ID, security-headers, and bot-guard by default — CSRF protection, the CSP nonce, the threat-aware cookie parser, the fetch-metadata guard, and the body parser were documented but not actually wired. This release closes that gap: createApp now mounts all of them by default, in dependency order (cookies, CSP nonce, fetch-metadata, then body parser, then CSRF last so it can read a body-field token). This is a behavior change — apps built with createApp now enforce CSRF on state-changing requests by default. Each layer is configurable via opts.middleware.<name> (operator cookie and field names flow straight through — nothing is hardcoded) or can be turned off with false, and disabling a security default now emits an app.middleware.disabled audit event. Every layer is idempotent: an operator who also mounts one of these inside opts.routes gets a no-op second mount rather than a double-apply. The default CSRF is a double-submit cookie that auto-skips requests carrying an Authorization header or no cookies at all, which are not CSRF-able, so token-authenticated API clients are not rejected. The README middleware list is now an accurate description of what createApp wires. **Added:** *Idempotent security middleware* — The cookie parser, CSP nonce, fetch-metadata, and CSRF middleware are now idempotent within a request: if one has already run (because createApp wired it and an operator also mounted it), the second instance is a no-op rather than re-parsing, re-generating a nonce, or issuing a second CSRF cookie. This lets an application compose its own middleware order on top of createApp's defaults without double-applying. The body parser already had this behavior. **Changed:** *createApp wires CSRF, CSP nonce, cookie parser, fetch-metadata, and body parser by default (breaking)* — Applications constructed with b.createApp now mount, in order: the threat-aware cookie parser, the CSP nonce generator, the fetch-metadata resource-isolation guard, the body parser (JSON / urlencoded / text / multipart), and CSRF protection — in addition to the request-ID, security-headers, and bot-guard layers already wired. The ordering guarantees CSRF runs after the body parser so a body-field token is available. This is a behavior change: state-changing requests (POST / PUT / DELETE / PATCH) that carry a session cookie are now CSRF-validated by default. Each layer is configured through opts.middleware.<name> (an object passes operator options straight through; cookie and field names are not hardcoded) or disabled with false. Operators who were mounting these middleware themselves inside opts.routes do not need to change anything — the second mount is now a no-op (see idempotency below). · *Default CSRF auto-skips token-authenticated and cookieless requests* — The CSRF middleware gains a skipStateless option (default false; createApp's default wiring sets it true). When on, token validation is skipped for requests that carry an Authorization header or no Cookie header at all — such requests are not CSRF-able, because CSRF abuses a victim's ambient cookie credential and these have none. The token is still issued on safe methods so a later cookie-authenticated browser flow works. Cross-site form CSRF is unaffected: the browser auto-sends the victim's cookies, so an attack request always carries a Cookie header and is validated. · *Disabling a default security middleware is audited* — Passing false for one of the security-on-by-default middleware (for example middleware: { csrf: false }) now emits an app.middleware.disabled audit event naming the middleware, so a weakened posture leaves a trace in the audit chain rather than being silent.
|
|
12
|
+
|
|
11
13
|
- v0.13.45 (2026-05-29) — **`b.cert` now fetches and staples a validated OCSP response per certificate, and validates declared compliance postures at create().** Two capabilities that b.cert documented but did not act on are now wired through. OCSP stapling: the cert manager fetches the leaf's OCSP response from the responder named in its Authority Information Access extension, validates it against the issuer (status, nonce, serial) via b.network.tls.ocsp, caches the DER, and exposes it on getContext().ocspResponse so a TLS server's OCSPRequest handler can staple it. The fetch runs in the background on a refresh timer and never blocks cert.start() — a slow or unreachable responder produces an audited per-certificate failure, not a stalled boot. Compliance postures: opts.compliance names are now validated against b.compliance.KNOWN_POSTURES at create() (an unknown name throws cert/unknown-compliance-posture instead of being silently recorded) and are surfaced on getContext().compliance for an auditor. Storage-confidentiality postures hold by construction because cert keys and certificates are always sealed at rest. The supporting composition primitive b.network.tls.ocsp.fetch (build request, POST to the responder through b.httpClient, validate the response) is now part of the public OCSP surface. **Added:** *b.network.tls.ocsp.fetch — fetch and validate an OCSP response* — The OCSP helper set previously built requests and evaluated responses but had no way to actually retrieve one. b.network.tls.ocsp.fetch({ leafPem, issuerPem, nonce?, timeoutMs? }) reads the responder URL from the leaf certificate's Authority Information Access extension, builds the request, POSTs it through b.httpClient (so the SSRF guard and pinned DNS apply), and validates the response against the issuer — returning the validated DER plus the parsed evaluation. It rejects when the leaf carries no OCSP responder URL or the response fails validation. · *b.cert staples a validated OCSP response per certificate* — With ocsp.stapling enabled (the default), the cert manager refreshes each certificate's OCSP response on a timer (ocsp.refreshMs, default 12h) and caches the validated DER. getContext(serverName).ocspResponse returns that DER for a TLS server to hand back from its OCSPRequest handler. The refresh runs in the background and is never on the path of cert.start(): an unreachable or slow responder is recorded as an audited cert.ocsp.refresh failure for that certificate and leaves the rest of the manager running. **Changed:** *opts.compliance posture names are validated at create()* — b.cert.create now checks each name in opts.compliance against b.compliance.KNOWN_POSTURES and throws cert/unknown-compliance-posture on an unrecognized name, so a typo is caught at construction rather than being silently recorded. The declared postures are surfaced on getContext().compliance. Cert keys and certificates are always sealed at rest, so storage-confidentiality postures are satisfied by construction.
|
|
12
14
|
|
|
13
15
|
- v0.13.44 (2026-05-29) — **Error codes on the consent, compliance, and protocol namespaces now follow the namespace/kebab-case contract.** The framework's error contract is `err.code = "namespace/kebab-case"`, and the vast majority of namespaces already followed it. This release normalizes the holdouts: fifteen namespaces that threw bare UPPER_SNAKE codes with no namespace, and nine that used a camelCase namespace prefix. After this release every error these namespaces throw carries a `namespace/kebab-case` code, so an operator switching on `err.code` no longer has to special-case them. This is a breaking change for code that matches the old strings — pre-1.0, there is no compatibility shim, so update any `err.code` comparisons against the listed namespaces. A codebase check now enforces the convention so it cannot regress. A small set of older codes (the cluster, scheduler, circuit-breaker, object-store, and upload subsystems) is intentionally left for the 1.0 release, where it will carry a deprecation cycle. **Changed:** *Bare UPPER_SNAKE error codes are now namespaced (breaking)* — Fifteen namespaces threw bare UPPER_SNAKE error codes with no namespace prefix (for example `mcp` threw `BAD_JSON`, `BAD_ENVELOPE`, `BAD_METHOD`). Their `err.code` values are now `namespace/kebab-case` — `mcp/bad-json`, `mcp/bad-envelope`, and so on. The affected namespaces are `b.a2a`, `b.aiInput`, `b.aiPref`, `b.budr`, `b.contentCredentials`, `b.darkPatterns`, `b.fapi2`, `b.fdx`, `b.graphqlFederation`, `b.iabTcf`, `b.iabMspa`, `b.mcp`, `b.secCyber`, `b.sse`, and `b.tcpa10dlc`. Operators matching the old bare codes on `err.code` must update those comparisons; the error message text is unchanged. · *camelCase error-code namespaces are now kebab-case (breaking)* — Nine namespaces emitted error codes whose namespace segment was camelCase (for example `aiDp/bad-bound`, `argParser/flag-duplicate`). The namespace segment is now kebab-case to match every other code: `ai-dp/`, `ai-capability/`, `ai-quota/`, `arg-parser/`, `audit-sign/`, `auth-step-up/`, `ddl-change-control/`, `dr-runbook/`, `tenant-quota/`, and `boot-gates/`. The `b.*` API namespace keys themselves are unchanged (those remain camelCase, e.g. `b.argParser`); only the `err.code` string changed. Operators matching these `err.code` strings must update them. **Detectors:** *Error-code shape is enforced* — A codebase check now flags any error code constructed via `new XError(...)` or the per-class `factory(...)` whose value is a bare UPPER_SNAKE string or carries a camelCase namespace segment, so the `namespace/kebab-case` contract cannot silently regress. It correctly ignores native error constructors (whose first argument is the message, not a code).
|
package/README.md
CHANGED
|
@@ -119,20 +119,17 @@ The framework bundles the surface a typical Node app reaches for. Every primitiv
|
|
|
119
119
|
### HTTP
|
|
120
120
|
|
|
121
121
|
- **Router + API specs** — schema-validated routes; OpenAPI publication (`b.openapi`) + AsyncAPI publication for event/streaming (`b.asyncapi`)
|
|
122
|
-
- **Middleware stack (wired by `
|
|
123
|
-
-
|
|
124
|
-
- CORS with W3C Private Network Access preflight refusal default + `allowPrivateNetwork` opt
|
|
125
|
-
- Rate-limit
|
|
122
|
+
- **Middleware stack (`createApp`)** — security layers wired ON by default (Core Rule §3); each is configurable via `middleware.<name>` (operator cookie / field names flow straight through — nothing static is baked in) or opt-out with `false` (disabling a default is audited via `app.middleware.disabled`). Ordered so each layer has what it needs (cookies + CSP nonce + fetch-metadata, then body parser, then CSRF last):
|
|
123
|
+
- Request-ID tagging and bot-guard
|
|
126
124
|
- Security headers with `Permissions-Policy` defaults denying storage-access / browsing-topics / private-aggregation / controlled-frame
|
|
127
|
-
- CSP nonce
|
|
128
|
-
- Body parser — JSON / urlencoded / text / multipart; multipart file parts stream to a tmp dir or buffer in memory (`storage: "memory"`) for read-only / serverless filesystems
|
|
129
|
-
- Compression
|
|
130
|
-
- SSE
|
|
131
|
-
- Request log
|
|
132
125
|
- Threat-aware cookie parser (`b.middleware.cookies`)
|
|
133
|
-
-
|
|
134
|
-
-
|
|
126
|
+
- CSP nonce — generated per request, merged into the CSP (`b.middleware.cspNonce`)
|
|
127
|
+
- Fetch-metadata resource-isolation guard (`b.middleware.fetchMetadata`)
|
|
128
|
+
- Body parser — JSON / urlencoded / text / multipart; multipart file parts stream to a tmp dir or buffer in memory (`storage: "memory"`) for read-only / serverless filesystems
|
|
129
|
+
- CSRF protection — double-submit cookie + Origin/Referer cross-check; auto-skips Authorization-header / cookieless requests, which are not CSRF-able (`b.middleware.csrfProtect`)
|
|
130
|
+
- CORS (W3C Private Network Access preflight refusal default + `allowPrivateNetwork` opt) and rate-limit are wired when configured via `middleware.cors` / `middleware.rateLimit`
|
|
135
131
|
- `Cache-Control: no-store` on every 401 from `requireAuth` / `requireAal` / `requireStepUp` per RFC 9111 §5.2.2.5
|
|
132
|
+
- **Additional middleware** to mount in your `routes` callback: compression, SSE, request logging, request-time DB role binding (`b.middleware.dbRoleFor`), in-process CIDR fence (`b.middleware.networkAllowlist`)
|
|
136
133
|
- **Outbound HTTP client** — HTTP/1.1 + HTTP/2 with SSRF gate (cloud-metadata IPs hard-denied; private / loopback / link-local overridable per call); scheme + userinfo + per-host destination allowlist; redirects, multipart, interceptors, progress, encrypted cookie jar (`b.httpClient`, `b.ssrfGuard`, `b.safeUrl`)
|
|
137
134
|
- **Network configurability (`b.network`)** — env-driven NTP / NTS (RFC 8915), IPv4/IPv6 NTP, DNS with IPv6 / DoH / DoT (private-CA pinning) / cache / lookup timeout; local DNSSEC signature verification (RFC 4035 — `b.network.dns.dnssec.verifyRrset` over a canonicalised RRset against RSA / ECDSA P-256·P-384 / Ed25519 DNSKEYs, plus DS-digest + key-tag, plus `verifyDenial` for NSEC / NSEC3 (RFC 5155) NXDOMAIN / NODATA proofs with iteration caps + Opt-Out handling, plus `verifyChain` to validate a full root→TLD→zone delegation chain against the pinned IANA root anchors) so a resolver client can verify both positive and negative answers instead of trusting the upstream AD bit; DANE / TLSA certificate matching (RFC 6698/7671 — `b.network.dns.dane.matchCertificate`) to pin a service's key through DNSSEC instead of a public CA; TSIG transaction signatures (RFC 8945 — `b.network.dns.tsig.sign` / `verify`) for shared-key HMAC authentication of zone transfers, dynamic updates, and query/response pairs, with constant-time MAC compare + fudge-window check (verified against dnspython); outbound HTTP proxy (`HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`); runtime DPI trust-store CA additions; application-level heartbeats; TCP socket defaults
|
|
138
135
|
- **Error pages** — operator-rendered, no app-frame leakage (`b.errorPage`)
|
package/lib/app.js
CHANGED
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
var nodeFs = require("node:fs");
|
|
93
93
|
var nodePath = require("node:path");
|
|
94
94
|
var appShutdown = require("./app-shutdown");
|
|
95
|
+
var audit = require("./audit");
|
|
95
96
|
var C = require("./constants");
|
|
96
97
|
var cluster = require("./cluster");
|
|
97
98
|
var db = require("./db");
|
|
@@ -103,13 +104,28 @@ var queue = require("./queue");
|
|
|
103
104
|
var routerMod = require("./router");
|
|
104
105
|
var vault = require("./vault");
|
|
105
106
|
|
|
106
|
-
function _resolveMiddlewareOpt(value, allowDefault) {
|
|
107
|
+
function _resolveMiddlewareOpt(value, allowDefault, name) {
|
|
107
108
|
// value can be:
|
|
108
109
|
// false — operator opted out
|
|
109
110
|
// undefined — fall back to allowDefault (mount with empty opts)
|
|
110
111
|
// true — explicit opt-in with default opts
|
|
111
112
|
// object — explicit opts
|
|
112
|
-
if (value === false)
|
|
113
|
+
if (value === false) {
|
|
114
|
+
// Operator explicitly disabled this middleware. When it's one of the
|
|
115
|
+
// security-on-by-default layers (allowDefault), leave an audit trace
|
|
116
|
+
// so the weakened posture is visible — Core Rule §3 security defaults
|
|
117
|
+
// shouldn't be silently opt-out-able. Drop-silent observability sink.
|
|
118
|
+
if (allowDefault && name) {
|
|
119
|
+
try {
|
|
120
|
+
audit.safeEmit({
|
|
121
|
+
action: "app.middleware.disabled",
|
|
122
|
+
outcome: "success",
|
|
123
|
+
metadata: { middleware: name },
|
|
124
|
+
});
|
|
125
|
+
} catch (_e) { /* drop-silent — by design */ }
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
113
129
|
if (value === undefined) return allowDefault ? {} : null;
|
|
114
130
|
if (value === true) return {};
|
|
115
131
|
if (value && typeof value === "object") return value;
|
|
@@ -196,21 +212,55 @@ async function createApp(opts) {
|
|
|
196
212
|
});
|
|
197
213
|
router.use(orchestrator.middleware());
|
|
198
214
|
|
|
199
|
-
var requestIdOpts = _resolveMiddlewareOpt(mwConfig.requestId, true);
|
|
215
|
+
var requestIdOpts = _resolveMiddlewareOpt(mwConfig.requestId, true, "requestId");
|
|
200
216
|
if (requestIdOpts) router.use(middleware.requestId(requestIdOpts));
|
|
201
217
|
|
|
202
|
-
var securityHeadersOpts = _resolveMiddlewareOpt(mwConfig.securityHeaders, true);
|
|
218
|
+
var securityHeadersOpts = _resolveMiddlewareOpt(mwConfig.securityHeaders, true, "securityHeaders");
|
|
203
219
|
if (securityHeadersOpts) router.use(middleware.securityHeaders(securityHeadersOpts));
|
|
204
220
|
|
|
205
|
-
var corsOpts = _resolveMiddlewareOpt(mwConfig.cors, false);
|
|
221
|
+
var corsOpts = _resolveMiddlewareOpt(mwConfig.cors, false, "cors");
|
|
206
222
|
if (corsOpts) router.use(middleware.cors(corsOpts));
|
|
207
223
|
|
|
208
|
-
var botGuardOpts = _resolveMiddlewareOpt(mwConfig.botGuard, true);
|
|
224
|
+
var botGuardOpts = _resolveMiddlewareOpt(mwConfig.botGuard, true, "botGuard");
|
|
209
225
|
if (botGuardOpts) router.use(middleware.botGuard(botGuardOpts));
|
|
210
226
|
|
|
211
|
-
var rateLimitOpts = _resolveMiddlewareOpt(mwConfig.rateLimit, false);
|
|
227
|
+
var rateLimitOpts = _resolveMiddlewareOpt(mwConfig.rateLimit, false, "rateLimit");
|
|
212
228
|
if (rateLimitOpts) router.use(middleware.rateLimit(rateLimitOpts));
|
|
213
229
|
|
|
230
|
+
// Security middleware wired ON by default (Core Rule §3). Each reads its
|
|
231
|
+
// config from opts.middleware.<name>: pass `false` to opt out (audited
|
|
232
|
+
// via _resolveMiddlewareOpt), or an object to customize — operator cookie
|
|
233
|
+
// / field names flow straight through, nothing static is baked in.
|
|
234
|
+
// Ordered so each layer has what it needs: cookies + cspNonce +
|
|
235
|
+
// fetchMetadata first, then bodyParser (so csrf can read a body-field
|
|
236
|
+
// token), then csrfProtect last. Every layer is idempotent — if an
|
|
237
|
+
// operator also mounts one of these inside opts.routes, the second mount
|
|
238
|
+
// is a no-op rather than a double-apply.
|
|
239
|
+
var cookiesOpts = _resolveMiddlewareOpt(mwConfig.cookies, true, "cookies");
|
|
240
|
+
if (cookiesOpts) router.use(middleware.cookies(cookiesOpts));
|
|
241
|
+
|
|
242
|
+
var cspNonceOpts = _resolveMiddlewareOpt(mwConfig.cspNonce, true, "cspNonce");
|
|
243
|
+
if (cspNonceOpts) router.use(middleware.cspNonce(cspNonceOpts));
|
|
244
|
+
|
|
245
|
+
var fetchMetadataOpts = _resolveMiddlewareOpt(mwConfig.fetchMetadata, true, "fetchMetadata");
|
|
246
|
+
if (fetchMetadataOpts) router.use(middleware.fetchMetadata(fetchMetadataOpts));
|
|
247
|
+
|
|
248
|
+
var bodyParserOpts = _resolveMiddlewareOpt(mwConfig.bodyParser, true, "bodyParser");
|
|
249
|
+
if (bodyParserOpts) router.use(middleware.bodyParser(bodyParserOpts));
|
|
250
|
+
|
|
251
|
+
var csrfOpts = _resolveMiddlewareOpt(mwConfig.csrf, true, "csrf");
|
|
252
|
+
if (csrfOpts) {
|
|
253
|
+
// Defaults: double-submit cookie (unless the operator chose a token
|
|
254
|
+
// lookup or their own cookie config) + skip validation for stateless
|
|
255
|
+
// token-API / cookieless requests. Operator config overrides both.
|
|
256
|
+
var csrfDefaults = { skipStateless: true };
|
|
257
|
+
if (csrfOpts.tokenLookup === undefined && csrfOpts.cookie === undefined) {
|
|
258
|
+
csrfDefaults.cookie = true;
|
|
259
|
+
}
|
|
260
|
+
csrfOpts = Object.assign(csrfDefaults, csrfOpts);
|
|
261
|
+
router.use(middleware.csrfProtect(csrfOpts));
|
|
262
|
+
}
|
|
263
|
+
|
|
214
264
|
// ---- 6. Operator routes ----
|
|
215
265
|
if (typeof opts.routes === "function") {
|
|
216
266
|
opts.routes(router);
|
package/lib/audit.js
CHANGED
|
@@ -243,6 +243,7 @@ var FRAMEWORK_NAMESPACES = [
|
|
|
243
243
|
"auth", "system", "audit", "consent", "subject",
|
|
244
244
|
// Per-primitive namespaces — keep alphabetical
|
|
245
245
|
"apikey", // b.apiKey
|
|
246
|
+
"app", // b.createApp (app.middleware.disabled — a security-default middleware was opted out at construction)
|
|
246
247
|
"backup", // b.backup
|
|
247
248
|
"breakglass", // b.breakGlass — column-policy / row-enforcement step-up auth (audit namespace lowercased per the validator's `namespace.verb` rule, same convention as b.apiKey → apikey.*)
|
|
248
249
|
"cache", // b.cache
|
|
@@ -89,6 +89,10 @@ function create(opts) {
|
|
|
89
89
|
var audit = opts.audit || null;
|
|
90
90
|
|
|
91
91
|
return function cookiesMiddleware(req, res, next) {
|
|
92
|
+
// Idempotent: if an earlier cookies middleware already parsed the jar
|
|
93
|
+
// this request (e.g. createApp wired it AND an operator mounted it
|
|
94
|
+
// again), don't re-parse — keep the first jar.
|
|
95
|
+
if (req.cookieJar !== undefined) return next();
|
|
92
96
|
var header = req && req.headers ? req.headers.cookie : "";
|
|
93
97
|
var rv = cookies.parseSafe(header || "", {
|
|
94
98
|
maxHeaderBytes: maxHeaderBytes,
|
|
@@ -333,6 +333,10 @@ function create(opts) {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
function cspNonce(req, res, next) {
|
|
336
|
+
// Idempotent: if an earlier cspNonce middleware already set a nonce on
|
|
337
|
+
// this request, keep it — re-generating would desync the header nonce
|
|
338
|
+
// from the one templates already rendered against.
|
|
339
|
+
if (req[property] !== undefined) return next();
|
|
336
340
|
// Generate the nonce. Cheap (16 bytes from getrandom → SHAKE256 →
|
|
337
341
|
// base64 encode); do it always for consistency unless `always:
|
|
338
342
|
// false` was set explicitly.
|
|
@@ -261,6 +261,7 @@ function _writeReject(res, message) {
|
|
|
261
261
|
* requireJsonContentType: boolean,
|
|
262
262
|
* trustProxy: boolean|number,
|
|
263
263
|
* audit: boolean,
|
|
264
|
+
* skipStateless: boolean, // default false — skip validation for Authorization-header / cookieless (not-CSRF-able) requests
|
|
264
265
|
* }
|
|
265
266
|
*
|
|
266
267
|
* @example
|
|
@@ -278,7 +279,7 @@ function create(opts) {
|
|
|
278
279
|
validateOpts(opts, [
|
|
279
280
|
"cookie", "tokenLookup", "fieldName", "headerName", "methods", "audit",
|
|
280
281
|
"trustProxy", "checkOrigin", "allowedOrigins", "requireJsonContentType",
|
|
281
|
-
"requireOrigin",
|
|
282
|
+
"requireOrigin", "skipStateless",
|
|
282
283
|
], "middleware.csrfProtect");
|
|
283
284
|
var trustProxy = opts.trustProxy === true || typeof opts.trustProxy === "number"
|
|
284
285
|
? opts.trustProxy : false;
|
|
@@ -335,6 +336,19 @@ function create(opts) {
|
|
|
335
336
|
// is opt-in rather than silent.
|
|
336
337
|
var requireOriginOpt = opts.requireOrigin === true;
|
|
337
338
|
|
|
339
|
+
// skipStateless — skip token VALIDATION for requests that carry an
|
|
340
|
+
// Authorization header (bearer / token auth) or no Cookie header at
|
|
341
|
+
// all. Such requests are not CSRF-able: CSRF abuses a victim's ambient
|
|
342
|
+
// cookie credential, and a token-authenticated or cookieless request
|
|
343
|
+
// has none to abuse. The token is still ISSUED on safe methods so a
|
|
344
|
+
// later cookie-authenticated browser flow on the same app works. Default
|
|
345
|
+
// false (strict — every state-changing request is validated). createApp
|
|
346
|
+
// wires its default csrf with this on so mixed browser-form + token-API
|
|
347
|
+
// surfaces don't reject legitimate API clients. Cross-site form CSRF is
|
|
348
|
+
// unaffected: the browser auto-sends the victim's cookies, so the attack
|
|
349
|
+
// request always carries a Cookie header and is validated.
|
|
350
|
+
var skipStateless = opts.skipStateless === true;
|
|
351
|
+
|
|
338
352
|
// Cookie issuance config (only when opts.cookie is set).
|
|
339
353
|
var cookieCfg = null;
|
|
340
354
|
if (hasCookie) {
|
|
@@ -436,6 +450,12 @@ function create(opts) {
|
|
|
436
450
|
}
|
|
437
451
|
|
|
438
452
|
return function csrfProtect(req, res, next) {
|
|
453
|
+
// Idempotent: a second csrf mount this request (e.g. createApp wired
|
|
454
|
+
// it AND an operator mounted it again) is a no-op — the first instance
|
|
455
|
+
// already issued + validated.
|
|
456
|
+
if (req._csrfApplied) return next();
|
|
457
|
+
req._csrfApplied = true;
|
|
458
|
+
|
|
439
459
|
// Issue/refresh the token on EVERY request (safe + state-changing)
|
|
440
460
|
// when running in cookie mode — templates rendered after a POST
|
|
441
461
|
// (e.g. error response) still need req.csrfToken populated.
|
|
@@ -443,6 +463,14 @@ function create(opts) {
|
|
|
443
463
|
|
|
444
464
|
if (methods.indexOf(req.method) === -1) return next();
|
|
445
465
|
|
|
466
|
+
// Stateless / token-authenticated requests are not CSRF-able — the
|
|
467
|
+
// token was still issued above for any later browser flow.
|
|
468
|
+
if (skipStateless) {
|
|
469
|
+
var hasAuthHeader = !!(req.headers && req.headers.authorization);
|
|
470
|
+
var hasCookieHeader = !!(req.headers && req.headers.cookie);
|
|
471
|
+
if (hasAuthHeader || !hasCookieHeader) return next();
|
|
472
|
+
}
|
|
473
|
+
|
|
446
474
|
// requireJsonContentType — refuse before the token check.
|
|
447
475
|
if (requireJsonCt) {
|
|
448
476
|
var ct = req.headers && req.headers["content-type"];
|
|
@@ -120,6 +120,9 @@ function create(opts) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
return function fetchMetadata(req, res, next) {
|
|
123
|
+
// Idempotent: a second fetch-metadata mount this request is a no-op.
|
|
124
|
+
if (req._fetchMetadataChecked) return next();
|
|
125
|
+
req._fetchMetadataChecked = true;
|
|
123
126
|
if (methods.indexOf(req.method) === -1) return next();
|
|
124
127
|
|
|
125
128
|
var headers = req.headers || {};
|
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.5",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:f993db8e-7dd3-41d0-95bd-33ee9d07ab8f",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-05-
|
|
8
|
+
"timestamp": "2026-05-30T02:44:28.905Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/core@0.13.
|
|
22
|
+
"bom-ref": "@blamejs/core@0.13.46",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "blamejs",
|
|
25
|
-
"version": "0.13.
|
|
25
|
+
"version": "0.13.46",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "The Node framework that owns its stack.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/core@0.13.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/core@0.13.46",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/core@0.13.
|
|
57
|
+
"ref": "@blamejs/core@0.13.46",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|