@blamejs/core 0.15.11 → 0.15.13

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.
Files changed (305) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/index.js +2 -0
  3. package/lib/a2a-tasks.js +7 -23
  4. package/lib/acme.js +13 -16
  5. package/lib/agent-event-bus.js +5 -4
  6. package/lib/agent-idempotency.js +2 -5
  7. package/lib/agent-orchestrator.js +2 -5
  8. package/lib/agent-saga.js +3 -5
  9. package/lib/agent-tenant.js +2 -5
  10. package/lib/ai-adverse-decision.js +2 -15
  11. package/lib/ai-capability.js +1 -6
  12. package/lib/ai-dp.js +1 -5
  13. package/lib/ai-input.js +2 -2
  14. package/lib/ai-pref.js +3 -8
  15. package/lib/ai-quota.js +3 -14
  16. package/lib/api-key.js +37 -28
  17. package/lib/archive-adapters.js +2 -4
  18. package/lib/archive-entry-policy.js +32 -0
  19. package/lib/archive-read.js +5 -17
  20. package/lib/archive-tar-read.js +5 -16
  21. package/lib/archive.js +2 -10
  22. package/lib/arg-parser.js +7 -6
  23. package/lib/asyncapi-traits.js +2 -6
  24. package/lib/atomic-file.js +108 -31
  25. package/lib/audit-chain.js +133 -53
  26. package/lib/audit-daily-review.js +24 -14
  27. package/lib/audit-emit.js +82 -0
  28. package/lib/audit-sign.js +257 -0
  29. package/lib/audit.js +84 -0
  30. package/lib/auth/access-lock.js +5 -27
  31. package/lib/auth/dpop.js +23 -35
  32. package/lib/auth/fido-mds3.js +9 -15
  33. package/lib/auth/jwt-external.js +26 -8
  34. package/lib/auth/jwt.js +13 -15
  35. package/lib/auth/lockout.js +6 -25
  36. package/lib/auth/oauth.js +67 -45
  37. package/lib/auth/oid4vci.js +55 -32
  38. package/lib/auth/oid4vp.js +3 -2
  39. package/lib/auth/openid-federation.js +6 -6
  40. package/lib/auth/passkey.js +3 -3
  41. package/lib/auth/password.js +7 -1
  42. package/lib/auth/saml.js +37 -27
  43. package/lib/auth/sd-jwt-vc-holder.js +2 -14
  44. package/lib/auth/sd-jwt-vc-issuer.js +2 -14
  45. package/lib/auth/sd-jwt-vc.js +1 -1
  46. package/lib/auth/status-list.js +7 -7
  47. package/lib/auth/step-up.js +6 -12
  48. package/lib/auth-bot-challenge.js +6 -37
  49. package/lib/backup/bundle.js +11 -18
  50. package/lib/backup/index.js +14 -47
  51. package/lib/bounded-map.js +112 -1
  52. package/lib/breach-deadline.js +1 -11
  53. package/lib/cache.js +7 -18
  54. package/lib/cbor.js +2 -1
  55. package/lib/cdn-cache-control.js +8 -9
  56. package/lib/cert.js +3 -10
  57. package/lib/chain-writer.js +162 -47
  58. package/lib/cli.js +5 -1
  59. package/lib/client-hints.js +10 -10
  60. package/lib/cloud-events.js +40 -31
  61. package/lib/cluster-storage.js +2 -38
  62. package/lib/cluster.js +4 -2
  63. package/lib/cms-codec.js +2 -1
  64. package/lib/codepoint-class.js +67 -1
  65. package/lib/compliance-ai-act-logging.js +1 -6
  66. package/lib/compliance-ai-act-transparency.js +2 -4
  67. package/lib/compliance-eaa.js +1 -11
  68. package/lib/compliance-sanctions-fetcher.js +21 -28
  69. package/lib/compliance-sanctions.js +2 -14
  70. package/lib/compliance.js +2 -9
  71. package/lib/config-drift.js +2 -12
  72. package/lib/content-digest.js +10 -8
  73. package/lib/cookies.js +5 -11
  74. package/lib/cose.js +19 -11
  75. package/lib/cra-report.js +1 -11
  76. package/lib/crypto-field.js +5 -10
  77. package/lib/crypto.js +120 -3
  78. package/lib/csp.js +235 -3
  79. package/lib/daemon.js +42 -41
  80. package/lib/data-act.js +19 -9
  81. package/lib/db-query.js +6 -40
  82. package/lib/db.js +34 -12
  83. package/lib/dbsc.js +5 -6
  84. package/lib/ddl-change-control.js +18 -14
  85. package/lib/deprecate.js +4 -5
  86. package/lib/did.js +6 -2
  87. package/lib/dsr.js +8 -12
  88. package/lib/external-db-migrate.js +21 -22
  89. package/lib/external-db.js +14 -26
  90. package/lib/fda-21cfr11.js +12 -8
  91. package/lib/fdx.js +22 -18
  92. package/lib/file-upload.js +80 -66
  93. package/lib/flag-evaluation-context.js +5 -8
  94. package/lib/framework-error.js +12 -0
  95. package/lib/framework-schema.js +19 -0
  96. package/lib/fsm.js +7 -12
  97. package/lib/gate-contract.js +869 -38
  98. package/lib/gdpr-ropa.js +4 -13
  99. package/lib/graphql-federation.js +1 -1
  100. package/lib/guard-agent-registry.js +2 -1
  101. package/lib/guard-all.js +1 -0
  102. package/lib/guard-archive.js +9 -30
  103. package/lib/guard-auth.js +23 -80
  104. package/lib/guard-cidr.js +20 -96
  105. package/lib/guard-csv.js +135 -196
  106. package/lib/guard-domain.js +23 -106
  107. package/lib/guard-dsn.js +16 -13
  108. package/lib/guard-email.js +46 -53
  109. package/lib/guard-envelope.js +1 -1
  110. package/lib/guard-event-bus-topic.js +2 -1
  111. package/lib/guard-filename.js +18 -62
  112. package/lib/guard-graphql.js +28 -75
  113. package/lib/guard-html-wcag.js +15 -2
  114. package/lib/guard-html.js +65 -117
  115. package/lib/guard-idempotency-key.js +2 -1
  116. package/lib/guard-image.js +280 -77
  117. package/lib/guard-imap-command.js +8 -9
  118. package/lib/guard-json.js +87 -103
  119. package/lib/guard-jsonpath.js +20 -88
  120. package/lib/guard-jwt.js +32 -114
  121. package/lib/guard-list-id.js +2 -7
  122. package/lib/guard-list-unsubscribe.js +2 -7
  123. package/lib/guard-mail-compose.js +5 -6
  124. package/lib/guard-mail-move.js +2 -1
  125. package/lib/guard-mail-query.js +5 -3
  126. package/lib/guard-mail-sieve.js +6 -7
  127. package/lib/guard-managesieve-command.js +5 -4
  128. package/lib/guard-markdown.js +76 -110
  129. package/lib/guard-message-id.js +5 -6
  130. package/lib/guard-mime.js +20 -99
  131. package/lib/guard-oauth.js +19 -73
  132. package/lib/guard-pdf.js +65 -72
  133. package/lib/guard-pop3-command.js +12 -13
  134. package/lib/guard-posture-chain.js +2 -1
  135. package/lib/guard-regex.js +24 -99
  136. package/lib/guard-saga-config.js +2 -1
  137. package/lib/guard-shell.js +22 -87
  138. package/lib/guard-smtp-command.js +8 -11
  139. package/lib/guard-sql.js +15 -13
  140. package/lib/guard-stream-args.js +2 -1
  141. package/lib/guard-svg.js +95 -140
  142. package/lib/guard-template.js +23 -80
  143. package/lib/guard-tenant-id.js +2 -1
  144. package/lib/guard-text.js +592 -0
  145. package/lib/guard-time.js +27 -95
  146. package/lib/guard-uuid.js +21 -93
  147. package/lib/guard-xml.js +76 -106
  148. package/lib/guard-yaml.js +24 -60
  149. package/lib/http-client-cache.js +8 -13
  150. package/lib/http-client-cookie-jar.js +2 -4
  151. package/lib/http-client.js +8 -21
  152. package/lib/http-message-signature.js +26 -8
  153. package/lib/i18n-messageformat.js +5 -7
  154. package/lib/i18n.js +83 -26
  155. package/lib/inbox.js +8 -8
  156. package/lib/incident-report.js +3 -21
  157. package/lib/ip-utils.js +49 -6
  158. package/lib/jobs.js +3 -2
  159. package/lib/keychain.js +6 -18
  160. package/lib/legal-hold.js +6 -15
  161. package/lib/log-stream-cloudwatch.js +44 -112
  162. package/lib/log-stream-otlp-grpc.js +28 -14
  163. package/lib/log-stream-otlp.js +16 -80
  164. package/lib/log-stream-syslog.js +6 -0
  165. package/lib/log-stream-webhook.js +20 -92
  166. package/lib/log.js +24 -2
  167. package/lib/mail-arc-sign.js +8 -3
  168. package/lib/mail-arf.js +3 -2
  169. package/lib/mail-auth.js +40 -66
  170. package/lib/mail-bimi.js +19 -39
  171. package/lib/mail-crypto-pgp.js +3 -2
  172. package/lib/mail-dav.js +8 -35
  173. package/lib/mail-deploy.js +6 -9
  174. package/lib/mail-dkim.js +19 -38
  175. package/lib/mail-greylist.js +15 -26
  176. package/lib/mail-helo.js +2 -3
  177. package/lib/mail-journal.js +2 -1
  178. package/lib/mail-mdn.js +4 -3
  179. package/lib/mail-rbl.js +5 -8
  180. package/lib/mail-scan.js +2 -2
  181. package/lib/mail-send-deliver.js +33 -20
  182. package/lib/mail-server-imap.js +32 -87
  183. package/lib/mail-server-jmap.js +35 -51
  184. package/lib/mail-server-managesieve.js +29 -83
  185. package/lib/mail-server-mx.js +33 -74
  186. package/lib/mail-server-net.js +177 -0
  187. package/lib/mail-server-pop3.js +30 -83
  188. package/lib/mail-server-rate-limit.js +30 -6
  189. package/lib/mail-server-submission.js +34 -73
  190. package/lib/mail-server-tls.js +89 -0
  191. package/lib/mail-spam-score.js +7 -8
  192. package/lib/mail-store.js +3 -2
  193. package/lib/mail.js +11 -11
  194. package/lib/markup-escape.js +31 -0
  195. package/lib/markup-tokenizer.js +54 -0
  196. package/lib/mcp-tool-registry.js +26 -23
  197. package/lib/mcp.js +1 -1
  198. package/lib/mdoc.js +11 -12
  199. package/lib/metrics.js +32 -30
  200. package/lib/middleware/age-gate.js +3 -23
  201. package/lib/middleware/api-encrypt.js +11 -22
  202. package/lib/middleware/assetlinks.js +2 -7
  203. package/lib/middleware/bearer-auth.js +2 -1
  204. package/lib/middleware/body-parser.js +79 -54
  205. package/lib/middleware/bot-disclose.js +7 -10
  206. package/lib/middleware/bot-guard.js +2 -10
  207. package/lib/middleware/csrf-protect.js +13 -2
  208. package/lib/middleware/daily-byte-quota.js +6 -26
  209. package/lib/middleware/deny-response.js +19 -1
  210. package/lib/middleware/fetch-metadata.js +7 -0
  211. package/lib/middleware/idempotency-key.js +4 -20
  212. package/lib/middleware/rate-limit.js +20 -28
  213. package/lib/middleware/scim-server.js +3 -2
  214. package/lib/middleware/security-headers.js +9 -1
  215. package/lib/middleware/security-txt.js +2 -6
  216. package/lib/middleware/tus-upload.js +12 -27
  217. package/lib/middleware/web-app-manifest.js +2 -7
  218. package/lib/migrations.js +4 -13
  219. package/lib/mime-parse.js +34 -17
  220. package/lib/module-loader.js +44 -0
  221. package/lib/money.js +105 -0
  222. package/lib/mtls-ca.js +116 -36
  223. package/lib/network-byte-quota.js +4 -18
  224. package/lib/network-dane.js +8 -6
  225. package/lib/network-dns-resolver.js +97 -6
  226. package/lib/network-dns.js +22 -26
  227. package/lib/network-dnssec.js +16 -16
  228. package/lib/network-heartbeat.js +6 -5
  229. package/lib/network-proxy.js +3 -7
  230. package/lib/network-smtp-policy.js +29 -41
  231. package/lib/network-tls.js +74 -55
  232. package/lib/network.js +2 -6
  233. package/lib/nis2-report.js +1 -11
  234. package/lib/nonce-store.js +81 -3
  235. package/lib/notify.js +7 -12
  236. package/lib/numeric-bounds.js +22 -8
  237. package/lib/object-store/azure-blob-bucket-ops.js +2 -6
  238. package/lib/object-store/azure-blob.js +5 -45
  239. package/lib/object-store/gcs.js +8 -71
  240. package/lib/object-store/http-put.js +1 -5
  241. package/lib/object-store/http-request.js +128 -0
  242. package/lib/object-store/sigv4-bucket-ops.js +2 -1
  243. package/lib/object-store/sigv4.js +9 -77
  244. package/lib/observability-otlp-exporter.js +9 -25
  245. package/lib/observability.js +95 -0
  246. package/lib/openapi-paths-builder.js +7 -3
  247. package/lib/otel-export.js +7 -10
  248. package/lib/outbox.js +43 -37
  249. package/lib/pagination.js +11 -15
  250. package/lib/parsers/safe-env.js +5 -4
  251. package/lib/parsers/safe-ini.js +10 -4
  252. package/lib/parsers/safe-toml.js +11 -9
  253. package/lib/parsers/safe-xml.js +2 -2
  254. package/lib/parsers/safe-yaml.js +7 -6
  255. package/lib/pick.js +63 -5
  256. package/lib/pipl-cn.js +69 -59
  257. package/lib/privacy-pass.js +8 -6
  258. package/lib/problem-details.js +2 -5
  259. package/lib/pubsub.js +4 -8
  260. package/lib/redact.js +2 -1
  261. package/lib/render.js +4 -2
  262. package/lib/request-helpers.js +133 -6
  263. package/lib/restore.js +5 -22
  264. package/lib/retention.js +3 -5
  265. package/lib/safe-async.js +457 -0
  266. package/lib/safe-buffer.js +137 -6
  267. package/lib/safe-decompress.js +2 -1
  268. package/lib/safe-dns.js +2 -1
  269. package/lib/safe-ical.js +12 -26
  270. package/lib/safe-json.js +7 -8
  271. package/lib/safe-jsonpath.js +6 -5
  272. package/lib/safe-mime.js +25 -29
  273. package/lib/safe-redirect.js +2 -5
  274. package/lib/safe-schema.js +7 -6
  275. package/lib/safe-sql.js +126 -0
  276. package/lib/safe-vcard.js +12 -26
  277. package/lib/sandbox-worker.js +9 -2
  278. package/lib/sandbox.js +3 -2
  279. package/lib/scheduler.js +5 -12
  280. package/lib/sec-cyber.js +82 -37
  281. package/lib/seeders.js +9 -21
  282. package/lib/self-update.js +92 -69
  283. package/lib/session-device-binding.js +112 -66
  284. package/lib/session.js +194 -6
  285. package/lib/sql.js +225 -78
  286. package/lib/sse.js +6 -10
  287. package/lib/static.js +136 -98
  288. package/lib/storage.js +4 -2
  289. package/lib/structured-fields.js +313 -17
  290. package/lib/tenant-quota.js +2 -20
  291. package/lib/tsa.js +11 -15
  292. package/lib/validate-opts.js +154 -8
  293. package/lib/vault/seal-pem-file.js +30 -48
  294. package/lib/vault-aad.js +3 -2
  295. package/lib/vc.js +2 -7
  296. package/lib/vex.js +35 -13
  297. package/lib/web-push-vapid.js +23 -20
  298. package/lib/webhook-dispatcher.js +706 -0
  299. package/lib/webhook.js +43 -18
  300. package/lib/websocket-channels.js +9 -7
  301. package/lib/websocket.js +7 -3
  302. package/lib/worm.js +2 -3
  303. package/lib/ws-client.js +8 -10
  304. package/package.json +1 -1
  305. package/sbom.cdx.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.15.x
