@blamejs/core 0.4.26 → 0.4.27
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 +1 -0
- package/lib/error-page.js +3 -10
- package/lib/forms.js +5 -4
- package/lib/mail.js +5 -4
- package/lib/object-store/sigv4-bucket-ops.js +12 -8
- package/lib/safe-schema.js +42 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,7 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.4.x
|
|
10
10
|
|
|
11
|
+
- **0.4.26** (2026-04-30) — primitive-drift sweep: middleware audit context + safeUrl
|
|
11
12
|
- **0.4.25** (2026-04-30) — b.objectStore.bucketOps: bucket-level operations (SigV4)
|
|
12
13
|
- **0.4.24** (2026-04-30) — b.objectStore: multipart upload + server-side encryption
|
|
13
14
|
- **0.4.23** (2026-04-30) — b.mail.dkim signing + calendar invites
|
package/lib/error-page.js
CHANGED
|
@@ -39,8 +39,11 @@
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
var lazyRequire = require("./lazy-require");
|
|
42
|
+
var template = require("./template");
|
|
42
43
|
var audit = lazyRequire(function () { return require("./audit"); });
|
|
43
44
|
|
|
45
|
+
var _esc = template.escapeHtml;
|
|
46
|
+
|
|
44
47
|
// Status code → default short reason. Used when the error doesn't carry
|
|
45
48
|
// its own message (e.g. a generic Error thrown from a route).
|
|
46
49
|
var STATUS_REASONS = {
|
|
@@ -114,16 +117,6 @@ function _wantsJson(req, defaultFormat) {
|
|
|
114
117
|
return req && req.method && req.method.toUpperCase() !== "GET";
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
function _esc(s) {
|
|
118
|
-
if (s === undefined || s === null) return "";
|
|
119
|
-
return String(s)
|
|
120
|
-
.replace(/&/g, "&")
|
|
121
|
-
.replace(/</g, "<")
|
|
122
|
-
.replace(/>/g, ">")
|
|
123
|
-
.replace(/"/g, """)
|
|
124
|
-
.replace(/'/g, "'");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
120
|
function _redactHeaders(headers) {
|
|
128
121
|
if (!headers || typeof headers !== "object") return {};
|
|
129
122
|
var out = {};
|
package/lib/forms.js
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
* forms.escapeHtml = template.escapeHtml (re-export for convenience)
|
|
37
37
|
*/
|
|
38
38
|
var nodeCrypto = require("crypto");
|
|
39
|
+
var safeSchema = require("./safe-schema");
|
|
39
40
|
var safeUrl = require("./safe-url");
|
|
40
41
|
var template = require("./template");
|
|
41
42
|
|
|
@@ -319,10 +320,10 @@ function validate(spec, body) {
|
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
if (f.type === "email" && typeof coerced === "string") {
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
if (
|
|
323
|
+
// Same pragmatic check the rest of the framework uses
|
|
324
|
+
// (safeSchema.EMAIL_RE — shared so we don't carry parallel
|
|
325
|
+
// copies of the same /^[^\s@]+@[^\s@]+\.[^\s@]+$/ regex).
|
|
326
|
+
if (!safeSchema.EMAIL_RE.test(coerced)) {
|
|
326
327
|
errors[f.name] = (f.label || f.name) + " must be a valid email address";
|
|
327
328
|
continue;
|
|
328
329
|
}
|
package/lib/mail.js
CHANGED
|
@@ -67,6 +67,7 @@ var audit = lazyRequire(function () { return require("./audit"); });
|
|
|
67
67
|
var httpClient = lazyRequire(function () { return require("./http-client"); });
|
|
68
68
|
var net = lazyRequire(function () { return require("net"); });
|
|
69
69
|
var tls = lazyRequire(function () { return require("tls"); });
|
|
70
|
+
var safeSchema = require("./safe-schema");
|
|
70
71
|
var validateOpts = require("./validate-opts");
|
|
71
72
|
var { FrameworkError } = require("./framework-error");
|
|
72
73
|
|
|
@@ -80,10 +81,10 @@ class MailError extends FrameworkError {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
// Pragmatic email
|
|
84
|
-
// regex is a fool's errand; this catches obvious nonsense
|
|
85
|
-
// real-world addresses through.
|
|
86
|
-
var EMAIL_RE =
|
|
84
|
+
// Pragmatic email regex — shared with forms.validate / safe-schema.
|
|
85
|
+
// RFC 5322 in a regex is a fool's errand; this catches obvious nonsense
|
|
86
|
+
// and lets real-world addresses through.
|
|
87
|
+
var EMAIL_RE = safeSchema.EMAIL_RE;
|
|
87
88
|
|
|
88
89
|
function _normalizeRecipientList(value, label) {
|
|
89
90
|
if (value === undefined || value === null) return [];
|
|
@@ -54,6 +54,7 @@ var nodeCrypto = require("crypto");
|
|
|
54
54
|
var sigv4 = require("./sigv4");
|
|
55
55
|
var safeXml = require("../parsers/safe-xml");
|
|
56
56
|
var safeUrl = require("../safe-url");
|
|
57
|
+
var template = require("../template");
|
|
57
58
|
var httpClient = require("../http-client");
|
|
58
59
|
var { ObjectStoreError } = require("../framework-error");
|
|
59
60
|
|
|
@@ -83,15 +84,18 @@ function _validateBucketName(name) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.replace(/'/g, "'");
|
|
93
|
-
}
|
|
87
|
+
// XML body strings flow through template.escapeHtml — `'` (which
|
|
88
|
+
// it emits for the apostrophe) is a numeric character reference and
|
|
89
|
+
// is valid in both XML and HTML, where `'` is XML-only. AWS S3
|
|
90
|
+
// accepts both; using the shared HTML escape keeps the framework
|
|
91
|
+
// down to one canonical escape primitive.
|
|
92
|
+
var _xmlEscape = template.escapeHtml;
|
|
94
93
|
|
|
94
|
+
// AWS PutBucketLifecycle / PutBucketCors require a Content-MD5 header
|
|
95
|
+
// for body integrity (legacy AWS API requirement; SigV4 already covers
|
|
96
|
+
// integrity via x-amz-content-sha256 but the API still validates this).
|
|
97
|
+
// MD5 here is NOT a credential or security primitive — it's an AWS API
|
|
98
|
+
// shape. b.credentialHash is the wrong tool.
|
|
95
99
|
function _md5Base64(buf) {
|
|
96
100
|
return nodeCrypto.createHash("md5").update(buf).digest("base64");
|
|
97
101
|
}
|
package/lib/safe-schema.js
CHANGED
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
* so the two stay distinct rather than one wrapping the other.
|
|
110
110
|
*/
|
|
111
111
|
|
|
112
|
+
var safeJson = require("./safe-json");
|
|
112
113
|
var { defineClass } = require("./framework-error");
|
|
113
114
|
|
|
114
115
|
var SafeSchemaError = defineClass("SafeSchemaError", { alwaysPermanent: true });
|
|
@@ -143,10 +144,17 @@ var ULID_RE = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
|
143
144
|
// base64 (standard alphabet, with optional padding). Base64url variants
|
|
144
145
|
// rejected — operators chain .regex(...) for that.
|
|
145
146
|
var BASE64_RE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
146
|
-
// IPv6 —
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
|
|
147
|
+
// IPv6 structural pattern — full 8-hextet, every `::`-compressed shape,
|
|
148
|
+
// `::` and `::1` literals, IPv4-mapped (`::ffff:1.2.3.4`), and 6-prefix
|
|
149
|
+
// + IPv4 tail. Adapted from validator.js (Apache-2.0); zone IDs
|
|
150
|
+
// (`fe80::1%eth0`) are deliberately omitted — the framework rejects
|
|
151
|
+
// them as non-portable, matching `safe-json.formats.ipv6`. Bounded
|
|
152
|
+
// quantifiers, no nested-quantifier alternation, ReDoS-safe.
|
|
153
|
+
//
|
|
154
|
+
// `.ipv6()` schema method delegates to `safeJson.formats.ipv6` for
|
|
155
|
+
// stricter algorithmic validation; this regex is exported as a
|
|
156
|
+
// structural pattern for operators who want it directly.
|
|
157
|
+
var IPV6_RE = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
150
158
|
|
|
151
159
|
// ---- helpers ----
|
|
152
160
|
|
|
@@ -424,22 +432,33 @@ function _stringMethods(schema, spec) {
|
|
|
424
432
|
_fail(p, "string/datetime", "must be an ISO-8601 datetime with timezone");
|
|
425
433
|
});
|
|
426
434
|
};
|
|
435
|
+
// IP-address validators delegate to safe-json's algorithmic format
|
|
436
|
+
// checks rather than re-running regex matches. The algorithmic path
|
|
437
|
+
// handles edge cases that pure regex misses (compressed `::` shapes,
|
|
438
|
+
// IPv4-mapped `::ffff:1.2.3.4`, multi-`::` rejection, group-count
|
|
439
|
+
// bounds) and keeps the framework's IP-validation behavior in one
|
|
440
|
+
// tested place. IPV4_RE / IPV6_RE remain exported for operators who
|
|
441
|
+
// want the structural pattern, but `.ipv4()` / `.ipv6()` / `.ip()`
|
|
442
|
+
// are the canonical validation surface.
|
|
427
443
|
schema.ipv4 = function () {
|
|
428
444
|
return chain(function (v, p) {
|
|
429
|
-
return
|
|
430
|
-
|
|
445
|
+
return (typeof v === "string" && safeJson.formats.ipv4(v))
|
|
446
|
+
? { ok: true }
|
|
447
|
+
: _fail(p, "string/ipv4", "must be a valid IPv4 address");
|
|
431
448
|
});
|
|
432
449
|
};
|
|
433
450
|
schema.ipv6 = function () {
|
|
434
451
|
return chain(function (v, p) {
|
|
435
|
-
return
|
|
436
|
-
|
|
452
|
+
return (typeof v === "string" && safeJson.formats.ipv6(v))
|
|
453
|
+
? { ok: true }
|
|
454
|
+
: _fail(p, "string/ipv6", "must be a valid IPv6 address");
|
|
437
455
|
});
|
|
438
456
|
};
|
|
439
457
|
schema.ip = function () {
|
|
440
458
|
return chain(function (v, p) {
|
|
441
|
-
return (
|
|
442
|
-
|
|
459
|
+
return (typeof v === "string" && safeJson.formats.ip(v))
|
|
460
|
+
? { ok: true }
|
|
461
|
+
: _fail(p, "string/ip", "must be a valid IP address (v4 or v6)");
|
|
443
462
|
});
|
|
444
463
|
};
|
|
445
464
|
schema.cuid = function () {
|
|
@@ -1173,4 +1192,17 @@ module.exports = {
|
|
|
1173
1192
|
|
|
1174
1193
|
// Errors
|
|
1175
1194
|
SafeSchemaError: SafeSchemaError,
|
|
1195
|
+
|
|
1196
|
+
// Validation regexes — exported so other modules don't re-declare
|
|
1197
|
+
// their own copies. Pragmatic patterns; operators wanting RFC-strict
|
|
1198
|
+
// behavior chain `.refine()` on top of the schema instead.
|
|
1199
|
+
EMAIL_RE: EMAIL_RE,
|
|
1200
|
+
URL_RE: URL_RE,
|
|
1201
|
+
UUID_RE: UUID_RE,
|
|
1202
|
+
DATE_RE: DATE_RE,
|
|
1203
|
+
DATETIME_RE: DATETIME_RE,
|
|
1204
|
+
IPV4_RE: IPV4_RE,
|
|
1205
|
+
IPV6_RE: IPV6_RE,
|
|
1206
|
+
CUID_RE: CUID_RE,
|
|
1207
|
+
ULID_RE: ULID_RE,
|
|
1176
1208
|
};
|