@blamejs/core 0.15.1 → 0.15.2

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,8 @@ upgrading across more than a few patches at a time.
8
8
 
9
9
  ## v0.15.x
10
10
 
11
+ - v0.15.2 (2026-06-12) — **Object keys with a space, +, &, or other reserved characters now sign correctly against S3-compatible stores and Google Cloud Storage.** The SigV4 request signer (and the Google Cloud Storage V4 signer that shares it) URI-encoded the object-key path a second time when building the canonical request it signs, while the request on the wire carried the path encoded once. Amazon S3 — and every S3-compatible store such as MinIO, Cloudflare R2, Wasabi, and Backblaze B2, plus GCS — signs the canonical path encoded exactly once, so any object key containing a space, a +, an &, parentheses, or a non-ASCII character was signed over a path the server never received and the request was rejected with HTTP 403 SignatureDoesNotMatch. Keys built only from unreserved characters were unaffected, which is why the regression went unnoticed. This release makes the canonical-path encoding match the service: S3 and GCS encode the path once, while the AWS services that genuinely require a second encoding (SQS, CloudWatch Logs, SNS) keep it. Object reads, writes, deletes, listings, presigned URLs, and backup or restore through the object-store adapter now succeed for keys with reserved characters. Separately, the bucket-operations key encoder now uses the AWS reserved-character set, so a key containing !, *, ', or ( is escaped to match the bytes the store signs over. **Fixed:** *SigV4 and GCS V4 sign object-key paths with the single encoding S3 and GCS expect* — A request to read, write, delete, list, or presign an object whose key contained a space, +, &, (, ), or a non-ASCII character failed with 403 SignatureDoesNotMatch against S3, every S3-compatible store, and Google Cloud Storage, because the canonical request double-encoded the path the wire carried once. The signer is now service-aware: S3 and GCS sign the path encoded once (matching the wire and the store's own canonicalization), while SQS, CloudWatch Logs, and SNS keep the second encoding the AWS spec requires for those services. No configuration change or migration is needed — object operations and presigned URLs for keys with reserved characters simply start working. Object keys made only of unreserved characters are byte-for-byte unchanged. · *Bucket-operations key encoder escapes the AWS reserved set* — The bucket-level object operations encoded key path segments with a generic URI encoder that left !, *, ', and ( unescaped. Those now route through the same AWS encoder the read and write paths use, so a key containing one of those characters is escaped consistently and signs correctly.
12
+
11
13
  - v0.15.1 (2026-06-11) — **Sealed-column lookups find rows written before the v0.15.0 hash change, and API-key secrets re-hash to the active algorithm on verify.** v0.15.0 changed the default derived hash — the blind index a sealed column is looked up by — from an unkeyed salted hash to a keyed MAC, and promised a transparent migration via a dual read. But no lookup path actually performed the dual read, so on a deployment that already held data, a lookup by a sealed column (a session's user id, an API key's owner, an audit actor or resource, a consent or data-subject id, a mail thread) computed only the new keyed digest and missed every row written before the upgrade. This release wires the dual read into every lookup: a sealed-column equality now matches both the active keyed digest and the legacy salted digest, so pre-upgrade rows are found again. That restores two correctness guarantees the gap had quietly broken — revoking all of a user's sessions no longer skips sessions created before the upgrade, and a subject erasure no longer leaves pre-upgrade rows behind. Separately, the framework's API-key store now re-hashes a stored secret to the active hash algorithm on the next successful verify, the transparent rotation the credential-hash primitive documented but the store had never performed. **Fixed:** *Sealed-column lookups match rows written before the v0.15.0 keyed-MAC change* — After v0.15.0 flipped the default derived-hash mode to a keyed MAC, a lookup by a sealed column computed only the new keyed digest, so rows written under the previous salted-hash default were no longer found — a silent index miss on every existing deployment. Every framework lookup path now dual-reads: `b.db.from(...).where(sealedField, value)` and the framework's own api-key, session, audit, consent, data-subject, and mail-thread lookups match the column against both the active keyed digest and the legacy salted digest (`b.db.hashCandidatesFor` exposes the candidate list for operator code). No migration or operator action is required; rows re-hash to the keyed form on read over time and the candidate set collapses back to a single value. Two correctness consequences are restored: revoking all of a user's sessions now also revokes sessions created before the upgrade, and a data-subject erasure now also deletes (and crypto-shreds) the subject's pre-upgrade rows. · *API-key secret hashes upgrade to the active algorithm on verify* — The framework's API-key store now re-hashes a stored secret to the configured hash algorithm on the next successful verify (leader-gated, best-effort, primary-match only), emitting an `apikey.secret_rehash` audit and observability event. This is the transparent rotation `b.credentialHash` documents — a key stored under an older algorithm or parameter set silently moves to the current one as it is used, with no change to the verify result or the returned record.
