@blamejs/core 0.6.12 → 0.6.20

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 (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/NOTICE +16 -0
  3. package/README.md +9 -8
  4. package/index.js +12 -0
  5. package/lib/api-key.js +2 -3
  6. package/lib/audit.js +4 -0
  7. package/lib/auth/password.js +449 -4
  8. package/lib/cache.js +3 -7
  9. package/lib/cli.js +598 -4
  10. package/lib/config-drift.js +309 -0
  11. package/lib/crypto-field.js +37 -0
  12. package/lib/crypto.js +8 -0
  13. package/lib/db.js +17 -2
  14. package/lib/dual-control.js +475 -0
  15. package/lib/file-type.js +265 -0
  16. package/lib/http-client.js +77 -0
  17. package/lib/internal-sha1-hibp.js +34 -0
  18. package/lib/middleware/csp-nonce.js +7 -4
  19. package/lib/middleware/index.js +2 -0
  20. package/lib/middleware/network-allowlist.js +199 -0
  21. package/lib/network-dns.js +469 -0
  22. package/lib/network-heartbeat.js +290 -0
  23. package/lib/network-nts.js +552 -0
  24. package/lib/network-proxy.js +246 -0
  25. package/lib/network-tls.js +326 -0
  26. package/lib/network.js +233 -0
  27. package/lib/notify.js +2 -3
  28. package/lib/ntp-check.js +50 -4
  29. package/lib/numeric-checks.js +40 -0
  30. package/lib/object-store/azure-blob.js +16 -42
  31. package/lib/permissions.js +223 -9
  32. package/lib/pqc-agent.js +4 -4
  33. package/lib/queue.js +5 -5
  34. package/lib/restore.js +5 -3
  35. package/lib/retention.js +439 -0
  36. package/lib/retry.js +3 -6
  37. package/lib/security-assert.js +368 -0
  38. package/lib/session.js +138 -8
  39. package/lib/slug.js +2 -3
  40. package/lib/ssrf-guard.js +9 -0
  41. package/lib/testing.js +3 -7
  42. package/lib/vendor/MANIFEST.json +12 -0
  43. package/lib/vendor/common-passwords-top-10000.txt +10000 -0
  44. package/lib/webhook.js +3 -6
  45. package/package.json +3 -2
  46. package/sbom.cyclonedx.json +61 -0
package/lib/network.js ADDED
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+
3
+ var ntpCheck = require("./ntp-check");
4
+ var nts = require("./network-nts");
5
+ var dns = require("./network-dns");
6
+ var proxy = require("./network-proxy");
7
+ var trust = require("./network-tls");
8
+ var heartbeat = require("./network-heartbeat");
9
+
10
+ var validateOpts = require("./validate-opts");
11
+ var lazyRequire = require("./lazy-require");
12
+ var { defineClass } = require("./framework-error");
13
+
14
+ var NetworkError = defineClass("NetworkError", { alwaysPermanent: true });
15
+
16
+ var observability = lazyRequire(function () { return require("./observability"); });
17
+ var audit = lazyRequire(function () { return require("./audit"); });
18
+
19
+ var SOCKET_DEFAULTS = {
20
+ noDelay: true,
21
+ keepAlive: true,
22
+ keepAliveInitialDelayMs: 0,
23
+ };
24
+
25
+ function _setSocketNoDelay(value) {
26
+ if (typeof value !== "boolean") {
27
+ throw new NetworkError("socket/bad-no-delay", "socket.setDefaultNoDelay: expected boolean, got " + typeof value);
28
+ }
29
+ SOCKET_DEFAULTS.noDelay = value;
30
+ }
31
+
32
+ function _setSocketKeepAlive(opts) {
33
+ opts = opts || {};
34
+ validateOpts(opts, ["enable", "initialDelayMs"], "socket.setDefaultKeepAlive");
35
+ if (opts.enable !== undefined) {
36
+ if (typeof opts.enable !== "boolean") {
37
+ throw new NetworkError("socket/bad-keepalive", "socket.setDefaultKeepAlive: enable must be boolean");
38
+ }
39
+ SOCKET_DEFAULTS.keepAlive = opts.enable;
40
+ }
41
+ if (opts.initialDelayMs !== undefined) {
42
+ if (typeof opts.initialDelayMs !== "number" || !isFinite(opts.initialDelayMs) || opts.initialDelayMs < 0) {
43
+ throw new NetworkError("socket/bad-keepalive-delay", "socket.setDefaultKeepAlive: initialDelayMs must be non-negative finite number");
44
+ }
45
+ SOCKET_DEFAULTS.keepAliveInitialDelayMs = opts.initialDelayMs;
46
+ }
47
+ }
48
+
49
+ // SO_LINGER is intentionally NOT exposed: Node's net.Socket has no
50
+ // public setLinger() method (the option is tracked at
51
+ // nodejs/node#27293 / rejected for the public surface). Reaching into
52
+ // socket._handle to call setLinger is an unstable internal API. The
53
+ // closest operator-exposed semantic is socket.destroy() (RST = "abort
54
+ // on close") vs socket.end() (graceful FIN). Operators needing true
55
+ // SO_LINGER should use a native binding outside the framework. This
56
+ // stub stays in the export with throw-on-call so a future Node release
57
+ // that exposes setLinger can be wired without an API addition.
58
+ function _setSocketLinger(_opts) {
59
+ throw new NetworkError("socket/linger-not-supported",
60
+ "socket.setDefaultLinger: SO_LINGER is not exposed by Node's public net.Socket API " +
61
+ "(see nodejs/node#27293). Use socket.destroy() (abort) vs socket.end() (graceful) " +
62
+ "to control close semantics, or a native binding if true SO_LINGER is required.");
63
+ }
64
+
65
+ function _socketDefaults() {
66
+ return {
67
+ noDelay: SOCKET_DEFAULTS.noDelay,
68
+ keepAlive: SOCKET_DEFAULTS.keepAlive,
69
+ keepAliveInitialDelayMs: SOCKET_DEFAULTS.keepAliveInitialDelayMs,
70
+ };
71
+ }
72
+
73
+ function applyToSocket(socket) {
74
+ if (!socket) return socket;
75
+ try {
76
+ if (typeof socket.setNoDelay === "function") socket.setNoDelay(SOCKET_DEFAULTS.noDelay);
77
+ if (typeof socket.setKeepAlive === "function") {
78
+ socket.setKeepAlive(SOCKET_DEFAULTS.keepAlive, SOCKET_DEFAULTS.keepAliveInitialDelayMs || 0);
79
+ }
80
+ } catch (_e) {}
81
+ return socket;
82
+ }
83
+
84
+ var ntpFacade = {
85
+ querySingle: ntpCheck.querySingle,
86
+ checkDrift: ntpCheck.checkDrift,
87
+ bootCheck: ntpCheck.bootCheck,
88
+ setThresholds: ntpCheck.setThresholds,
89
+ getThresholds: ntpCheck.getThresholds,
90
+ setServers: function (list) {
91
+ if (!Array.isArray(list) || list.length === 0) {
92
+ throw new NetworkError("ntp/bad-servers", "ntp.setServers: expected non-empty array");
93
+ }
94
+ ntpFacade._defaultServers = list.slice();
95
+ _emitObs("network.ntp.servers.set", { count: list.length });
96
+ },
97
+ getServers: function () {
98
+ return (ntpFacade._defaultServers || ntpCheck.DEFAULT_SERVERS).slice();
99
+ },
100
+ _defaultServers: null,
101
+ nts: nts,
102
+ };
103
+
104
+ function bootFromEnv(opts) {
105
+ opts = opts || {};
106
+ validateOpts(opts, ["env", "audit"], "network.bootFromEnv");
107
+ var env = opts.env || process.env;
108
+ var applied = { ntp: {}, dns: {}, proxy: false, tls: {}, heartbeat: 0, socket: {} };
109
+
110
+ if (env.BLAMEJS_NTP_SERVERS) {
111
+ var list = String(env.BLAMEJS_NTP_SERVERS).split(",").map(function (s) { return s.trim(); }).filter(Boolean);
112
+ if (list.length > 0) { ntpFacade.setServers(list); applied.ntp.servers = list.length; }
113
+ }
114
+ var ntpTimeout = env.BLAMEJS_NTP_TIMEOUT_MS;
115
+ if (ntpTimeout) {
116
+ var t = parseInt(ntpTimeout, 10);
117
+ if (isFinite(t) && t > 0) { ntpFacade._defaultTimeoutMs = t; applied.ntp.timeoutMs = t; }
118
+ }
119
+ var ntpWarn = env.BLAMEJS_NTP_DRIFT_WARN_MS;
120
+ var ntpFatal = env.BLAMEJS_NTP_DRIFT_FATAL_MS;
121
+ if (ntpWarn || ntpFatal) {
122
+ var thr = {};
123
+ if (ntpWarn) { thr.warnMs = parseInt(ntpWarn, 10); applied.ntp.warnMs = thr.warnMs; }
124
+ if (ntpFatal) { thr.fatalMs = parseInt(ntpFatal, 10); applied.ntp.fatalMs = thr.fatalMs; }
125
+ ntpCheck.setThresholds(thr);
126
+ }
127
+
128
+ var dnsServers = env.BLAMEJS_DNS_SERVERS;
129
+ if (dnsServers) {
130
+ var dl = String(dnsServers).split(",").map(function (s) { return s.trim(); }).filter(Boolean);
131
+ if (dl.length > 0) { dns.setServers(dl); applied.dns.servers = dl.length; }
132
+ }
133
+ if (env.BLAMEJS_DNS_RESULT_ORDER) { dns.setResultOrder(env.BLAMEJS_DNS_RESULT_ORDER); applied.dns.resultOrder = env.BLAMEJS_DNS_RESULT_ORDER; }
134
+ if (env.BLAMEJS_DNS_FAMILY) { dns.setFamily(parseInt(env.BLAMEJS_DNS_FAMILY, 10)); applied.dns.family = parseInt(env.BLAMEJS_DNS_FAMILY, 10); }
135
+ if (env.BLAMEJS_DNS_LOOKUP_TIMEOUT_MS) { dns.setLookupTimeoutMs(parseInt(env.BLAMEJS_DNS_LOOKUP_TIMEOUT_MS, 10)); applied.dns.lookupTimeoutMs = parseInt(env.BLAMEJS_DNS_LOOKUP_TIMEOUT_MS, 10); }
136
+ if (env.BLAMEJS_DNS_CACHE_TTL_MS) { dns.setCacheTtlMs(parseInt(env.BLAMEJS_DNS_CACHE_TTL_MS, 10)); applied.dns.cacheTtlMs = parseInt(env.BLAMEJS_DNS_CACHE_TTL_MS, 10); }
137
+ if (env.BLAMEJS_DOH_URL) { dns.useDnsOverHttps({ url: env.BLAMEJS_DOH_URL }); applied.dns.doh = env.BLAMEJS_DOH_URL; }
138
+ else if (env.BLAMEJS_DOH_PROVIDER) { dns.useDnsOverHttps({ provider: env.BLAMEJS_DOH_PROVIDER }); applied.dns.dohProvider = env.BLAMEJS_DOH_PROVIDER; }
139
+ if (env.BLAMEJS_DOT_HOST) { dns.useDnsOverTls({ host: env.BLAMEJS_DOT_HOST, port: env.BLAMEJS_DOT_PORT ? parseInt(env.BLAMEJS_DOT_PORT, 10) : 853 }); applied.dns.dot = env.BLAMEJS_DOT_HOST; }
140
+
141
+ if (env.HTTP_PROXY || env.http_proxy || env.HTTPS_PROXY || env.https_proxy ||
142
+ env.NO_PROXY || env.no_proxy || env.ALL_PROXY || env.all_proxy) {
143
+ applied.proxy = proxy.fromEnv(env);
144
+ }
145
+
146
+ if (env.BLAMEJS_EXTRA_CA_CERTS) {
147
+ trust.addCa(env.BLAMEJS_EXTRA_CA_CERTS, { label: "BLAMEJS_EXTRA_CA_CERTS" });
148
+ applied.tls.fileLoaded = env.BLAMEJS_EXTRA_CA_CERTS;
149
+ }
150
+ if (env.BLAMEJS_EXTRA_CA_CERTS_DIR) {
151
+ trust.addCaBundle(env.BLAMEJS_EXTRA_CA_CERTS_DIR, { label: "BLAMEJS_EXTRA_CA_CERTS_DIR" });
152
+ applied.tls.dirLoaded = env.BLAMEJS_EXTRA_CA_CERTS_DIR;
153
+ }
154
+ if (env.BLAMEJS_USE_SYSTEM_TRUST === "1" || env.BLAMEJS_USE_SYSTEM_TRUST === "true") {
155
+ trust.useSystemTrust(true);
156
+ applied.tls.systemTrust = true;
157
+ }
158
+
159
+ if (env.BLAMEJS_SOCKET_NO_DELAY) _setSocketNoDelay(env.BLAMEJS_SOCKET_NO_DELAY === "1" || env.BLAMEJS_SOCKET_NO_DELAY === "true");
160
+ if (env.BLAMEJS_SOCKET_KEEPALIVE) _setSocketKeepAlive({ enable: env.BLAMEJS_SOCKET_KEEPALIVE === "1" || env.BLAMEJS_SOCKET_KEEPALIVE === "true" });
161
+ if (env.BLAMEJS_SOCKET_KEEPALIVE_DELAY_MS) _setSocketKeepAlive({ initialDelayMs: parseInt(env.BLAMEJS_SOCKET_KEEPALIVE_DELAY_MS, 10) });
162
+ applied.socket = _socketDefaults();
163
+
164
+ var auditOn = opts.audit !== false;
165
+ if (auditOn) {
166
+ var sink;
167
+ try { sink = audit(); } catch (_e) { sink = null; }
168
+ if (sink && typeof sink.safeEmit === "function") {
169
+ try {
170
+ sink.safeEmit({
171
+ action: "network.boot.from_env",
172
+ outcome: "success",
173
+ metadata: applied,
174
+ });
175
+ } catch (_e) {}
176
+ }
177
+ }
178
+ _emitObs("network.boot.from_env", { source: "env" });
179
+ return applied;
180
+ }
181
+
182
+ function snapshot() {
183
+ return {
184
+ ntp: {
185
+ servers: ntpFacade.getServers(),
186
+ thresholds: ntpCheck.getThresholds(),
187
+ },
188
+ dns: dns._stateForTest(),
189
+ proxy: proxy.snapshot(),
190
+ tls: {
191
+ systemTrust: trust.isSystemTrustEnabled(),
192
+ caCount: trust.getTrustStore().length,
193
+ },
194
+ heartbeat: heartbeat.statuses(),
195
+ socket: _socketDefaults(),
196
+ };
197
+ }
198
+
199
+ function _emitObs(name, fields) {
200
+ try { observability().emit(name, fields || {}); } catch (_e) {}
201
+ }
202
+
203
+ function _resetForTest() {
204
+ ntpFacade._defaultServers = null;
205
+ ntpFacade._defaultTimeoutMs = null;
206
+ if (typeof ntpCheck._resetThresholdsForTest === "function") ntpCheck._resetThresholdsForTest();
207
+ dns._resetForTest();
208
+ proxy._resetForTest();
209
+ trust._resetForTest();
210
+ heartbeat._resetForTest();
211
+ SOCKET_DEFAULTS.noDelay = true;
212
+ SOCKET_DEFAULTS.keepAlive = true;
213
+ SOCKET_DEFAULTS.keepAliveInitialDelayMs = 0;
214
+ }
215
+
216
+ module.exports = {
217
+ ntp: ntpFacade,
218
+ dns: dns,
219
+ proxy: proxy,
220
+ tls: trust,
221
+ heartbeat: heartbeat,
222
+ socket: {
223
+ setDefaultNoDelay: _setSocketNoDelay,
224
+ setDefaultKeepAlive: _setSocketKeepAlive,
225
+ setDefaultLinger: _setSocketLinger,
226
+ defaults: _socketDefaults,
227
+ applyToSocket: applyToSocket,
228
+ },
229
+ bootFromEnv: bootFromEnv,
230
+ snapshot: snapshot,
231
+ NetworkError: NetworkError,
232
+ _resetForTest: _resetForTest,
233
+ };
package/lib/notify.js CHANGED
@@ -49,6 +49,7 @@
49
49
 
50
50
  var lazyRequire = require("./lazy-require");
51
51
  var bootLog = require("./log");
52
+ var numericChecks = require("./numeric-checks");
52
53
  var requestHelpers = require("./request-helpers");
53
54
  var safeAsync = require("./safe-async");
54
55
  var safeUrl = require("./safe-url");
@@ -76,9 +77,7 @@ var DEFAULTS = Object.freeze({
76
77
 
77
78
  // ---- Call-site validation (throw on bad input) ----
78
79
 
79
- function _isFiniteNonNegative(n) {
80
- return typeof n === "number" && isFinite(n) && n >= 0;
81
- }
80
+ var _isFiniteNonNegative = numericChecks.isFiniteNonNegative;
82
81
 
83
82
  function _validateTransport(name, t) {
84
83
  if (!t || typeof t !== "object") {
package/lib/ntp-check.js CHANGED
@@ -36,6 +36,43 @@ var DEFAULT_SERVERS = ["pool.ntp.org", "time.cloudflare.com"];
36
36
  var DEFAULT_PORT = 123;
37
37
  var DEFAULT_TIMEOUT_MS = 3000;
38
38
 
39
+ var DEFAULT_DRIFT_WARN_MS = C.TIME.minutes(5);
40
+ var DEFAULT_DRIFT_FATAL_MS = C.TIME.hours(1);
41
+
42
+ var thresholds = {
43
+ warnMs: DEFAULT_DRIFT_WARN_MS,
44
+ fatalMs: DEFAULT_DRIFT_FATAL_MS,
45
+ };
46
+
47
+ function setThresholds(opts) {
48
+ opts = opts || {};
49
+ if (opts.warnMs !== undefined) {
50
+ if (typeof opts.warnMs !== "number" || !isFinite(opts.warnMs) || opts.warnMs < 0) {
51
+ throw new TypeError("ntpCheck.setThresholds: warnMs must be non-negative finite number, got " + JSON.stringify(opts.warnMs));
52
+ }
53
+ thresholds.warnMs = opts.warnMs;
54
+ }
55
+ if (opts.fatalMs !== undefined) {
56
+ if (typeof opts.fatalMs !== "number" || !isFinite(opts.fatalMs) || opts.fatalMs < 0) {
57
+ throw new TypeError("ntpCheck.setThresholds: fatalMs must be non-negative finite number, got " + JSON.stringify(opts.fatalMs));
58
+ }
59
+ thresholds.fatalMs = opts.fatalMs;
60
+ }
61
+ if (thresholds.warnMs > thresholds.fatalMs && thresholds.fatalMs > 0) {
62
+ throw new RangeError("ntpCheck.setThresholds: warnMs (" + thresholds.warnMs +
63
+ ") must be <= fatalMs (" + thresholds.fatalMs + ")");
64
+ }
65
+ }
66
+
67
+ function getThresholds() {
68
+ return { warnMs: thresholds.warnMs, fatalMs: thresholds.fatalMs };
69
+ }
70
+
71
+ function _resetThresholdsForTest() {
72
+ thresholds.warnMs = DEFAULT_DRIFT_WARN_MS;
73
+ thresholds.fatalMs = DEFAULT_DRIFT_FATAL_MS;
74
+ }
75
+
39
76
  /**
40
77
  * Query an NTP server once. Resolves with { driftMs, serverTimeMs } or
41
78
  * rejects with { code, message } where code is one of:
@@ -142,22 +179,26 @@ async function bootCheck(opts) {
142
179
  }
143
180
  var absMs = Math.abs(result.driftMs);
144
181
  var driftStr = (result.driftMs >= 0 ? "+" : "") + result.driftMs + "ms";
145
- if (absMs >= C.TIME.hours(1)) {
182
+ var fatalMs = (opts && typeof opts.driftFatalMs === "number") ? opts.driftFatalMs : thresholds.fatalMs;
183
+ var warnMs = (opts && typeof opts.driftWarnMs === "number") ? opts.driftWarnMs : thresholds.warnMs;
184
+ if (fatalMs > 0 && absMs >= fatalMs) {
146
185
  return {
147
186
  ok: false,
148
187
  severity: "fatal",
149
188
  driftMs: result.driftMs,
150
189
  server: result.server,
151
- message: "clock drift " + driftStr + " from " + result.server + " (>= 1 hour) — refuse to boot",
190
+ message: "clock drift " + driftStr + " from " + result.server +
191
+ " (>= " + fatalMs + "ms) — refuse to boot",
152
192
  };
153
193
  }
154
- if (absMs >= C.TIME.minutes(5)) {
194
+ if (warnMs > 0 && absMs >= warnMs) {
155
195
  return {
156
196
  ok: true,
157
197
  severity: "warning",
158
198
  driftMs: result.driftMs,
159
199
  server: result.server,
160
- message: "clock drift " + driftStr + " from " + result.server + " (>= 5 minutes) — investigate",
200
+ message: "clock drift " + driftStr + " from " + result.server +
201
+ " (>= " + warnMs + "ms) — investigate",
161
202
  };
162
203
  }
163
204
  return {
@@ -173,6 +214,11 @@ module.exports = {
173
214
  querySingle: querySingle,
174
215
  checkDrift: checkDrift,
175
216
  bootCheck: bootCheck,
217
+ setThresholds: setThresholds,
218
+ getThresholds: getThresholds,
176
219
  DEFAULT_SERVERS: DEFAULT_SERVERS,
220
+ DEFAULT_DRIFT_WARN_MS: DEFAULT_DRIFT_WARN_MS,
221
+ DEFAULT_DRIFT_FATAL_MS: DEFAULT_DRIFT_FATAL_MS,
177
222
  NTP_TO_UNIX_OFFSET_SECONDS: NTP_TO_UNIX_OFFSET_SECONDS,
223
+ _resetThresholdsForTest: _resetThresholdsForTest,
178
224
  };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * numeric-checks — predicate helpers for opts / arg validation.
4
+ *
5
+ * Existed previously as private `_isPositiveInt` / `_isFiniteNonNegative`
6
+ * / `_isNonNegFinite` copies inside api-key, cache, notify, retry, slug,
7
+ * testing, webhook, and (new in v0.6.12) inline checks in queue and
8
+ * restore. Same shape, different file — that's the repeat-means-primitive
9
+ * rule. Everything routes through here now so adding (e.g.) NaN-or-
10
+ * Infinity-string handling is a one-file change.
11
+ *
12
+ * Predicates only — callers throw with their own framework-error class.
13
+ *
14
+ * isPositiveInt(n) n is a finite integer >= 1
15
+ * isFiniteNonNegative(n) n is a finite number >= 0
16
+ * isPositiveFinite(n) n is a finite number > 0
17
+ *
18
+ * All return false for non-numbers, NaN, Infinity, -Infinity, null,
19
+ * undefined, strings, etc. — operators get one consistent gate against
20
+ * the silent-NaN-cap class of bug regardless of which primitive they're
21
+ * configuring.
22
+ */
23
+
24
+ function isPositiveInt(n) {
25
+ return typeof n === "number" && isFinite(n) && n >= 1 && Math.floor(n) === n;
26
+ }
27
+
28
+ function isFiniteNonNegative(n) {
29
+ return typeof n === "number" && isFinite(n) && n >= 0;
30
+ }
31
+
32
+ function isPositiveFinite(n) {
33
+ return typeof n === "number" && isFinite(n) && n > 0;
34
+ }
35
+
36
+ module.exports = {
37
+ isPositiveInt: isPositiveInt,
38
+ isFiniteNonNegative: isFiniteNonNegative,
39
+ isPositiveFinite: isPositiveFinite,
40
+ };
@@ -400,49 +400,23 @@ function create(config) {
400
400
  function presignedUploadUrl(opts) { return _presign("PUT", "cw", opts); }
401
401
  function presignedDownloadUrl(opts) { return _presign("GET", "r", opts); }
402
402
 
403
- // Azure SAS doesn't support an equivalent of S3 / GCS POST policy
404
- // with a content-length-range constraint. The SAS spec carries
405
- // permissions / start / expiry / IP / protocol / resource-content-
406
- // headers but no body-size cap Azure validates the upload at the
407
- // service level only via the operator's optional Block Blob size
408
- // limit applied at storage-account or container scope, not via the
409
- // SAS token itself.
403
+ // Azure SAS has no equivalent of S3 / GCS POST policy with a
404
+ // content-length-range constraint the SAS spec carries permissions
405
+ // / start / expiry / IP / protocol / resource-content-headers but
406
+ // no body-size cap. Returning a PUT URL under the POST-policy name
407
+ // would be a silent shape mismatch (operators wiring an HTML form
408
+ // expecting multipart fields get a PUT URL with no fields), so the
409
+ // azure-blob backend refuses cleanly.
410
410
  //
411
- // Rather than throw NOT_SUPPORTED, this returns the same SAS PUT
412
- // shape as presignedUploadUrl with an `enforcement: 'client-only'`
413
- // marker so operators making cross-vendor decisions know the
414
- // body-size guard is advisory on Azure and must be enforced on the
415
- // client side or via a server-side post-upload check.
416
- //
417
- // For strict server-side body-size enforcement on Azure, the
418
- // canonical pattern is: SAS-authorize the upload, then have the
419
- // operator's app issue a HEAD on the resulting blob and delete +
420
- // 4xx the requester if Content-Length > opts.maxBytes.
421
- function presignedUploadPolicy(opts) {
422
- opts = opts || {};
423
- if (typeof opts.maxBytes !== "number" || !Number.isFinite(opts.maxBytes) ||
424
- opts.maxBytes <= 0) {
425
- throw _err("INVALID_MAX_BYTES",
426
- "presignedUploadPolicy: maxBytes (positive number of bytes) is required " +
427
- "(advisory on Azure — see docstring for server-side enforcement)", true);
428
- }
429
- var underlying = _presign("PUT", "cw", opts);
430
- return {
431
- url: underlying.url,
432
- method: "PUT",
433
- // SAS uploads are PUT, not multipart POST — there are no form
434
- // fields. Operators uploading attach the body directly to the
435
- // returned URL with the headers in `headers`.
436
- fields: null,
437
- headers: underlying.headers,
438
- expiresAt: underlying.expiresAt,
439
- maxBytes: opts.maxBytes,
440
- enforcement: "client-only",
441
- enforcementNote:
442
- "Azure SAS does not natively cap upload size. Operators needing " +
443
- "strict size enforcement must HEAD the blob post-upload and reject " +
444
- "if Content-Length exceeds maxBytes.",
445
- };
411
+ // For strict server-side body-size enforcement on Azure: use
412
+ // presignedUploadUrl + a server-side post-upload HEAD that deletes
413
+ // and 4xxs the requester if Content-Length > limit.
414
+ function presignedUploadPolicy(_opts) {
415
+ throw _err("PRESIGN_NOT_SUPPORTED",
416
+ "azure-blob backend does not support presigned upload policies — " +
417
+ "Azure SAS has no body-size cap. Use presignedUploadUrl + a server-side " +
418
+ "HEAD-and-delete check, or switch to an S3 / GCS-compatible backend.",
419
+ true);
446
420
  }
447
421
 
448
422
  return {