10
10
 
11
+ - v0.15.13 (2026-06-19) — **Consolidates a large set of duplicated, security-sensitive code paths — injected-dependency validation, positive-integer option caps, TOCTOU-safe file reads, markup escaping, audit emission, structured-field parsing, and untrusted-JWK import — onto shared hardened primitives, so a fix or guard now applies everywhere at once; adds a TOCTOU-safe file reader; and makes several configuration errors throw typed framework errors instead of a bare Error.** Across the framework, logic that had been hand-rolled in many places (and had quietly drifted between copies) is now single-sourced through shared primitives. The practical effect for operators is consistency: the strongest available guard is applied everywhere a given operation happens, rather than in whichever copy happened to have it. Injected dependencies (stores, backends, vaults, db handles, query objects) are validated through one contract; operator-tunable positive-integer options (pool sizes, byte caps, timeouts, stream limits) validate through one bounds primitive that forwards the caller's non-retryable / HTTP-status flags; the open-fd → fstat → read-fully pattern that several call sites used to defend file reads against a swap-after-stat race (CWE-367) is now the b.atomicFile.fdSafeReadSync primitive, with symlink refusal, inode-equality, a byte cap, and an integrity hash available as options and each caller's exact typed error preserved; and the XML/HTML markup escapers (including the b.guardHtml / b.guardSvg sanitizer output) route through one b.markupEscape so the base & < > " chain can't drift between them. A few configuration-validation paths that threw a bare Error (httpClient.configurePool, b.db stream-limit validation) now throw the module's typed framework error. No security defaults change; this release tightens and unifies existing protections rather than adding opt-ins. **Added:** *b.atomicFile.fdSafeReadSync(filepath, opts?)* — A TOCTOU-safe synchronous file read (CWE-367 / js/file-system-race): it opens the path read-only, then binds the size, content, and integrity measurement to the inode the fd holds open, so a swap between stat and read can't change which bytes are returned. Optional guards layer on top — maxBytes (refuse an over-cap file), refuseSymlink + inodeCheck (refuse a symlink source and any inode swap, the strongest posture for operator-writable paths), expectedHash (SHA3-512), encoding (return a string), allowShortRead — and an errorFor(kind, detail) callback lets each caller keep its own typed error. The framework's own file reads (atomic-file, the TLS certificate-path loader, the sealed-PEM source reader, the backup bundle reader) all route through it. · *Shared substrate primitives for previously-duplicated logic* — A set of shared primitives now back call sites that had each re-implemented the same logic: validateOpts.requireMethods (gains a `permanent` flag) for injected-dependency contract checks; numericBounds positive-finite-int validators (gain an errorOpts { permanent, statusCode }) for tunable integer options; b.markupEscape for the & < > " markup chain; structured-field parsing helpers (parseTagList, forEachKeyValue, splitUnquoted, stripDoubleQuotes, unfoldHeaderContinuations); crypto.importPublicJwk and crypto.makeBase64UrlDecoder; safeSql.toPositional; safeBuffer.makeByteCoercer; nonceStore.enforceReplay; and the audit/observability namespaced emitters. These are mostly invisible substrate — the operator-visible benefit is that a guard or fix added to one of them now covers every caller. **Changed:** *Configuration errors throw typed framework errors* — Two configuration-validation paths that threw a bare `Error` now throw the module's typed framework error: httpClient.configurePool (bad maxSockets / maxFreeSockets / keepAliveMsecs → HttpClientError, code httpclient/bad-opts) and the b.db stream-limit validation (Query.stream → DbQueryError). The thrown error remains an Error subclass, so existing `instanceof Error` / try-catch handling is unaffected; code that matched the old free-text message should match the typed error's `code` instead. Several routed validators also report a slightly more precise message ("positive finite integer" instead of "positive integer"). **Fixed:** *Webhook deliveries retry transient transport failures instead of dead-lettering them* — A delivery that failed with a transient transport error (connection reset, timeout, 5xx) was recorded as permanently failed and dead-lettered rather than retried. The destination-safety check (SSRF / blocked-host guard) now runs in its own step and is the only permanent failure; a transport failure backs off and retries up to the configured limit. · *Webhook deliveries table creates on MySQL* — The pending-delivery index used a partial-index (WHERE) clause that MySQL does not support, so the deliveries table failed to create on a MySQL backend. The index is now dialect-aware — partial on PostgreSQL / SQLite, plain on MySQL. · *Inline webhook delivery can't be double-sent by concurrent retry processing* — An inline delivery is now claimed (status set to in-flight with a claim timestamp) before the POST, so a concurrent retry pass can't pick up and re-send the same delivery; a row left in-flight by a crash is reclaimed after the stale-claim window. · *Audit checkpoint can never be anchored against a replaced database* — close() fires a best-effort final checkpoint as the database shuts down. In a narrow close-then-reopen window that checkpoint's write could resume after a fresh database had opened and anchor the prior database's chain tip into it. checkpoint() now binds to the database it read the tip from and refuses to write (returns null, fail-closed) if that handle has since been closed or replaced — so a checkpoint is only ever written against the database it measured. **Security:** *TOCTOU-safe file reads applied uniformly* — The open-fd → fstat → read pattern that anchors a file read to one inode against a swap-after-stat race is now centralized in b.atomicFile.fdSafeReadSync, and every framework file read routes through it. The sealed-PEM source reader keeps the strongest posture (symlink refusal + inode-equality + byte cap), and those guards are now available as options to any caller — a re-introduced hand-rolled read-loop is flagged by a codebase-pattern detector. · *Injected-dependency and integer-option validation can't silently drift* — Injected stores / backends / vaults / db handles / query objects are validated through one contract (validateOpts.requireMethods), and operator-tunable positive-integer options through one bounds primitive (numericBounds), both forwarding the caller's non-retryable / HTTP-status error flags so a config error stays permanent / carries its 4xx. Inverse detectors flag any re-introduced inline check, so the validation can no longer be partially copied or weakened in one place. · *Single markup-escape chain for the HTML/SVG sanitizers* — The b.guardHtml and b.guardSvg sanitizer output escapers, the AI-Act transparency and mail HTML escapers, and the XML report escapers now share one b.markupEscape for the base & < > " chain (apostrophe form as a parameter; each caller keeps its own input coercion and any extra escapes such as guardHtml.escapeAttr's backtick / = IE-attribute-injection hardening). Byte-for-byte parity with the prior escapers was verified across an XSS-vector corpus, so the consolidation cannot have introduced an escaping gap; a re-inlined & < > " chain anywhere else is flagged by a detector. · *One hardening point for untrusted public-JWK import* — The createPublicKey-from-JWK call that imports attacker-controlled key material (DID publicKeyJwk, DNSKEY, COSE_Key, DPoP / OAuth / OIDC / DBSC proof JWKs) is centralized in b.crypto.importPublicJwk, so the untrusted-key import has a single audited home; each caller keeps its own kty/crv pre-validation and typed error. · *Linear-time Content-Security-Policy header parsing* — The CSP response-header parser split directives on a `/\s*,\s*/` regex that ran in O(n^2) on a long comma-less run of whitespace, letting a crafted header stall a worker (js/polynomial-redos). It now splits on the literal comma and trims each item, which is linear and byte-for-byte equivalent. · *Parsed INI and OpenAPI path maps can't reach Object.prototype* — The INI parser already refuses a `__proto__` / `constructor` / `prototype` section or key (it throws before any write); as defense-in-depth, every parsed node — and the OpenAPI paths map keyed by URL pattern — is now a null-prototype object, so even a future gap could only ever set an own property, never mutate Object.prototype (CWE-1321).
12
+
13
+ - v0.15.12 (2026-06-14) — **Hardens a set of defense-in-depth seams: a single-pass structured-field unescape, a constant-time content-digest member match, complete reserved-character stripping, a Trojan-Source escape on the boot logger, generic body-parse error responses, and an audit trail whenever outbound TLS certificate validation is disabled.** A sweep of low-severity but real hardening items. RFC 8941 structured-field string values (HTTP Message Signatures, Client Hints, Cache-Control) were un-escaped with two chained replaces that mis-decoded an escaped backslash adjacent to another escape; they now use one left-to-right pass that decodes each escape exactly once. The HTTP Message Signature content-digest check dropped a dead identity-replace and now matches the sha3-512 member by an exact, top-level, constant-time comparison instead of an unanchored substring scan. b.guardFilename's reserved-character strip used a non-global regex that left every separator after the first; it now strips all of them. The boot logger's TTY branch wrote raw text, bypassing the Trojan-Source / control-character escape the main logger applies — it now escapes the bidi and C0/newline control classes on every sink. The body parser no longer echoes a caught exception's detail (an fs errno + temp path, or a parse hook's thrown message) to the HTTP client — the client gets a generic status phrase while the full detail stays on the audit chain. And any outbound TLS connection that runs with peer-certificate validation disabled (an explicit operator opt-in, never a default) now emits a tls.insecure_skip_verify audit + observability event so the degraded posture is visible for compliance and incident response. **Added:** *b.structuredFields.unescapeSfStringBody(body)* — A single-pass decode of the RFC 8941 §3.3.3 quoted-string backslash escapes (the bytes between the surrounding quotes). It replaces the chained two-`.replace()` form, which is not equivalent to one decode — whichever pass runs first can rewrite a backslash the other escape sequence owns, so a lone escaped backslash decoded to two. The HTTP Message Signature, Client Hints, and Cache-Control sf-string readers now route through it. · *tls.insecure_skip_verify audit event* — b.network.tls.auditInsecureTls(meta) emits an audit + observability event at the point an outbound TLS connection honors rejectUnauthorized:false / allowInsecure. The connectWithEch, OTLP-gRPC log stream, syslog-TLS log stream, and SMTP transports all emit it when an operator disables certificate validation — parallel to the existing tls.classical_downgrade audit. No default changes; the framework never disables validation itself. **Security:** *Single-pass structured-field string unescape* — The RFC 8941 sf-string readers in HTTP Message Signatures (Signature-Input covered-component names), Client Hints, and Cache-Control directive values un-escaped with `.replace(/\\\\/g,"\\").replace(/\\"/g,'"')` — two sequential passes that mis-decode adjacent escapes (a lone escaped backslash became two). All four sites now use the single-pass b.structuredFields.unescapeSfStringBody. It is fail-closed (a mis-decoded covered-component name just fails the signature check, never bypasses it); the fix restores RFC-conformant interop with peers that legitimately escape these values. · *Constant-time, member-anchored content-digest verification* — b.crypto.httpSig.verify's covered content-digest check dropped a dead no-op replace and now parses the Content-Digest header into its top-level members and matches the sha3-512 member EXACTLY, in constant time (b.crypto.timingSafeEqual), rather than scanning for the digest text as a substring anywhere in the header. The Content-Digest header is already bound by the signature, so the substring form was not reachably exploitable; the change removes the latent ambiguity and the timing channel. · *Reserved-character filename strip removes every occurrence* — b.guardFilename's reservedCharPolicy:"strip" (the permissive profile) used a non-global regex, so only the FIRST reserved character — including path separators — was replaced and the rest leaked through. The strip is now global: every reserved character is removed. Not a traversal bypass (the unconditional security floor still throws on `..`, null bytes, NTFS ADS, UNC, overlong UTF-8), but the strip is now complete and consistent. · *Boot logger escapes control + bidi characters on every sink* — The boot-time logger's TTY branch wrote the raw message, bypassing the Trojan-Source (bidi) and control-character escapes the main logger applies — a hostile message could forge extra log lines on a terminal (CWE-117) or re-order the visible line (CVE-2021-42574). Both boot branches now escape the bidi and C0/newline control classes, matching the create() path and the logger's advertised guarantee. · *Body-parser error responses never echo internal detail* — The body-parser's terminal error path surfaced a caught exception's message verbatim to the HTTP client — a multipart filesystem error leaked the errno + temp path, and a parse hook's thrown error (which can carry secrets) was echoed back. The client now gets a curated message only for a framework-classified 4xx error and a generic status phrase otherwise; the parse-hook wrapper carries a fixed message, and full diagnostics stay on the audit chain server-side (CWE-209). The cluster leader-discovery endpoint's error body is generalized the same way.
14
+
11
15
  - v0.15.11 (2026-06-14) — **Replaces a family of quadratic-time regexes that hostile input could use to stall a worker with linear scans, refuses a relocatable sealed-cell downgrade on the read side, fails closed when enabling row-level security behind a non-native driver, and scans the vendored crypto for known CVEs on every build.** Several text-handling primitives stripped trailing whitespace or extracted a mail address with a regex whose backtracking is quadratic in the input length on adversarial strings — a request body, a YAML document, a CSV cell, or a From header crafted as a long run of spaces could pin a worker's CPU. Each is now a linear character scan with identical output. The HTML-content check the MCP tool surface applies gained the vbscript: and data:text/html vectors it was missing. On the data-at-rest side, an AAD-bound (or per-row-key) column now refuses a plain, unbound vault cell on read — a relocatable envelope an attacker with write access could copy in from another row defeats the cross-row binding, so the field is nulled rather than surfaced; operators mid-migration opt back in with registerTable({ allowPlainMigration: true }). declareRowPolicy now treats row-level-security as enabled only on a value that unambiguously means true, so a non-native Postgres driver that returns the string "f" can no longer be read as "already on" and silently skip the ENABLE that protects the table's rows. Finally, because the framework's crypto is vendored rather than installed, npm audit and Dependabot never see it: every build now matches the vendored versions against the OSV vulnerability database, with a complementary Semgrep pass and workflow-file static analysis alongside. **Added:** *b.safeBuffer.indexAfterOpenTag(html, tagName)* — A linear helper that returns the offset just past a `<tag ...>` opening tag (case-insensitive), or -1 when absent or unterminated — the insertion point a response rewriter uses to splice content after <body> or <head> without a regex. It replaces the O(n^2) html.match(/<body[^>]*>/i) shape and is stricter than it: a real tag boundary is required after the name, so <bodyfoo> is not mistaken for <body>. **Security:** *Linear-time replacements across a family of quadratic regexes (ReDoS class)* — Several primitives located or stripped text with a regex whose backtracking is quadratic in V8 on adversarial input (CWE-1333): b.safeBuffer and the safe-env / safe-yaml / guard-csv parsers stripped trailing horizontal whitespace with /[ \t]+$/; b.mail extracted the address from a `Name <addr>` header with /<([^>]+)>/; the bot-disclosure and speculation-rules response middleware found the <body> insertion point with /<body[^>]*>/i; and the BIMI certificate-chain splitter walked PEM blocks with a lazy /BEGIN[\s\S]*?END/ scan. A crafted field — a long run of spaces, an unterminated bracket, a body carrying many <body starts with no closing >, a chain of BEGIN markers — could drive a worker's CPU to seconds of work. Each is now a linear scan: a shared b.safeBuffer.stripTrailingHspace (backward char walk), b.safeBuffer.indexAfterOpenTag (forward indexOf walk for the tag insertion point), a forward indexOf for address extraction, and an indexOf walk for the PEM split. Output is byte-identical (the tag-find is stricter — it no longer mistakes <bodyfoo> for <body>), and 400K-character adversarial inputs that took 8–85 seconds now complete in under 2 ms. · *MCP HTML-content check covers vbscript: and data:text/html* — The dangerous-markup check applied to text/html tool content matched <script>/<iframe>/<object>/<embed> and javascript: URLs but not the vbscript: scheme or data:text/html payloads. Both are now refused; data: URLs carrying non-HTML media (data:image/png and similar) are unaffected. · *AAD-bound columns refuse a plain sealed cell on read* — b.cryptoField.unsealRow now refuses a plain, unbound vault: envelope found on an AAD-bound (or per-row-key) column and nulls the field instead of returning it. A plain envelope carries no per-cell binding, so a writer who could place one — copied from anywhere under the same vault root — would otherwise relocate a value across rows or columns and defeat the copy-protection the AAD binding advertises. Operators migrating pre-AAD rows up to bound ciphertext opt into a bounded acceptance window with registerTable({ allowPlainMigration: true }) and clear it when migration completes. · *Row-level-security enablement fails closed on non-native drivers* — b.db.declareRowPolicy read pg_class.relrowsecurity to skip a redundant ENABLE ROW LEVEL SECURITY, but tested it with a bare truthiness check. A native pg driver returns a JS boolean; a proxy or ORM may return the string "f" for a disabled table — and "f" is truthy, so the check read it as already-enabled and silently skipped the ENABLE, leaving every row in the table unprotected while the migration reported success. RLS now counts as enabled only on a value that unambiguously means true (true, 1, or "t"/"true"/"1"/"on"/"yes"); every other shape re-issues ENABLE, a harmless no-op on an already-enabled table. · *Vendored-crypto CVE scanning, complementary SAST, and workflow static analysis in CI* — The framework ships zero npm runtime dependencies — its crypto (the noble suite, the WebAuthn server, the PKI layer) is vendored under lib/vendor/, where npm audit, Dependabot, and Socket cannot see it. Every build now generates a CycloneDX SBOM of the vendored tree (each library carrying an npm purl) and runs it through OSV-Scanner, matching the exact pinned version against the OSV vulnerability database; a published CVE or GHSA affecting a vendored version fails the build so the copy is refreshed before merge. A Semgrep pass (registry security-audit + javascript packs at ERROR severity) runs alongside CodeQL as complementary SAST, and actionlint statically checks the workflow files. All three install the OSS tool from its upstream release, matching the existing secret-scan gate's posture. **Detectors:** *Quadratic trailing-whitespace and tag-find regex detectors* — Two codebase-pattern detectors refuse reintroduction of the quadratic shapes: the /[ \t]+$/ trailing-whitespace strip (as .replace, .test, or via the named TRAILING_HSPACE_RE export) outside the linear helper that owns it, and the str.match(/<tag[^>]*>/) document-tag find that the response middleware must route through b.safeBuffer.indexAfterOpenTag. Each is proven to fire on the removed shape and stay silent on the linear replacement, so the ReDoS class cannot creep back into a new parser, guard, or response rewriter.
