@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 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, "&lt;")
122
- .replace(/>/g, "&gt;")
123
- .replace(/"/g, "&quot;")
124
- .replace(/'/g, "&#39;");
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
- // Pragmatic email check RFC 5322 is impractical to regex
323
- // correctly; this catches obvious nonsense ("foo", "foo@",
324
- // "@bar") without over-engineering.
325
- if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(coerced)) {
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 checksame shape as forms.validate. RFC 5322 in a
84
- // regex is a fool's errand; this catches obvious nonsense and lets
85
- // real-world addresses through.
86
- var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
84
+ // Pragmatic email regexshared 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
- function _xmlEscape(s) {
87
- return String(s)
88
- .replace(/&/g, "&amp;")
89
- .replace(/</g, "&lt;")
90
- .replace(/>/g, "&gt;")
91
- .replace(/"/g, "&quot;")
92
- .replace(/'/g, "&apos;");
93
- }
87
+ // XML body strings flow through template.escapeHtml — `&#x27;` (which
88
+ // it emits for the apostrophe) is a numeric character reference and
89
+ // is valid in both XML and HTML, where `&apos;` 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
  }
@@ -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 — covers full, compressed (::), and IPv4-mapped forms. Not
147
- // exhaustive on every legal corner, but rejects the common malformed
148
- // inputs operators actually see at HTTP boundaries.
149
- var IPV6_RE = /^(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{0,4}|(?:[0-9a-fA-F]{1,4}:){1,6}(?::[0-9a-fA-F]{1,4}){1,1}|(?:[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})$/;
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 IPV4_RE.test(v) ? { ok: true } :
430
- _fail(p, "string/ipv4", "must be a valid IPv4 address");
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 IPV6_RE.test(v) ? { ok: true } :
436
- _fail(p, "string/ipv6", "must be a valid IPv6 address");
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 (IPV4_RE.test(v) || IPV6_RE.test(v)) ? { ok: true } :
442
- _fail(p, "string/ip", "must be a valid IP address (v4 or v6)");
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/core",
3
- "version": "0.4.26",
3
+ "version": "0.4.27",
4
4
  "description": "The Node framework that owns its stack.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",