12
14
 
13
15
  - v0.15.0 (2026-06-08) — **A chainable SQL builder, MySQL as a first-class data backend, and a keyed lookup-hash default — the data layer goes tri-dialect.** This release makes the framework's data layer dialect-portable. `b.sql` is a new chainable query builder that quotes every identifier by construction, binds every value as a placeholder, and emits dialect-correct SQL for SQLite, Postgres, and MySQL; `b.guardSql` validates result rows against NUL bytes, quote-jump sequences, and per-column / total size boundaries. The entire framework data layer — the signed audit chain, cluster leadership and fencing, sessions, break-glass, the local queue, cache, scheduler, migrations, consent, and mail storage — is rebuilt on `b.sql`, which makes MySQL a supported external-database backend alongside Postgres and SQLite. Running the data layer on a real Postgres server surfaced two latent correctness bugs that only a non-SQLite backend exposes: identifiers were emitted unquoted at DDL time but read back camelCase (Postgres folds unquoted names to lowercase, silently breaking the audit chain, consent chain, cluster fencing, and vault-key consistency), and sealed columns coerced Buffer / object payloads through `String()` before encryption (corrupting non-string ciphertext); both are fixed by quoting every identifier and coercing per the column's declared type. Derived-hash columns — the blind-index lookup columns registered through `registerTable` — now default to a keyed MAC (SHAKE256 under the vault's per-deployment MAC key) instead of an unkeyed salted hash, so an exfiltrated database can no longer be brute-forced or rainbow-tabled to recover the indexed values; existing salted-hash indexes are read through a dual-read path and migrated forward, so the change is non-breaking. Audit-signing key rotation now preserves every historical checkpoint (rotation previously stranded checkpoints signed under the prior key). New cross-border data-residency postures (appi-jp, pdpa-sg, uk-gdpr) enforce a mandatory storage vacuum after erasure. Outbound TLS appends classical X25519 to its key-exchange preference so it can complete a handshake with a peer that advertises no post-quantum hybrid — previously the hybrids-only preference failed those handshakes outright — and emits a `tls.classical_downgrade` audit event whenever a connection lands on a classical group. Outbound HTTP/2 negotiation falls back to HTTP/1.1 against servers that only speak h1, the network heartbeat honors a target's permitted protocols instead of pinning cleartext targets down, a WebSocket connection closes cleanly on a peer's TCP half-close instead of wedging open, and the Azure blob backend encodes object-key path segments correctly. **Added:** *b.sql — a dialect-aware chainable SQL builder* — `b.sql` composes SELECT / INSERT / UPDATE / UPSERT / DELETE / DDL from a fluent chain. Every identifier is validated and quoted by construction (`"name"` on SQLite/Postgres, `` `name` `` on MySQL), every value binds as a placeholder rather than interpolating, and the emitted statement is validated as a single balanced, single-statement query before it leaves the builder. Pass `{ dialect: "postgres" | "mysql" | "sqlite" }` (default SQLite) to target a backend; `upsert` emits the dialect-final conflict syntax. It composes `b.safeSql` for the identifier and placeholder primitives, so a SQL string can no longer be assembled by hand inside the framework. · *b.guardSql — result-row output validation* — `b.guardSql` gates query result rows against embedded NUL bytes, quote-jump sequences, and configurable per-column and total-size boundaries, with the standard guard profiles (strict / balanced / permissive) and compliance postures (hipaa / pci-dss / gdpr / soc2). It is the output-side complement to the input-side `b.safeSql`. · *MySQL is a first-class data backend* — MySQL joins Postgres and SQLite as a supported external-database backend. The framework's schema reconciler emits MySQL DDL, and the full data layer — signed audit chain (append + verify), cluster leadership and lease fencing, sessions, break-glass, the local queue, cache, scheduler, migrations, and consent — runs against a real MySQL server. Select the backend at `b.cluster.init` / `b.externalDb` configuration via the `dialect` option; `b.clusterStorage.dialect()` exposes the configured backend dialect to composing code. · *Cross-border erasure postures: appi-jp, pdpa-sg, uk-gdpr* — Three data-residency compliance postures are added (Japan APPI, Singapore PDPA, UK GDPR). Each requires a mandatory storage vacuum after erasure (so deleted rows are reclaimed from the page store, not just tombstoned), a signed audit chain, encrypted backups, and a minimum TLS version. Pin one with `b.compliance.set`. **Fixed:** *Cross-border erasure performs the mandatory vacuum* — Erasure under the uk-gdpr, appi-jp, and pdpa-sg residency postures now runs the storage vacuum the posture mandates, reclaiming erased rows from the page store rather than leaving them recoverable as free-list tombstones. **Security:** *Lookup-hash columns default to a keyed MAC* — Derived-hash (blind-index) columns registered through `registerTable` now default to `derivedHashMode: "hmac-shake256"` — SHAKE256 keyed with the vault's per-deployment MAC key — instead of the previous unkeyed `salted-sha3`. The index value is no longer recomputable from the indexed plaintext alone, so an attacker who exfiltrates the database cannot brute-force or rainbow-table a lookup column (for example a subject-email index) without also holding the vault MAC key (CWE-916 / CWE-759). Existing `salted-sha3` indexes are read through a dual-read path and re-derived on write, so deployments upgrade without re-indexing up front. · *Postgres identifier casing no longer breaks the audit and cluster chains* — Identifiers were written unquoted in DDL but read back in camelCase. On Postgres (which folds an unquoted identifier to lowercase) this silently desynchronized the signed audit chain, the consent chain, cluster leadership and fencing, and vault-key consistency — each reads a column the server had stored under a lowercased name. Every framework identifier is now quoted at both DDL and query time so the stored and read names match on every dialect (CWE-670). SQLite deployments were unaffected and remain byte-compatible. · *Sealed columns preserve non-string payloads* — A sealed column coerced its value through `String()` before encryption, corrupting Buffer and object payloads (a Buffer became `"[object Object]"`-class garbage, an object its `toString`). Sealed values are now encoded per the column's declared type before the seal, so binary and structured payloads round-trip intact (CWE-704). · *Audit-signing key rotation preserves historical checkpoints* — Rotating the audit-signing key stranded every checkpoint signed under the prior key — `verifyCheckpoints` ignored the per-fingerprint history file the rotation writes, so post-rotation verification failed on otherwise-valid historical checkpoints. Verification now resolves each checkpoint's signing key by fingerprint (`getPublicKeyByFingerprint`) across the rotation history, so the full chain verifies after a key rotation. · *Outbound TLS reaches classical-only peers and audits the downgrade* — The framework's outbound TLS offered only ML-KEM hybrid key-exchange groups, so a handshake with a peer that does not advertise a post-quantum hybrid — most of today's internet — failed outright (`handshake_failure`), leaving outbound connections to webhooks, OAuth providers, ACME directories, object stores, and DoT/DoH/SMTP/Redis-over-TLS unable to complete. Classical X25519 is now appended to the group preference so the hybrid is still negotiated whenever the peer supports it, and the connection completes over classical X25519 when it does not. Every connection that lands on a classical group rather than the post-quantum hybrid emits a `tls.classical_downgrade` audit event (carrying the negotiated group) so operators can observe and alert on which peers are not yet post-quantum-capable. · *Transport reachability and correctness* — Outbound HTTP/2 negotiation now falls back to HTTP/1.1 when a TLS server offers only h1 (an ALPN protocol_version alert no longer fails the request). The network heartbeat honors a target's permitted protocols instead of dropping non-default ones, so a cleartext `http://` health target is no longer reported permanently down. A WebSocket connection closes cleanly when a peer half-closes its TCP socket (a bare FIN) instead of wedging the connection open. The Azure blob backend percent-encodes each object-key path segment, so a key containing reserved characters can no longer corrupt the request URL. **Migration:** *Derived-hash default change is non-breaking; MySQL is opt-in* — Lookup-hash columns default to the keyed MAC on new writes and migrate existing rows on access through the dual-read path — no upfront re-indexing, no operator action required. To pin the previous unkeyed index (for example to keep a column byte-compatible with an external system), pass `derivedHashMode: "salted-sha3"` to `registerTable`. MySQL as a data backend is opt-in: existing SQLite and Postgres deployments are unchanged unless you set `dialect: "mysql"`. The Postgres identifier-casing and sealed-column-coercion fixes change the emitted DDL and the at-rest encoding of non-string sealed values; a Postgres deployment created before this release reconciles its schema to the quoted identifiers on the next schema-ensure pass.
@@ -364,7 +364,10 @@ function create(config) {
364
364
  // Build the canonical request — identical shape to SigV4. The
365
365
  // sigv4 export gives us the formatter so this stays in lockstep
366
366
  // with the AWS implementation.
367
- var canon = sigv4.canonicalRequest(method, url, headers, "UNSIGNED-PAYLOAD");
367
+ // GCS's V4 signature, like S3, URI-encodes the canonical path ONCE; the key
368
+ // is already single-encoded into url.pathname above, so pass doubleEncodePath
369
+ // = false (a second encode would 403 any key with a space/+/&/unicode).
370
+ var canon = sigv4.canonicalRequest(method, url, headers, "UNSIGNED-PAYLOAD", false);
368
371
  var stringToSign = [
369
372
  GCS_V4_ALGORITHM,
370
373
  amzDate,
@@ -514,8 +514,11 @@ function create(config) {
514
514
  function _objectUrl(name, key, query) {
515
515
  // Each key segment is encoded individually so that legitimate "/"
516
516
  // separators in the key are preserved (S3 treats keys with slashes
517
- // as flat names, not directories).
518
- var encKey = key.split("/").map(encodeURIComponent).join("/");
517
+ // as flat names, not directories). Use sigv4.awsUriEncode (not
518
+ // encodeURIComponent, which leaves !*'() unescaped) so the wire path
519
+ // matches the bytes S3 canonicalizes the signature over — same encoder
520
+ // _keyToUrl uses for the put/get path.
521
+ var encKey = key.split("/").map(function (s) { return sigv4.awsUriEncode(s, true); }).join("/");
519
522
  var uo = _internalUrl(endpoint, allowedProtocols);
520
523
  if (pathStyle) {
521
524
  uo.pathname = "/" + name + "/" + encKey;
@@ -86,9 +86,16 @@ function hmacSha256(key, data) {
86
86
  // AWS-style URI encoding: same as RFC 3986 except path '/' may be preserved.
87
87
  function awsUriEncode(str, encodeSlash) {
88
88
  var out = "";
89
- for (var i = 0; i < str.length; i++) {
90
- var c = str.charCodeAt(i);
91
- var ch = str.charAt(i);
89
+ // Iterate by Unicode code point, not UTF-16 code unit. Array.from() keeps a
90
+ // non-BMP character's surrogate pair together (one element), so a key like
91
+ // "photo-<U+1F600>.jpg" encodes as a single UTF-8 sequence. Iterating by
92
+ // index would hand encodeURIComponent a lone surrogate, which throws
93
+ // "URIError: URI malformed". Output is byte-for-byte identical for the
94
+ // BMP/ASCII keys that are the overwhelming common case.
95
+ var cps = Array.from(str);
96
+ for (var i = 0; i < cps.length; i++) {
97
+ var ch = cps[i];
98
+ var c = ch.codePointAt(0);
92
99
  if ((c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A) ||
93
100
  (c >= 0x30 && c <= 0x39) ||
94
101
  ch === "-" || ch === "_" || ch === "." || ch === "~") {
@@ -137,13 +144,24 @@ function canonicalHeaders(headers) {
137
144
  return { canonical: canon, signed: signed.join(";") };
138
145
  }
139
146
 
140
- function canonicalRequest(method, urlObj, headers, payloadHash) {
147
+ // AWS SigV4 canonical URI. Per the SigV4 spec, S3 (and S3-compatible stores +
148
+ // GCS's V4) URI-encode the path EXACTLY ONCE; every other AWS service (sqs,
149
+ // logs, sns, ...) encodes it TWICE. Callers build urlObj through the WHATWG URL
150
+ // parser, so urlObj.pathname is ALREADY the single-encoded wire form (a key
151
+ // "a b.txt" is "/a%20b.txt") and the request sends that pathname verbatim. So
152
+ // for S3/GCS the canonical path MUST equal the pathname as-is: a second
153
+ // awsUriEncode would sign "/a%2520b.txt", a path the wire never carries, giving
154
+ // SignatureDoesNotMatch (403) for any key with a space/+/&/unicode. For the
155
+ // double-encode services the second pass is the spec requirement. signRequest
156
+ // derives doubleEncodePath from the service; GCS's V4 signer passes false.
157
+ function canonicalRequest(method, urlObj, headers, payloadHash, doubleEncodePath) {
141
158
  var canonHeaders = canonicalHeaders(headers);
142
159
  var path = urlObj.pathname;
143
160
  if (!path) path = "/";
161
+ var canonicalPath = doubleEncodePath ? awsUriEncode(path, false) : path;
144
162
  return [
145
163
  method.toUpperCase(),
146
- awsUriEncode(path, false),
164
+ canonicalPath,
147
165
  canonicalQueryString(urlObj.searchParams),
148
166
  canonHeaders.canonical,
149
167
  canonHeaders.signed,
@@ -204,7 +222,11 @@ function signRequest(opts) {
204
222
  headers["x-amz-security-token"] = opts.sessionToken;
205
223
  }
206
224
 
207
- var canon = canonicalRequest(opts.method, url, headers, opts.payloadHash);
225
+ // S3 single-encodes the canonical path; every other AWS service double-encodes
226
+ // it (see canonicalRequest). The path itself is "/" for the non-S3 callers
227
+ // (cloudwatch/sqs put params in the query or body), so this only changes the
228
+ // wire result for S3, where it fixes the long-standing double-encode 403.
229
+ var canon = canonicalRequest(opts.method, url, headers, opts.payloadHash, service !== "s3");
208
230
  var credentialScope = dateStamp + "/" + opts.region + "/" + service + "/aws4_request";
209
231
  var sts = stringToSign(amzDate, credentialScope, canon);
210
232
  var signingKey = deriveSigningKey(opts.secretAccessKey, dateStamp, opts.region, service);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/core",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "The Node framework that owns its stack.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
package/sbom.cdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.5",
5
- "serialNumber": "urn:uuid:167ad68f-23f7-47a4-a412-8703ce390619",
5
+ "serialNumber": "urn:uuid:ff927df0-9d1a-45d2-9e38-dfeac8f50738",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-06-11T15:59:54.794Z",
8
+ "timestamp": "2026-06-12T02:42:36.413Z",
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.15.1",
22
+ "bom-ref": "@blamejs/core@0.15.2",
23
23
  "type": "application",
24
24
  "name": "blamejs",
25
- "version": "0.15.1",
25
+ "version": "0.15.2",
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.15.1",
29
+ "purl": "pkg:npm/%40blamejs/core@0.15.2",
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.15.1",
57
+ "ref": "@blamejs/core@0.15.2",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]