12
16
 
13
17
  - v0.15.10 (2026-06-13) — **Makes S3 Object-Lock version erasure reachable through the object store, and pins the build toolchain's native binary to a reviewed hash.** The object store gains the versioned-delete surface its S3 Object Lock support always needed for real erasure. An unversioned delete on a versioning-enabled (Object-Lock) bucket only writes a delete-marker — the data version survives — so the framework's own delete could report success while a record protected for compliance, or one a data subject asked to erase, stayed on disk. b.objectStore / b.storage now carry a versionId: put and saveRaw return the version they created, deleteFile(key, { versionId, bypassGovernanceRetention }) targets a specific version (refused — not silently delete-markered — when it is under an active retention), and listVersions enumerates versions and delete-markers so an erasure workflow can find them. Backends with no version surface (the filesystem backend, and the current Azure and GCS adapters) refuse a versioned delete loudly rather than silently dropping the current object. Separately, the build toolchain's native bundler binary is now verified against a reviewed SHA-256 pin so a tampered or drifted binary is caught before it bundles the framework. **Added:** *Versioned object delete + listVersions for S3 Object-Lock erasure* — b.storage.deleteFile and the b.objectStore sigv4 backend now accept opts.versionId to erase a specific object version, and opts.bypassGovernanceRetention to lift a GOVERNANCE-mode retention for callers with the permission (COMPLIANCE stays immutable to everyone). b.storage.saveRaw and the backend put now return the versionId they created on a versioning-enabled bucket, and a new b.storage.listVersions(prefix) / backend listVersions enumerates every version and delete-marker (key, versionId, isLatest, deleteMarker, size, lastModified, etag) so a right-to-erasure or crypto-shred workflow can target prior versions. On a backend with no version surface, listVersions throws VERSIONS_UNSUPPORTED and a versioned delete throws VERSIONID_UNSUPPORTED rather than silently acting on the current object. · *b.localDb.thin reaches SQLite resource-limit parity (limits option)* — b.localDb.thin now opens its node:sqlite handle with the same parse-time statement-size cap as b.db and the CLI — a SQL statement over 1 MiB is rejected at parse time, the SQLITE_LIMIT_LENGTH floor that guards prepare()/exec() of raw SQL against an attacker-influenced megaquery (SQLite's default is 1 GB). The cap is on by default; a new limits option (e.g. { sqlLength: 2 * 1024 * 1024 } or other SQLITE_LIMIT_* keys) lets an operator raise or extend it. Previously the thin opener had no limits plumbing, so a consumer on that path could not reach parity with the rest of the framework's SQLite surface. **Fixed:** *S3 Object-Lock version erasure is reachable through the framework delete path* — On a versioning-enabled (Object-Lock) bucket, an unversioned DELETE only writes a delete-marker — the protected data version survives untouched — yet the framework's delete had no versionId surface, so it issued the unversioned form and reported success while the bytes the lock protects remained. A retention or legal hold could therefore look enforced to the framework caller while the operation WORM actually blocks was unreachable. The delete path now targets the exact version: deleting a version under a COMPLIANCE retention is refused (it throws, even with bypassGovernanceRetention), a no-retention version erases cleanly, and the enforcement is proven end-to-end against MinIO through the framework's own API. · *b.configDrift.verifyVendorIntegrity is now working-directory-independent* — The vendored-dependency integrity check resolved each manifest file path against process.cwd(), so it only worked when run from the application root. Run from anywhere else it read-failed every entry (reporting ok:false), and under a crafted working directory that happened to contain a clean vendor tree it could hash a different tree than the one actually loaded. It now resolves each file under the framework's own vendor directory by default — the tree loaded at runtime — and honors an explicit libVendorDir for verifying a deployed tree elsewhere, so the result no longer depends on where the process was started. **Security:** *Build toolchain native binary pinned to a reviewed hash* — The native bundler binary the build toolchain runs (esbuild's per-platform compiler, a development dependency that never ships in the runtime) is now verified against a SHA-256 pin captured by diffing the published package tarballs and hashing the binary. The build gate fails if the on-disk binary does not match the reviewed hash for its (version, platform); for a version that has not been reviewed it notes the gap and skips rather than trusting an unverified binary. A cross-artifact check keeps the version in agreement across package.json, the CI install step, and the hash map, so the gate can never quietly test a version that was never diffed — closing a real drift where CI had been installing an older patch than package.json declared. The reviewed diff is benign: version strings plus an installer size-bound and error-message hardening, no new install hooks, files, or network paths, and no runtime-dependency impact. **Detectors:** *Object-store erasure guard, esbuild-pin agreement, + structural re-anchoring of the lint detectors* — A new guard locks the object-store delete path to the versioned-erasure contract: b.storage.deleteFile must thread versionId to the backend, so it can never silently revert to the WORM-blind unversioned delete. A second guard enforces that the esbuild build-tool version agrees across package.json, the CI install step, and the binary-hash map, so a future bump can't update one and leave the gate testing an unreviewed version. Separately, the framework's internal codebase-pattern lint detectors were re-anchored from fixed character spans to structural code boundaries, so they keep matching the code they guard as those functions grow rather than aging out of range; reviving them surfaced a few internal validation and transaction sites that now route through shared helpers (a required positive-integer-with-range validator and an async transaction wrapper) instead of hand-rolling the check. No public API change.
package/index.js CHANGED
@@ -225,6 +225,7 @@ var guardYaml = require("./lib/guard-yaml");
225
225
  var guardXml = require("./lib/guard-xml");
226
226
  var guardMarkdown = require("./lib/guard-markdown");
227
227
  var guardEmail = require("./lib/guard-email");
228
+ var guardText = require("./lib/guard-text");
228
229
  var guardDomain = require("./lib/guard-domain");
229
230
  var guardUuid = require("./lib/guard-uuid");
230
231
  var guardCidr = require("./lib/guard-cidr");
@@ -609,6 +610,7 @@ module.exports = {
609
610
  guardXml: guardXml,
610
611
  guardMarkdown: guardMarkdown,
611
612
  guardEmail: guardEmail,
613
+ guardText: guardText,
612
614
  guardDomain: guardDomain,
613
615
  guardUuid: guardUuid,
614
616
  guardCidr: guardCidr,
package/lib/a2a-tasks.js CHANGED
@@ -51,7 +51,7 @@ var validateOpts = require("./validate-opts");
51
51
  var { defineClass } = require("./framework-error");
52
52
 
53
53
  var httpClient = lazyRequire(function () { return require("./http-client"); });
54
- var audit = lazyRequire(function () { return require("./audit"); });
54
+ var auditEmit = require("./audit-emit");
55
55
  var C = require("./constants");
56
56
 
57
57
  // A2aTasksError is the per-call error class — separate from A2aError
@@ -82,15 +82,7 @@ var TASK_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
82
82
  var SKILL_NAME_RE = /^[a-zA-Z][a-zA-Z0-9._-]{0,63}$/; // allow:duplicate-regex — RFC-3986-unreserved identifier shape, shared across mcp.js + mcp-tool-registry.js
83
83
  // RFC-3986-unreserved identifier shape (length cap inside regex), not a byte count
84
84
 
85
- function _emitAudit(action, metadata, outcome) {
86
- try {
87
- audit().safeEmit({
88
- action: action,
89
- outcome: outcome || "success",
90
- metadata: metadata,
91
- });
92
- } catch (_e) { /* best-effort */ }
93
- }
85
+ var _emitAudit = auditEmit.emit;
94
86
 
95
87
  var bCrypto = lazyRequire(function () { return require("./crypto"); });
96
88
 
@@ -515,19 +507,11 @@ function _jsonRpcError(id, code, message, data) {
515
507
  }
516
508
 
517
509
  function _readBody(req, maxBytes) {
518
- return new Promise(function (resolve, reject) {
519
- var collector = safeBuffer.boundedChunkCollector({
520
- maxBytes: maxBytes,
521
- errorClass: A2aTasksError,
522
- sizeCode: "a2a-tasks/body-too-large",
523
- sizeMessage: "a2a-tasks: request body exceeded " + maxBytes + " bytes",
524
- });
525
- req.on("data", function (chunk) {
526
- try { collector.push(chunk); }
527
- catch (capErr) { reject(capErr); }
528
- });
529
- req.on("end", function () { resolve(collector.result()); });
530
- req.on("error", function (e) { reject(e); });
510
+ return safeBuffer.collectStream(req, {
511
+ maxBytes: maxBytes,
512
+ errorClass: A2aTasksError,
513
+ sizeCode: "a2a-tasks/body-too-large",
514
+ sizeMessage: "a2a-tasks: request body exceeded " + maxBytes + " bytes",
531
515
  });
532
516
  }
533
517
 
package/lib/acme.js CHANGED
@@ -42,6 +42,7 @@
42
42
  */
43
43
 
44
44
  var nodeCrypto = require("node:crypto");
45
+ var safeBuffer = require("./safe-buffer");
45
46
 
46
47
  var C = require("./constants");
47
48
  var asn1 = require("./asn1-der");
@@ -92,10 +93,6 @@ function _emitAudit(audit, action, outcome, metadata) {
92
93
  } catch (_e) { /* audit best-effort */ }
93
94
  }
94
95
 
95
- function _emitObs(name, fields) {
96
- try { observability().safeEvent(name, 1, fields || {}); } catch (_e) { /* obs best-effort */ }
97
- }
98
-
99
96
  // JWK shape for an ES256 (P-256) public key — RFC 7518 §6.2.1.
100
97
  function _publicJwkFromKeyObject(keyObject) {
101
98
  if (!keyObject || typeof keyObject.export !== "function") {
@@ -479,7 +476,7 @@ function create(opts) {
479
476
  state.directory = body;
480
477
  _emitAudit(audit, "acme.directory.fetched", "success",
481
478
  { directoryUrl: state.directoryUrl, hasAri: typeof body.renewalInfo === "string" });
482
- _emitObs("acme.directory.fetched", { hasAri: typeof body.renewalInfo === "string" });
479
+ observability().safeEvent("acme.directory.fetched", 1, { hasAri: typeof body.renewalInfo === "string" });
483
480
  return body;
484
481
  }
485
482
 
@@ -557,7 +554,7 @@ function create(opts) {
557
554
  var id = orderOpts.identifiers[i];
558
555
  if (!id || typeof id.type !== "string" || typeof id.value !== "string" ||
559
556
  id.type.length === 0 || id.value.length === 0 ||
560
- id.value.length > C.BYTES.bytes(255)) {
557
+ safeBuffer.byteLengthOf(id.value) > C.BYTES.bytes(255)) {
561
558
  throw _err("acme/bad-identifier",
562
559
  "newOrder: identifier must be { type: string, value: string<=255 }", true);
563
560
  }
@@ -573,7 +570,7 @@ function create(opts) {
573
570
  // the field. v1-defensible scope: refuse non-string + cap length so
574
571
  // attacker-supplied profile values can't bloat the JSON payload.
575
572
  if (typeof orderOpts.profile === "string") {
576
- if (orderOpts.profile.length === 0 || orderOpts.profile.length > C.BYTES.bytes(64)) {
573
+ if (orderOpts.profile.length === 0 || safeBuffer.byteLengthOf(orderOpts.profile) > C.BYTES.bytes(64)) {
577
574
  throw _err("acme/bad-profile",
578
575
  "newOrder: profile name must be a non-empty string <= 64 bytes", true);
579
576
  }
@@ -615,7 +612,7 @@ function create(opts) {
615
612
  } else {
616
613
  throw _err("acme/bad-csr", "finalize: csr must be a DER Buffer or PEM string", true);
617
614
  }
618
- if (csrDer.length === 0 || csrDer.length > C.BYTES.kib(64)) {
615
+ if (csrDer.length === 0 || safeBuffer.byteLengthOf(csrDer) > C.BYTES.kib(64)) {
619
616
  throw _err("acme/bad-csr",
620
617
  "finalize: CSR DER size out of range (got " + csrDer.length + " bytes)", true);
621
618
  }
@@ -675,7 +672,7 @@ function create(opts) {
675
672
  }
676
673
  _emitAudit(audit, "acme.cert.issued", "success",
677
674
  { orderUrl: order.url, bytes: pem.length });
678
- _emitObs("acme.cert.issued", { bytes: pem.length });
675
+ observability().safeEvent("acme.cert.issued", 1, { bytes: pem.length });
679
676
  return pem;
680
677
  }
681
678
 
@@ -846,7 +843,7 @@ function create(opts) {
846
843
  }
847
844
  for (var di = 0; di < opts2.domains.length; di += 1) {
848
845
  var d = opts2.domains[di];
849
- if (typeof d !== "string" || d.length === 0 || d.length > C.BYTES.bytes(255)) {
846
+ if (typeof d !== "string" || d.length === 0 || safeBuffer.byteLengthOf(d) > C.BYTES.bytes(255)) {
850
847
  throw _err("acme/bad-csr-domain",
851
848
  "buildCsr: domains[" + di + "] must be a non-empty string <= 255 bytes", true);
852
849
  }
@@ -1042,7 +1039,7 @@ function create(opts) {
1042
1039
  windowEnd: ari.suggestedWindow.end,
1043
1040
  nowIso: new Date(nowMs).toISOString(),
1044
1041
  });
1045
- _emitObs("acme.cert.renew.skipped", { reason: "before-window" });
1042
+ observability().safeEvent("acme.cert.renew.skipped", 1, { reason: "before-window" });
1046
1043
  var ret = { shouldRenew: false, reason: "before-window", ari: ari };
1047
1044
  if (jitter) ret.renewAt = new Date(renewAtMs).toISOString();
1048
1045
  return ret;
@@ -1053,7 +1050,7 @@ function create(opts) {
1053
1050
  reason: "past-window",
1054
1051
  windowEnd: ari.suggestedWindow.end,
1055
1052
  });
1056
- _emitObs("acme.cert.renew.scheduled", { reason: "past-window" });
1053
+ observability().safeEvent("acme.cert.renew.scheduled", 1, { reason: "past-window" });
1057
1054
  var rp = { shouldRenew: true, reason: "past-window", ari: ari };
1058
1055
  if (jitter) rp.renewAt = new Date(renewAtMs).toISOString();
1059
1056
  return rp;
@@ -1064,7 +1061,7 @@ function create(opts) {
1064
1061
  windowEnd: ari.suggestedWindow.end,
1065
1062
  renewAt: jitter ? new Date(renewAtMs).toISOString() : null,
1066
1063
  });
1067
- _emitObs("acme.cert.renew.scheduled", { reason: "in-window" });
1064
+ observability().safeEvent("acme.cert.renew.scheduled", 1, { reason: "in-window" });
1068
1065
  var ri = { shouldRenew: true, reason: "in-window", ari: ari };
1069
1066
  if (jitter) ri.renewAt = new Date(renewAtMs).toISOString();
1070
1067
  return ri;
@@ -1140,7 +1137,7 @@ function create(opts) {
1140
1137
  "revokeCert returned " + rsp.statusCode, true, rsp.statusCode);
1141
1138
  }
1142
1139
  _emitAudit(audit, "acme.cert.revoked", "success", { reason: ropts.reason || null });
1143
- _emitObs("acme.cert.revoked", { reason: ropts.reason || 0 });
1140
+ observability().safeEvent("acme.cert.revoked", 1, { reason: ropts.reason || 0 });
1144
1141
  return true;
1145
1142
  }
1146
1143
 
@@ -1190,7 +1187,7 @@ function create(opts) {
1190
1187
  privateKey = newPrivateKey;
1191
1188
  publicJwk = newPublicJwk;
1192
1189
  _emitAudit(audit, "acme.account.key_rotated", "success", { accountUrl: state.accountUrl });
1193
- _emitObs("acme.account.key_rotated", {});
1190
+ observability().safeEvent("acme.account.key_rotated", 1, {});
1194
1191
  return true;
1195
1192
  }
1196
1193
 
@@ -1332,7 +1329,7 @@ function create(opts) {
1332
1329
  if (!opts2 || typeof opts2 !== "object" || typeof opts2.identifier !== "string" || opts2.identifier.length === 0) {
1333
1330
  throw _err("acme/bad-identifier", "dnsAccount01ChallengeRecord: opts.identifier (host) is required", true);
1334
1331
  }
1335
- if (opts2.identifier.length > C.BYTES.bytes(255)) {
1332
+ if (safeBuffer.byteLengthOf(opts2.identifier) > C.BYTES.bytes(255)) {
1336
1333
  throw _err("acme/bad-identifier", "dnsAccount01ChallengeRecord: identifier exceeds 255 bytes", true);
1337
1334
  }
1338
1335
  if (!state.accountUrl) {
@@ -70,6 +70,7 @@ var agentAudit = require("./agent-audit");
70
70
  var envelopeMac = require("./agent-envelope-mac");
71
71
  var safeJson = require("./safe-json");
72
72
  var bCrypto = require("./crypto");
73
+ var boundedMap = require("./bounded-map");
73
74
 
74
75
  var audit = lazyRequire(function () { return require("./audit"); });
75
76
 
@@ -149,10 +150,10 @@ function create(opts) {
149
150
 
150
151
  function _registerTopic(topics, name, topicOpts, auditImpl) {
151
152
  guardEventBusTopic.validate(name);
152
- if (topics.has(name)) {
153
+ boundedMap.requireAbsent(topics, name, function () {
153
154
  throw new AgentEventBusError("agent-event-bus/topic-duplicate",
154
155
  "registerTopic: '" + name + "' already registered");
155
- }
156
+ });
156
157
  if (!topicOpts.schema || typeof topicOpts.schema !== "object") {
157
158
  throw new AgentEventBusError("agent-event-bus/bad-schema",
158
159
  "registerTopic: schema required (flat key→type map)");
@@ -193,10 +194,10 @@ function _registerTopic(topics, name, topicOpts, auditImpl) {
193
194
  // lifecycle traceability.
194
195
  function _unregisterTopic(topics, name, auditImpl) {
195
196
  guardEventBusTopic.validate(name);
196
- if (!topics.has(name)) {
197
+ boundedMap.requirePresent(topics, name, function () {
197
198
  throw new AgentEventBusError("agent-event-bus/unknown-topic",
198
199
  "unregisterTopic: '" + name + "' not registered");
199
- }
200
+ });
200
201
  topics.delete(name);
201
202
  _safeAudit(auditImpl, "agent.event_bus.topic_unregistered", null, { name: name });
202
203
  }
@@ -143,11 +143,8 @@ function _ensureSealTable() {
143
143
  function create(opts) {
144
144
  opts = opts || {};
145
145
  var store = opts.store || _inMemoryBackend(opts.maxInMemoryEntries);
146
- if (typeof store.get !== "function" || typeof store.put !== "function" ||
147
- typeof store.delete !== "function") {
148
- throw new AgentIdempotencyError("agent-idempotency/bad-store",
149
- "create: store must expose { get, put, delete }");
150
- }
146
+ validateOpts.requireMethods(store, ["get", "put", "delete"],
147
+ "create: store", AgentIdempotencyError, "agent-idempotency/bad-store");
151
148
  var ttlMs = typeof opts.ttlMs === "number" ? opts.ttlMs : DEFAULT_TTL_MS;
152
149
  if (!Number.isFinite(ttlMs) || ttlMs <= 0) {
153
150
  throw new AgentIdempotencyError("agent-idempotency/bad-ttl",
@@ -157,11 +157,8 @@ var _saltedFnvBasisCache = null;
157
157
  function create(opts) {
158
158
  opts = opts || {};
159
159
  var backend = opts.backend || _inMemoryBackend();
160
- if (typeof backend.get !== "function" || typeof backend.set !== "function" ||
161
- typeof backend.delete !== "function" || typeof backend.list !== "function") {
162
- throw new AgentOrchestratorError("agent-orchestrator/bad-backend",
163
- "b.agent.orchestrator.create: backend must expose { get, set, delete, list }");
164
- }
160
+ validateOpts.requireMethods(backend, ["get", "set", "delete", "list"],
161
+ "b.agent.orchestrator.create: backend", AgentOrchestratorError, "agent-orchestrator/bad-backend");
165
162
  var clusterImpl = opts.cluster || cluster();
166
163
  var auditImpl = opts.audit || audit();
167
164
  var permissions = opts.permissions || null;
package/lib/agent-saga.js CHANGED
@@ -71,6 +71,7 @@
71
71
 
72
72
  var lazyRequire = require("./lazy-require");
73
73
  var { defineClass } = require("./framework-error");
74
+ var validateOpts = require("./validate-opts");
74
75
  var guardSagaConfig = require("./guard-saga-config");
75
76
  var bCrypto = require("./crypto");
76
77
  var agentAudit = require("./agent-audit");
@@ -118,11 +119,8 @@ function create(config) {
118
119
  // `agent.saga.no_state_store` surfaces the posture per call).
119
120
  var stateStore = config.stateStore || null;
120
121
  if (stateStore !== null) {
121
- if (typeof stateStore.saveStep !== "function" ||
122
- typeof stateStore.loadResumePoint !== "function") {
123
- throw new AgentSagaError("agent-saga/bad-state-store",
124
- "create: stateStore must expose { saveStep, loadResumePoint, markCompleted?, markFailed? }");
125
- }
122
+ validateOpts.requireMethods(stateStore, ["saveStep", "loadResumePoint"],
123
+ "create: stateStore", AgentSagaError, "agent-saga/bad-state-store");
126
124
  }
127
125
  return {
128
126
  run: function (ctx, initialState, opts) { return _run(config, auditImpl, stateStore, ctx, initialState, opts || {}); },
@@ -153,11 +153,8 @@ var TENANT_KEY_BYTES = 32;
153
153
  function create(opts) {
154
154
  opts = opts || {};
155
155
  var backend = opts.backend || _inMemoryBackend();
156
- if (typeof backend.get !== "function" || typeof backend.set !== "function" ||
157
- typeof backend.delete !== "function" || typeof backend.list !== "function") {
158
- throw new AgentTenantError("agent-tenant/bad-backend",
159
- "create: backend must expose { get, set, delete, list }");
160
- }
156
+ validateOpts.requireMethods(backend, ["get", "set", "delete", "list"],
157
+ "create: backend", AgentTenantError, "agent-tenant/bad-backend");
161
158
  var auditImpl = opts.audit || audit();
162
159
  var permissions = opts.permissions || null;
163
160
  var ctx = {
@@ -99,25 +99,12 @@ function wrap(opts) {
99
99
  var legalBasis = opts.legalBasis;
100
100
  var decide = opts.decide;
101
101
  var onAdverse = typeof opts.onAdverse === "function" ? opts.onAdverse : null;
102
- var auditOn = opts.audit !== false;
103
102
  var now = typeof opts.now === "function" ? opts.now : function () { return Date.now(); };
104
103
 
105
104
  var deadlines = REGIME_DEADLINES[legalBasis] || REGIME_DEADLINES["operator-defined"];
106
105
 
107
- function _emitAudit(action, outcome, metadata) {
108
- if (!auditOn) return;
109
- try {
110
- audit().safeEmit({
111
- action: "ai.adverse_decision." + action,
112
- outcome: outcome,
113
- metadata: metadata || {},
114
- });
115
- } catch (_e) { /* drop-silent */ }
116
- }
117
- function _emitMetric(verb, n, labels) {
118
- try { observability().safeEvent("ai.adverse_decision." + verb, n || 1, labels || {}); }
119
- catch (_e) { /* drop-silent */ }
120
- }
106
+ var _emitAudit = audit().namespaced("ai.adverse_decision", opts.audit);
107
+ var _emitMetric = observability().namespaced("ai.adverse_decision");
121
108
 
122
109
  return async function adverseDecisionDecorated(subject) {
123
110
  if (!subject || typeof subject !== "object") {
@@ -239,12 +239,7 @@ function create(opts) {
239
239
  }
240
240
  var auditOn = opts.audit !== false;
241
241
 
242
- function _emitAudit(action, outcome, metadata) {
243
- if (!auditOn) return;
244
- try {
245
- audit().safeEmit({ action: action, outcome: outcome, metadata: metadata || {} });
246
- } catch (_e) { /* audit best-effort — drop-silent */ }
247
- }
242
+ var _emitAudit = audit().namespaced(null, { audit: auditOn });
248
243
 
249
244
  function describe(modelId) {
250
245
  var d = registry.get(modelId);
package/lib/ai-dp.js CHANGED
@@ -429,11 +429,7 @@ function budget(opts) {
429
429
  var spentDelta = 0;
430
430
  var rdp = RDP_ORDERS.map(function () { return 0; }); // rdp accounting
431
431
 
432
- function _emitAudit(action, outcome, metadata) {
433
- if (!auditOn) return;
434
- try { audit().safeEmit({ action: action, outcome: outcome, metadata: metadata || {} }); }
435
- catch (_e) { /* drop-silent */ }
436
- }
432
+ var _emitAudit = audit().namespaced(null, { audit: auditOn });
437
433
 
438
434
  function _currentEpsilon(rdpCurve) {
439
435
  if (accounting === "basic") return spentEpsilon;
package/lib/ai-input.js CHANGED
@@ -23,6 +23,7 @@
23
23
  var C = require("./constants");
24
24
  var numericBounds = require("./numeric-bounds");
25
25
  var audit = require("./audit");
26
+ var codepointClass = require("./codepoint-class");
26
27
  var { AiInputError } = require("./framework-error");
27
28
 
28
29
  var SAMPLE_TRUNC = 80; // sample truncation length, not bytes
@@ -69,8 +70,7 @@ function _featuresOf(input) {
69
70
  var cp = input.charCodeAt(i);
70
71
  if ((cp >= 0x202a && cp <= 0x202e) || (cp >= 0x2066 && cp <= 0x2069)) bidi++;
71
72
  else if (cp === 0x200b || cp === 0x200c || cp === 0x200d || cp === 0xfeff || cp === 0x2060) zw++;
72
- else if (cp < 0x20 && cp !== 0x09 && cp !== 0x0a && cp !== 0x0d) ctrl++;
73
- else if (cp === 0x7f) ctrl++;
73
+ else if (codepointClass.isForbiddenControlChar(cp, { allowLf: true, allowCr: true })) ctrl++;
74
74
  }
75
75
  return {
76
76
  length: input.length,
package/lib/ai-pref.js CHANGED
@@ -152,13 +152,8 @@ function parseHeader(value) {
152
152
  label: "aiPref.parseHeader",
153
153
  });
154
154
  var out = { train: null, infer: null, snippet: null, price: null };
155
- var pairs = value.split(",");
156
- for (var i = 0; i < pairs.length; i += 1) {
157
- var p = pairs[i].trim();
158
- var eq = p.indexOf("=");
159
- if (eq === -1) continue;
160
- var k = p.slice(0, eq).trim().toLowerCase();
161
- var val = p.slice(eq + 1).trim();
155
+ var kvps = structuredFields.parseKeyValuePieces(value.split(","));
156
+ structuredFields.forEachKeyValue(kvps, function (k, val) {
162
157
  if (k === "train" && TRAIN_VALUES.indexOf(val) !== -1) out.train = val;
163
158
  else if (k === "infer" && INFER_VALUES.indexOf(val) !== -1) out.infer = val;
164
159
  else if (k === "snippet" && SNIPPET_VALUES.indexOf(val) !== -1) out.snippet = val;
@@ -169,7 +164,7 @@ function parseHeader(value) {
169
164
  var pt = parseInt(val, 10);
170
165
  if (isFinite(pt) && pt > 0) out.price = Object.assign({ perTokens: pt }, out.price || {});
171
166
  }
172
- }
167
+ });
173
168
  return out;
174
169
  }
175
170
 
package/lib/ai-quota.js CHANGED
@@ -318,12 +318,7 @@ function create(opts) {
318
318
  return null;
319
319
  }
320
320
 
321
- function _emitAudit(action, outcome, metadata) {
322
- if (!auditOn) return;
323
- try {
324
- audit().safeEmit({ action: action, outcome: outcome, metadata: metadata || {} });
325
- } catch (_e) { /* audit best-effort — drop-silent */ }
326
- }
321
+ var _emitAudit = audit().namespaced(null, { audit: auditOn });
327
322
 
328
323
  function _emitMetric(name, n) {
329
324
  try { observability().safeEvent(name, n || 1, {}); }
@@ -507,14 +502,8 @@ function _validateLimitMap(map, label) {
507
502
  }
508
503
 
509
504
  function _validateStore(store) {
510
- if (!store || typeof store !== "object" ||
511
- typeof store.reserve !== "function" ||
512
- typeof store.add !== "function" ||
513
- typeof store.get !== "function" ||
514
- typeof store.reset !== "function") {
515
- throw new AiQuotaError("ai-quota/bad-store",
516
- "ai.quota.create: store must expose reserve / add / get / reset functions");
517
- }
505
+ validateOpts.requireMethods(store, ["reserve", "add", "get", "reset"],
506
+ "ai.quota.create: store", AiQuotaError, "ai-quota/bad-store");
518
507
  }
519
508
 
520
509
  module.exports = {
package/lib/api-key.js CHANGED
@@ -134,37 +134,46 @@ function _validateIdentifier(name, value) {
134
134
  }
135
135
 
136
136
  function _validateCreateOpts(opts) {
137
- validateOpts.requireObject(opts, "apiKey.create", ApiKeyError);
138
- _validateIdentifier("apiKey.create: namespace", opts.namespace);
139
- if (opts.prefix !== undefined) _validateIdentifier("apiKey.create: prefix", opts.prefix);
140
- validateOpts.optionalPositiveInt(opts.idBytes, "apiKey.create: idBytes", ApiKeyError);
141
- validateOpts.optionalPositiveInt(opts.secretBytes, "apiKey.create: secretBytes", ApiKeyError);
142
- validateOpts.optionalBoolean(opts.trackLastUsedAt, "apiKey.create: trackLastUsedAt", ApiKeyError);
143
- validateOpts.optionalBoolean(opts.auditFailures, "apiKey.create: auditFailures", ApiKeyError);
144
- validateOpts.optionalBoolean(opts.auditSuccess, "apiKey.create: auditSuccess", ApiKeyError);
145
- validateOpts.optionalFiniteNonNegative(opts.purgeAfterMs, "apiKey.create: purgeAfterMs", ApiKeyError);
146
- if (opts.hashAlgo !== undefined) {
147
- if (typeof opts.hashAlgo !== "string" ||
148
- (opts.hashAlgo !== "shake256" && opts.hashAlgo !== "argon2id")) {
149
- throw _err("BAD_OPT", "apiKey.create: hashAlgo must be 'shake256' or 'argon2id', got " +
150
- JSON.stringify(opts.hashAlgo));
151
- }
152
- }
153
- validateOpts.auditShape(opts.audit, "apiKey.create", ApiKeyError);
154
- validateOpts.optionalFunction(opts.clock, "apiKey.create: clock", ApiKeyError);
137
+ validateOpts.shape(opts, {
138
+ namespace: function (v, l) { _validateIdentifier(l, v); },
139
+ prefix: function (v, l) { if (v !== undefined) _validateIdentifier(l, v); },
140
+ idBytes: "optional-positive-int",
141
+ secretBytes: "optional-positive-int",
142
+ trackLastUsedAt: "optional-boolean",
143
+ auditFailures: "optional-boolean",
144
+ auditSuccess: "optional-boolean",
145
+ purgeAfterMs: "optional-non-negative",
146
+ hashAlgo: function (v) {
147
+ if (v !== undefined) {
148
+ if (typeof v !== "string" || (v !== "shake256" && v !== "argon2id")) {
149
+ throw _err("BAD_OPT", "apiKey.create: hashAlgo must be 'shake256' or 'argon2id', got " +
150
+ JSON.stringify(v));
151
+ }
152
+ }
153
+ },
154
+ audit: function (v) { validateOpts.auditShape(v, "apiKey.create", ApiKeyError); },
155
+ clock: "optional-function",
156
+ }, "apiKey.create", ApiKeyError);
155
157
  }
156
158
 
157
159
  function _validateIssueOpts(opts) {
158
- validateOpts.requireObject(opts, "apiKey.issue", ApiKeyError);
159
- validateOpts.requireNonEmptyString(opts.ownerId, "apiKey.issue: ownerId", ApiKeyError, "MISSING_OWNER");
160
- validateOpts.optionalNonEmptyStringArray(opts.scopes, "apiKey.issue: scopes", ApiKeyError, "BAD_SCOPES");
161
- validateOpts.optionalPlainObject(opts.metadata, "apiKey.issue: metadata",
162
- ApiKeyError, "BAD_METADATA");
163
- if (opts.expiresAt !== undefined && opts.expiresAt !== null) {
164
- if (typeof opts.expiresAt !== "number" || !isFinite(opts.expiresAt) || opts.expiresAt < 0) {
165
- throw _err("BAD_OPT", "apiKey.issue: expiresAt must be a non-negative finite number (unix ms) or null");
166
- }
167
- }
160
+ validateOpts.shape(opts, {
161
+ ownerId: { rule: "required-string", code: "MISSING_OWNER" },
162
+ scopes: { rule: "optional-string-array", code: "BAD_SCOPES" },
163
+ metadata: { rule: "optional-plain-object", code: "BAD_METADATA" },
164
+ expiresAt: function (v) {
165
+ if (v !== undefined && v !== null) {
166
+ if (typeof v !== "number" || !isFinite(v) || v < 0) {
167
+ throw _err("BAD_OPT", "apiKey.issue: expiresAt must be a non-negative finite number (unix ms) or null");
168
+ }
169
+ }
170
+ },
171
+ }, "apiKey.issue", ApiKeyError, undefined, {
172
+ // `req` / `context` are the audit-actor pass-through bag — forwarded
173
+ // verbatim to requestHelpers.resolveActorWithOverride (via _actor)
174
+ // to populate the issue audit's 5 W's, not validated locally.
175
+ allow: ["req", "context"],
176
+ });
168
177
  }
169
178
 
170
179
  // ---- Token format ----
@@ -547,10 +547,8 @@ function http(url, opts) {
547
547
  * for await (var e of reader.entries()) entries.push(e);
548
548
  */
549
549
  function trustedStream(readable, opts) {
550
- if (!readable || typeof readable.pipe !== "function" || typeof readable.on !== "function") {
551
- throw new AdapterError("adapter/bad-arg",
552
- "trustedStream: arg must be a Readable (or pipe/on-compatible stream)");
553
- }
550
+ validateOpts.requireMethods(readable, ["pipe", "on"],
551
+ "trustedStream: arg (Readable / pipe-on-compatible stream)", AdapterError, "adapter/bad-arg");
554
552
  if (!(readable instanceof nodeStream.Readable) && !readable.readable) {
555
553
  // Accept stream-like duck-typed objects; many libraries return
556
554
  // Readable-flavored bytes via Symbol.asyncIterator only.
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * lib/archive-entry-policy.js — the entry-type extraction policy shared by the
4
+ * ZIP (archive-read) and TAR (archive-tar-read) readers.
5
+ *
6
+ * Special archive entry types — symlinks, hardlinks, device nodes, FIFOs, and
7
+ * sockets — are a malicious-archive vector (symlink traversal out of the
8
+ * extraction root, device-node creation, etc.), so every type is DENIED by
9
+ * default; an operator opts a type in explicitly per archive. Both readers
10
+ * normalized the same default the same way, so the policy + its overlay live
11
+ * here once rather than drifting between the two formats.
12
+ */
13
+
14
+ var DEFAULT_ENTRY_TYPE_POLICY = Object.freeze({
15
+ symlinks: false,
16
+ hardlinks: false,
17
+ devices: false,
18
+ fifos: false,
19
+ sockets: false,
20
+ });
21
+
22
+ // normalize(p) — overlay an operator policy onto the all-denied default and
23
+ // freeze it. A falsy `p` returns the shared default object (no allocation).
24
+ function normalize(p) {
25
+ if (!p) return DEFAULT_ENTRY_TYPE_POLICY;
26
+ return Object.freeze(Object.assign({}, DEFAULT_ENTRY_TYPE_POLICY, p));
27
+ }
28
+
29
+ module.exports = {
30
+ DEFAULT_ENTRY_TYPE_POLICY: DEFAULT_ENTRY_TYPE_POLICY,
31
+ normalize: normalize,
32
+ };