@blamejs/core 0.7.80 → 0.7.82
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 +4 -0
- package/lib/mail-bimi.js +133 -0
- package/lib/mail.js +2 -0
- package/lib/middleware/host-allowlist.js +159 -0
- package/lib/middleware/index.js +3 -0
- package/package.json +1 -1
- package/sbom.cyclonedx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,10 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.7.x
|
|
10
10
|
|
|
11
|
+
- **0.7.82** (2026-05-06) — `b.mail.bimi` — BIMI record builder + verifier (RFC 9091). BIMI publishes a sender's brand logo URL in DNS so receiving MTAs can render it next to the message in supported clients (Gmail, Yahoo, Apple Mail). **`b.mail.bimi.recordShape({ logoUrl, vmcUrl?, selector? })`** produces the canonical `v=BIMI1; l=https://...; a=https://...` TXT-record string per RFC 9091 §4. Both `l=` (SVG logo URL) and `a=` (Verified Mark Certificate URL per RFC 9091 §6) are HTTPS-required (refuses `http://`). All field values are CR/LF/NUL/semicolon-screened so a hostile URL can't inject a record-separator into the published TXT. **`b.mail.bimi.fetchPolicy(domain, { selector?, dnsLookup? })`** queries `<selector>._bimi.<domain>` (default selector `"default"`) and returns the structured record `{ v, l, a }` or `null` when no policy is published / record is malformed. **`b.mail.bimi.parseRecord(text)`** parses any operator-supplied TXT body — semicolon-separated `key=value` pairs per RFC 9091 §4. The framework does NOT validate the SVG / VMC contents against the RFC §5/§6 profiles — operators feed those to their own asset pipeline; the fetch primitive is a thin DNS lookup that returns the structured record so an operator dashboard or SMTP send-time preflight can verify the publication. BIMI is layered on a passing DMARC posture (the receiver requires DMARC quarantine/reject); operators with the existing `b.mail.dmarc` posture set up benefit from BIMI rendering immediately on receivers that honor it.
|
|
12
|
+
|
|
13
|
+
- **0.7.81** (2026-05-06) — `b.middleware.hostAllowlist` — DNS rebinding defense. Refuses requests whose `Host` header doesn't match the operator-supplied allowlist; the DNS rebinding chain (attacker DNS flips evil.com → 127.0.0.1, browser still believes the URL string says "evil.com" so same-origin policy lets the JS read the response, but the operator's localhost is what actually serves) is closed by checking the post-DNS-resolution `Host` header on the framework's side. **`b.middleware.hostAllowlist({ hosts, denyStatus?, denyBody?, audit? })`** — operators pass an allowlist of canonical Host values (with or without port). Wildcard-leading entries (`*.example.com`) match any single label; `app.sub.example.com` does NOT match `*.example.com` (multi-label rejected by design — a wildcard certificate authority issues only single-label intermediate). Entries without a port match any port; entries with a port require exact match. Default `denyStatus: 421` (RFC 7540 §9.1.2 "Misdirected Request"); default `denyBody: "Misdirected Request"`. Audit emits `network.host_allowlist.denied` with the reason (`missing-host` / `host-not-in-allowlist`) and the actual Host value for triage. Operators running explicitly-public services that accept arbitrary subdomains (multi-tenant forum shapes) skip this middleware entirely; there's no per-request opt-out.
|
|
14
|
+
|
|
11
15
|
- **0.7.80** (2026-05-06) — `b.middleware.securityTxt` (RFC 9116) + SQLite `secure_delete=ON` at DB boot. **`b.middleware.securityTxt({ contact, expires, encryption?, policy?, ack?, preferredLanguages?, hiring?, canonical?, alsoAtRoot?, audit? })`** serves a static body at `/.well-known/security.txt` (and root `/security.txt` when `alsoAtRoot: true`) per RFC 9116. Operators wire it on their app so security researchers know where to find the disclosure policy. The `Contact:` and `Expires:` fields are REQUIRED per §2.5; the framework throws at config-time when either is missing AND when `expires` is in the past (RFC 9116 §2.5.5). All field values are CR/LF/NUL-screened (header injection defense). Body is built once at create() and served with `Content-Length` + `Cache-Control: public, max-age=86400` + `X-Content-Type-Options: nosniff`. **SQLite `PRAGMA secure_delete=ON`** is now applied at `b.db.init` time alongside the existing PRAGMA block. SQLite normally just unlinks rows from the B-tree; the underlying page bytes survive on disk until a new write reuses the slot. With `secure_delete=ON`, freed pages are overwritten with zeros so a forensic recovery against the encrypted database file can't reconstruct deleted rows. The cost is one extra write per delete — already dominated by the framework's audit-chain emissions on every DSR erase / cascade fan-out.
|
|
12
16
|
|
|
13
17
|
- **0.7.79** (2026-05-06) — PQC TLS handshake key shares + DB hardening sweep (3 items). **`b.network.tls.pqc`** — operator-facing TLS 1.3 key-share configuration. The framework's app-layer envelope has been PQC-first since v0.7.28 (ML-KEM-1024 + X25519 hybrid for sealed records); this slice extends PQC posture down to the **TLS handshake itself**. `b.network.tls.pqc.setKeyShares(["X25519MLKEM768", "X25519", "secp256r1"])` configures the TLS 1.3 key-share groups the framework's `https.Server` / `https.Agent` advertises. The first listed group is the operator priority; the peer picks the first mutually supported entry. **`X25519MLKEM768`** is the IETF draft-kwiatkowski-tls-ecdhe-mlkem-02 hybrid KEM that negotiates post-quantum + classical in one handshake — forward-secrecy survives both classical-CRQC and future quantum cryptanalysis. Default list is `["X25519MLKEM768", "X25519", "secp256r1"]` so the framework attempts hybrid first, falls back to classical X25519 with peers that don't support the hybrid (most of the public web today), and to `secp256r1` for legacy peers. **`b.network.tls.applyToContext({ base })`** now threads the configured key-share list through as the `groups` option to Node's TLS context (operators who explicitly set `groups` in their `base` config keep the override). Operators wanting classical-only call `b.network.tls.pqc.setKeyShares(["X25519"])`; calling `.resetKeyShares()` restores the default. Requires Node 24+ with OpenSSL 3.5+ for the X25519MLKEM768 group; older Node falls back silently to the classical entries. **DB hardening: PRAGMA integrity_check at boot** — `b.db.init` now runs `PRAGMA integrity_check` after the existing PRAGMA block and refuses boot if SQLite reports anything other than `"ok"`. Catches B-tree corruption at boot rather than letting it surface mid-query when the engine stumbles on a bad page. Skip via `opts.skipIntegrityCheck: true` for tmpfs-only fixtures (audited reason). **DB hardening: migration-lock holder ID boot token** — `lib/external-db-migrate.js:_lockHolderId()` now appends a per-process random 8-byte boot token, so a recycled PID-on-hostname slot after a container restart can't be misattributed back to the new boot when reading stale lock rows. Closes the PID-reuse-across-container-restart concurrent-ownership window flagged in the v0.7.67 audit batch.
|
package/lib/mail-bimi.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BIMI — Brand Indicators for Message Identification (RFC 9091).
|
|
4
|
+
*
|
|
5
|
+
* BIMI records publish a sender's brand logo URL in DNS so receiving
|
|
6
|
+
* MTAs can render it next to the message in supported clients
|
|
7
|
+
* (Gmail, Yahoo, Apple Mail). The record format is:
|
|
8
|
+
*
|
|
9
|
+
* default._bimi.<domain> IN TXT "v=BIMI1; l=https://...; a=https://..."
|
|
10
|
+
*
|
|
11
|
+
* - `l=` URL to the SVG logo file (Tiny PS Profile per RFC 9091 §5)
|
|
12
|
+
* - `a=` URL to the Verified Mark Certificate (VMC) — RFC 9091 §6
|
|
13
|
+
*
|
|
14
|
+
* BIMI is layered on a passing DMARC posture (the receiver requires
|
|
15
|
+
* DMARC to be at quarantine or reject). No-op for senders without
|
|
16
|
+
* DMARC enforcement.
|
|
17
|
+
*
|
|
18
|
+
* Surface:
|
|
19
|
+
* b.mail.bimi.recordShape({ logoUrl, vmcUrl?, selector? }) → string
|
|
20
|
+
* b.mail.bimi.fetchPolicy(domain, opts?) → { v, l, a } | null
|
|
21
|
+
* b.mail.bimi.parseRecord(text) → { v, l, a } | null
|
|
22
|
+
*
|
|
23
|
+
* The framework does NOT validate the SVG / VMC contents against the
|
|
24
|
+
* RFC 9091 §5/§6 profiles — operators feed those to their own asset
|
|
25
|
+
* pipeline. The fetch primitive is a thin DNS lookup that returns
|
|
26
|
+
* the structured record so an operator dashboard or SMTP send-time
|
|
27
|
+
* preflight can verify the publication.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
var dns = require("node:dns");
|
|
31
|
+
var dnsPromises = dns.promises;
|
|
32
|
+
var validateOpts = require("./validate-opts");
|
|
33
|
+
var safeUrl = require("./safe-url");
|
|
34
|
+
var C = require("./constants");
|
|
35
|
+
var { defineClass } = require("./framework-error");
|
|
36
|
+
|
|
37
|
+
var BimiError = defineClass("BimiError", { alwaysPermanent: true });
|
|
38
|
+
|
|
39
|
+
var BIMI_VERSION = "BIMI1";
|
|
40
|
+
var BIMI_DEFAULT_SELECTOR = "default";
|
|
41
|
+
var BIMI_RECORD_MAX_BYTES = C.BYTES.kib(2);
|
|
42
|
+
|
|
43
|
+
function _validateUrl(url, label) {
|
|
44
|
+
// RFC 9091 §4.2 — `l=` and `a=` MUST be HTTPS URLs.
|
|
45
|
+
try {
|
|
46
|
+
safeUrl.parse(url, { allowedProtocols: ["https:"] });
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new BimiError("mail-bimi/bad-" + label,
|
|
49
|
+
"bimi: " + label + " must be an https:// URL — got '" + url + "': " +
|
|
50
|
+
((e && e.message) || String(e)));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function recordShape(opts) {
|
|
55
|
+
validateOpts.requireObject(opts, "bimi.recordShape", BimiError);
|
|
56
|
+
validateOpts(opts, ["logoUrl", "vmcUrl", "selector"], "bimi.recordShape");
|
|
57
|
+
validateOpts.requireNonEmptyString(opts.logoUrl,
|
|
58
|
+
"bimi.recordShape: logoUrl", BimiError, "mail-bimi/no-logo");
|
|
59
|
+
_validateUrl(opts.logoUrl, "logoUrl");
|
|
60
|
+
if (opts.vmcUrl !== undefined && opts.vmcUrl !== null) {
|
|
61
|
+
validateOpts.requireNonEmptyString(opts.vmcUrl,
|
|
62
|
+
"bimi.recordShape: vmcUrl", BimiError, "mail-bimi/bad-vmc");
|
|
63
|
+
_validateUrl(opts.vmcUrl, "vmcUrl");
|
|
64
|
+
}
|
|
65
|
+
// No CR/LF/NUL/semicolon — defense-in-depth so a hostile URL can't
|
|
66
|
+
// inject a record-separator sequence into the published TXT.
|
|
67
|
+
if (/[\r\n\0;]/.test(opts.logoUrl)) {
|
|
68
|
+
throw new BimiError("mail-bimi/bad-logo",
|
|
69
|
+
"bimi.recordShape: logoUrl contains forbidden control / record-separator characters");
|
|
70
|
+
}
|
|
71
|
+
if (opts.vmcUrl && /[\r\n\0;]/.test(opts.vmcUrl)) {
|
|
72
|
+
throw new BimiError("mail-bimi/bad-vmc",
|
|
73
|
+
"bimi.recordShape: vmcUrl contains forbidden control / record-separator characters");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var fields = ["v=" + BIMI_VERSION, "l=" + opts.logoUrl];
|
|
77
|
+
if (opts.vmcUrl) fields.push("a=" + opts.vmcUrl);
|
|
78
|
+
return fields.join("; ");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function parseRecord(text) {
|
|
82
|
+
if (typeof text !== "string" || text.length === 0) return null;
|
|
83
|
+
if (text.length > BIMI_RECORD_MAX_BYTES) return null; // bound BEFORE parse — TXT-record sanity cap
|
|
84
|
+
// RFC 9091 §4 — semicolon-separated, key=value, leading "v=BIMI1".
|
|
85
|
+
var parts = text.split(";");
|
|
86
|
+
var rv = { v: null, l: null, a: null };
|
|
87
|
+
for (var i = 0; i < parts.length; i += 1) {
|
|
88
|
+
var p = parts[i].trim();
|
|
89
|
+
if (p.length === 0) continue;
|
|
90
|
+
var eq = p.indexOf("=");
|
|
91
|
+
if (eq === -1) continue;
|
|
92
|
+
var k = p.slice(0, eq).trim().toLowerCase();
|
|
93
|
+
var v = p.slice(eq + 1).trim();
|
|
94
|
+
if (k === "v" || k === "l" || k === "a") rv[k] = v;
|
|
95
|
+
}
|
|
96
|
+
if (rv.v !== BIMI_VERSION || !rv.l) return null;
|
|
97
|
+
return rv;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function fetchPolicy(domain, opts) {
|
|
101
|
+
validateOpts.requireNonEmptyString(domain,
|
|
102
|
+
"bimi.fetchPolicy: domain", BimiError, "mail-bimi/bad-domain");
|
|
103
|
+
opts = opts || {};
|
|
104
|
+
var selector = opts.selector || BIMI_DEFAULT_SELECTOR;
|
|
105
|
+
var qname = selector + "._bimi." + domain;
|
|
106
|
+
var records;
|
|
107
|
+
try {
|
|
108
|
+
if (opts.dnsLookup) records = await opts.dnsLookup(qname, "TXT");
|
|
109
|
+
else records = await dnsPromises.resolveTxt(qname);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
if (e && (e.code === "ENOTFOUND" || e.code === "ENODATA")) return null;
|
|
112
|
+
throw new BimiError("mail-bimi/lookup-failed",
|
|
113
|
+
"bimi.fetchPolicy: TXT lookup for " + qname + " failed: " +
|
|
114
|
+
((e && e.message) || String(e)));
|
|
115
|
+
}
|
|
116
|
+
// RFC 9091 §4.1 — a TXT lookup may return multiple chunks; pick
|
|
117
|
+
// the first record that begins with v=BIMI1.
|
|
118
|
+
for (var i = 0; i < (records || []).length; i += 1) {
|
|
119
|
+
var rec = records[i];
|
|
120
|
+
var s = Array.isArray(rec) ? rec.join("") : String(rec);
|
|
121
|
+
var parsed = parseRecord(s);
|
|
122
|
+
if (parsed) return parsed;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
recordShape: recordShape,
|
|
129
|
+
parseRecord: parseRecord,
|
|
130
|
+
fetchPolicy: fetchPolicy,
|
|
131
|
+
BIMI_VERSION: BIMI_VERSION,
|
|
132
|
+
BimiError: BimiError,
|
|
133
|
+
};
|
package/lib/mail.js
CHANGED
|
@@ -71,6 +71,7 @@ var httpClient = lazyRequire(function () { return require("./http-client"); });
|
|
|
71
71
|
var guardEmail = lazyRequire(function () { return require("./guard-email"); });
|
|
72
72
|
var mailDkim = require("./mail-dkim");
|
|
73
73
|
var mailAuth = require("./mail-auth");
|
|
74
|
+
var mailBimi = require("./mail-bimi");
|
|
74
75
|
var mailUnsubscribe = require("./mail-unsubscribe");
|
|
75
76
|
var net = lazyRequire(function () { return require("net"); });
|
|
76
77
|
var nodeUrl = require("url");
|
|
@@ -1102,6 +1103,7 @@ module.exports = {
|
|
|
1102
1103
|
dmarc: mailAuth.dmarc,
|
|
1103
1104
|
arc: mailAuth.arc,
|
|
1104
1105
|
authResults: mailAuth.authResults,
|
|
1106
|
+
bimi: mailBimi,
|
|
1105
1107
|
// Test-only export: lets unit tests inspect the wire format without
|
|
1106
1108
|
// standing up a TLS-capable SMTP fixture. Operators don't call this.
|
|
1107
1109
|
_buildRfc822ForTest: _buildRfc822,
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* host-allowlist — DNS rebinding defense.
|
|
4
|
+
*
|
|
5
|
+
* Refuses requests whose `Host` header doesn't match the operator-
|
|
6
|
+
* supplied allowlist. The DNS rebinding attack chain is:
|
|
7
|
+
*
|
|
8
|
+
* 1. Attacker sets a short-TTL DNS record for evil.com pointing
|
|
9
|
+
* at their own server.
|
|
10
|
+
* 2. Victim's browser visits attacker's page; the page issues
|
|
11
|
+
* fetch() requests to evil.com.
|
|
12
|
+
* 3. Attacker's DNS now answers evil.com → 127.0.0.1 (or the
|
|
13
|
+
* operator's internal IP).
|
|
14
|
+
* 4. Browser, applying same-origin policy on the URL string,
|
|
15
|
+
* thinks fetch() is hitting evil.com — but the connection
|
|
16
|
+
* lands on the operator's localhost / internal service.
|
|
17
|
+
* 5. The operator's service serves whatever it would serve to
|
|
18
|
+
* its own admin UI; the JS reads the response.
|
|
19
|
+
*
|
|
20
|
+
* Defense: refuse the request unless the `Host` header (the part
|
|
21
|
+
* the operator's server actually sees) matches a known origin.
|
|
22
|
+
*
|
|
23
|
+
* var allow = b.middleware.hostAllowlist({
|
|
24
|
+
* hosts: ["app.example.com", "app.example.com:443"],
|
|
25
|
+
* denyStatus: 421, // RFC 7540 §9.1.2 "Misdirected Request"
|
|
26
|
+
* denyBody: "Misdirected Request",
|
|
27
|
+
* audit: true,
|
|
28
|
+
* });
|
|
29
|
+
* router.use(allow);
|
|
30
|
+
*
|
|
31
|
+
* Operators behind a CDN / proxy that rewrites the Host header set
|
|
32
|
+
* `hosts` to the post-rewrite values. Wildcard-leading entries
|
|
33
|
+
* (`*.example.com`) match any single label. Localhost is explicitly
|
|
34
|
+
* allowed only when the operator lists it.
|
|
35
|
+
*
|
|
36
|
+
* Operators running an explicitly-public service (anyone-can-host-
|
|
37
|
+
* the-domain shapes — e.g. a forum that serves arbitrary subdomains)
|
|
38
|
+
* skip this middleware entirely; there's no opt-out per request.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
var lazyRequire = require("../lazy-require");
|
|
42
|
+
var requestHelpers = require("../request-helpers");
|
|
43
|
+
var validateOpts = require("../validate-opts");
|
|
44
|
+
var { defineClass } = require("../framework-error");
|
|
45
|
+
|
|
46
|
+
var HostAllowlistError = defineClass("HostAllowlistError", { alwaysPermanent: true });
|
|
47
|
+
|
|
48
|
+
var audit = lazyRequire(function () { return require("../audit"); });
|
|
49
|
+
|
|
50
|
+
function _normalizeHostEntry(s) {
|
|
51
|
+
// Lowercase + strip whitespace. Per RFC 7230 §5.4 the Host header is
|
|
52
|
+
// case-insensitive on the host portion.
|
|
53
|
+
if (typeof s !== "string") return null;
|
|
54
|
+
var t = s.trim().toLowerCase();
|
|
55
|
+
if (t.length === 0) return null;
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Match a single allowlist entry against an actual Host header value.
|
|
60
|
+
// Wildcards: `*.example.com` matches `app.example.com` but not
|
|
61
|
+
// `app.sub.example.com` (single-label only). Exact host:port match
|
|
62
|
+
// is supported when the entry includes a port; entries without a port
|
|
63
|
+
// match any port.
|
|
64
|
+
function _matches(entry, actual) {
|
|
65
|
+
if (entry === actual) return true;
|
|
66
|
+
// Wildcard prefix
|
|
67
|
+
if (entry.indexOf("*.") === 0) {
|
|
68
|
+
var suffix = entry.slice(1); // ".example.com"
|
|
69
|
+
var actualHost = actual.split(":")[0];
|
|
70
|
+
if (actualHost.length <= suffix.length) return false;
|
|
71
|
+
if (actualHost.slice(-suffix.length) !== suffix) return false;
|
|
72
|
+
var prefix = actualHost.slice(0, actualHost.length - suffix.length);
|
|
73
|
+
if (prefix.indexOf(".") !== -1) return false; // single-label
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
// Port-stripped equality — entry without port matches any port
|
|
77
|
+
if (entry.indexOf(":") === -1 && actual.indexOf(":") !== -1) {
|
|
78
|
+
var actualNoPort = actual.split(":")[0];
|
|
79
|
+
return entry === actualNoPort;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function create(opts) {
|
|
85
|
+
validateOpts.requireObject(opts, "middleware.hostAllowlist", HostAllowlistError);
|
|
86
|
+
validateOpts(opts, [
|
|
87
|
+
"hosts", "denyStatus", "denyBody", "audit",
|
|
88
|
+
], "middleware.hostAllowlist");
|
|
89
|
+
|
|
90
|
+
if (!Array.isArray(opts.hosts) || opts.hosts.length === 0) {
|
|
91
|
+
throw new HostAllowlistError("host-allowlist/no-hosts",
|
|
92
|
+
"middleware.hostAllowlist: opts.hosts must be a non-empty array of allowed Host header values");
|
|
93
|
+
}
|
|
94
|
+
var hosts = [];
|
|
95
|
+
for (var i = 0; i < opts.hosts.length; i += 1) {
|
|
96
|
+
var n = _normalizeHostEntry(opts.hosts[i]);
|
|
97
|
+
if (!n) {
|
|
98
|
+
throw new HostAllowlistError("host-allowlist/bad-host",
|
|
99
|
+
"middleware.hostAllowlist: hosts[" + i + "] is not a non-empty string");
|
|
100
|
+
}
|
|
101
|
+
hosts.push(n);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var denyStatus = (typeof opts.denyStatus === "number") ? opts.denyStatus : 421; // allow:raw-byte-literal — HTTP 421 status
|
|
105
|
+
var denyBody = typeof opts.denyBody === "string" ? opts.denyBody : "Misdirected Request";
|
|
106
|
+
var auditOn = opts.audit !== false;
|
|
107
|
+
|
|
108
|
+
return function hostAllowlistMiddleware(req, res, next) {
|
|
109
|
+
var raw = req.headers && req.headers.host;
|
|
110
|
+
if (typeof raw !== "string" || raw.length === 0) {
|
|
111
|
+
// RFC 7230 §5.4 — a request without a Host header is malformed
|
|
112
|
+
// for HTTP/1.1; HTTP/2 maps :authority into req.headers.host
|
|
113
|
+
// automatically. Reject either shape.
|
|
114
|
+
_deny(res, denyStatus, denyBody);
|
|
115
|
+
_emitDenied(req, "missing-host");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var actual = raw.toLowerCase();
|
|
119
|
+
var matched = false;
|
|
120
|
+
for (var hi = 0; hi < hosts.length; hi += 1) {
|
|
121
|
+
if (_matches(hosts[hi], actual)) { matched = true; break; }
|
|
122
|
+
}
|
|
123
|
+
if (!matched) {
|
|
124
|
+
_deny(res, denyStatus, denyBody);
|
|
125
|
+
_emitDenied(req, "host-not-in-allowlist", actual);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
return next();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
function _deny(res, status, body) {
|
|
132
|
+
if (res.headersSent) return;
|
|
133
|
+
res.writeHead(status, {
|
|
134
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
135
|
+
"Content-Length": Buffer.byteLength(body),
|
|
136
|
+
});
|
|
137
|
+
res.end(body);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function _emitDenied(req, reason, actual) {
|
|
141
|
+
if (!auditOn) return;
|
|
142
|
+
try {
|
|
143
|
+
audit().safeEmit({
|
|
144
|
+
action: "network.host_allowlist.denied",
|
|
145
|
+
outcome: "fail",
|
|
146
|
+
actor: { clientIp: requestHelpers.clientIp(req) },
|
|
147
|
+
metadata: {
|
|
148
|
+
reason: reason,
|
|
149
|
+
host: actual || null,
|
|
150
|
+
route: req.url,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
} catch (_e) { /* drop-silent — observability sink failure */ }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = {
|
|
158
|
+
create: create,
|
|
159
|
+
};
|
package/lib/middleware/index.js
CHANGED
|
@@ -33,6 +33,7 @@ var fetchMetadata = require("./fetch-metadata");
|
|
|
33
33
|
var gpc = require("./gpc");
|
|
34
34
|
var headers = require("./headers");
|
|
35
35
|
var health = require("./health");
|
|
36
|
+
var hostAllowlist = require("./host-allowlist");
|
|
36
37
|
var networkAllowlist = require("./network-allowlist");
|
|
37
38
|
var rateLimit = require("./rate-limit");
|
|
38
39
|
var requestId = require("./request-id");
|
|
@@ -69,6 +70,7 @@ module.exports = {
|
|
|
69
70
|
apiEncrypt: apiEncrypt,
|
|
70
71
|
dbRoleFor: dbRoleFor.create,
|
|
71
72
|
dpop: dpop.create,
|
|
73
|
+
hostAllowlist: hostAllowlist.create,
|
|
72
74
|
networkAllowlist: networkAllowlist.create,
|
|
73
75
|
|
|
74
76
|
// Module exports for advanced use (constants, raw factory access)
|
|
@@ -95,6 +97,7 @@ module.exports = {
|
|
|
95
97
|
apiEncrypt: apiEncrypt,
|
|
96
98
|
dbRoleFor: dbRoleFor,
|
|
97
99
|
dpop: dpop,
|
|
100
|
+
hostAllowlist: hostAllowlist,
|
|
98
101
|
networkAllowlist: networkAllowlist,
|
|
99
102
|
},
|
|
100
103
|
};
|
package/package.json
CHANGED
package/sbom.cyclonedx.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:3d6daca5-7eec-417f-a793-a338db272d40",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-05-06T05:
|
|
8
|
+
"timestamp": "2026-05-06T05:54:05.145Z",
|
|
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.7.
|
|
22
|
+
"bom-ref": "@blamejs/core@0.7.82",
|
|
23
23
|
"type": "library",
|
|
24
24
|
"name": "blamejs",
|
|
25
|
-
"version": "0.7.
|
|
25
|
+
"version": "0.7.82",
|
|
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.7.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/core@0.7.82",
|
|
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.7.
|
|
57
|
+
"ref": "@blamejs/core@0.7.82",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|