@blamejs/blamejs-shop 0.5.20 → 0.5.21

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 (93) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +1 -0
  3. package/SECURITY.md +17 -0
  4. package/lib/addresses.js +2 -2
  5. package/lib/admin.js +14 -5
  6. package/lib/affiliates.js +7 -23
  7. package/lib/announcement-bar.js +5 -22
  8. package/lib/api-keys.js +4 -13
  9. package/lib/asset-manifest.json +1 -1
  10. package/lib/banner-ab-tests.js +5 -9
  11. package/lib/blog-articles.js +8 -26
  12. package/lib/captcha-gate.js +7 -17
  13. package/lib/carrier-accounts.js +3 -10
  14. package/lib/catalog-drafts.js +5 -12
  15. package/lib/category-navigation.js +4 -20
  16. package/lib/cms-blocks.js +4 -7
  17. package/lib/compliance-export.js +4 -11
  18. package/lib/consent-ledger.js +2 -4
  19. package/lib/cost-layers.js +56 -21
  20. package/lib/customer-import.js +2 -2
  21. package/lib/customer-notes.js +7 -23
  22. package/lib/customer-roles.js +3 -5
  23. package/lib/customer-segments.js +17 -14
  24. package/lib/customer-surveys.js +7 -14
  25. package/lib/customers.js +2 -4
  26. package/lib/dispute-resolution.js +5 -13
  27. package/lib/dropship-forwarding.js +3 -5
  28. package/lib/dunning.js +2 -7
  29. package/lib/email-ab-tests.js +4 -8
  30. package/lib/email-campaigns.js +25 -14
  31. package/lib/email-warmup.js +2 -7
  32. package/lib/experiments.js +6 -10
  33. package/lib/externaldb-d1.js +47 -23
  34. package/lib/geolocation.js +18 -28
  35. package/lib/gift-options.js +5 -23
  36. package/lib/knowledge-base.js +7 -22
  37. package/lib/line-gift-wrap.js +3 -17
  38. package/lib/live-chat.js +5 -18
  39. package/lib/metered-usage.js +3 -8
  40. package/lib/notifications.js +3 -7
  41. package/lib/operator-accounts.js +3 -5
  42. package/lib/operator-approvals.js +6 -8
  43. package/lib/operator-audit-log.js +2 -7
  44. package/lib/operator-help-center.js +5 -21
  45. package/lib/operator-inbox.js +4 -11
  46. package/lib/operator-roles.js +5 -7
  47. package/lib/order-escalation.js +2 -2
  48. package/lib/order-export.js +24 -20
  49. package/lib/order-notes.js +4 -14
  50. package/lib/order-ratings.js +4 -10
  51. package/lib/payment-methods.js +5 -13
  52. package/lib/payment-retries.js +2 -7
  53. package/lib/pixel-events.js +8 -23
  54. package/lib/plan-changes.js +2 -7
  55. package/lib/product-qa.js +4 -8
  56. package/lib/promo-banners.js +7 -15
  57. package/lib/purchase-orders.js +3 -6
  58. package/lib/push-notifications.js +7 -32
  59. package/lib/pwa-manifest.js +6 -11
  60. package/lib/quotes.js +5 -9
  61. package/lib/reviews.js +4 -10
  62. package/lib/robots-config.js +6 -14
  63. package/lib/sales-tax-filings.js +2 -2
  64. package/lib/search-facets.js +5 -5
  65. package/lib/search-ranking.js +4 -7
  66. package/lib/search-synonyms.js +7 -21
  67. package/lib/security-middleware.js +86 -58
  68. package/lib/seller-signup.js +10 -26
  69. package/lib/sidebar-widgets.js +6 -15
  70. package/lib/site-redirects.js +5 -16
  71. package/lib/sitemap-generator.js +3 -7
  72. package/lib/sms-dispatcher.js +7 -23
  73. package/lib/stock-receipts.js +4 -10
  74. package/lib/storefront-dashboards.js +2 -10
  75. package/lib/storefront-forms.js +9 -22
  76. package/lib/storefront-pages.js +6 -20
  77. package/lib/storefront.js +2 -2
  78. package/lib/subscription-billing.js +3 -8
  79. package/lib/subscription-controls.js +2 -7
  80. package/lib/suggestion-box.js +9 -26
  81. package/lib/support-tickets.js +6 -24
  82. package/lib/tax-remittance.js +2 -2
  83. package/lib/tenants.js +2 -7
  84. package/lib/text-guard.js +137 -35
  85. package/lib/theme-assets.js +4 -16
  86. package/lib/translations.js +3 -6
  87. package/lib/trust-badges.js +4 -7
  88. package/lib/vendor-invoices.js +3 -6
  89. package/lib/vendors.js +5 -19
  90. package/lib/webhook-receiver.js +3 -10
  91. package/lib/webhook-subscriptions.js +3 -13
  92. package/lib/wishlist-sharing.js +5 -10
  93. package/package.json +1 -1
package/lib/reviews.js CHANGED
@@ -50,9 +50,9 @@ var REVIEW_ORDER_KEY = ["created_at:desc", "id:desc"];
50
50
  var CUSTOMER_ORDER_KEY = ["created_at:desc", "id:desc"];
51
51
 
52
52
  var ALLOWED_STATUSES = ["pending", "published", "rejected"];
53
- var CONTROL_BYTE_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/;
54
53
 
55
54
  var b = require("./vendor/blamejs");
55
+ var textGuard = require("./text-guard");
56
56
 
57
57
  // ---- validators ---------------------------------------------------------
58
58
 
@@ -75,9 +75,7 @@ function _title(s) {
75
75
  if (s.length > MAX_TITLE_LEN) {
76
76
  throw new TypeError("reviews: title must be <= " + MAX_TITLE_LEN + " characters");
77
77
  }
78
- if (CONTROL_BYTE_RE.test(s)) {
79
- throw new TypeError("reviews: title contains control bytes");
80
- }
78
+ textGuard.freeText(s, "reviews: title");
81
79
  return s;
82
80
  }
83
81
 
@@ -89,9 +87,7 @@ function _body(s) {
89
87
  if (s.length > MAX_BODY_LEN) {
90
88
  throw new TypeError("reviews: body must be <= " + MAX_BODY_LEN + " characters");
91
89
  }
92
- if (CONTROL_BYTE_RE.test(s)) {
93
- throw new TypeError("reviews: body contains control bytes");
94
- }
90
+ textGuard.freeText(s, "reviews: body");
95
91
  return s;
96
92
  }
97
93
 
@@ -288,9 +284,7 @@ function create(opts) {
288
284
  if (reason.length > MAX_REJECT_REASON_LEN) {
289
285
  throw new TypeError("reviews.reject: reason must be <= " + MAX_REJECT_REASON_LEN + " characters");
290
286
  }
291
- if (CONTROL_BYTE_RE.test(reason)) {
292
- throw new TypeError("reviews.reject: reason contains control bytes");
293
- }
287
+ textGuard.freeText(reason, "reviews.reject: reason");
294
288
  }
295
289
  var ts = _now();
296
290
  var existing = (await query("SELECT id, status FROM reviews WHERE id = ?1", [id])).rows[0];
@@ -96,9 +96,9 @@ var MAX_CRAWL_DELAY = 86400; // 24 h — anything larger is a typo
96
96
  var MAX_PRIORITY = 1000000;
97
97
  var MAX_RULE_ID_LEN = 80;
98
98
 
99
- var CONTROL_BYTE_RE = /[\x00-\x1f\x7f]/;
100
99
 
101
100
  var b = require("./vendor/blamejs");
101
+ var textGuard = require("./text-guard");
102
102
 
103
103
  // ---- predefined templates ---------------------------------------------
104
104
  //
@@ -183,9 +183,7 @@ function _userAgent(s) {
183
183
  "robotsConfig: user_agent must be a string 1.." + MAX_USER_AGENT_LEN + " chars"
184
184
  );
185
185
  }
186
- if (CONTROL_BYTE_RE.test(s)) {
187
- throw new TypeError("robotsConfig: user_agent must not contain control bytes");
188
- }
186
+ textGuard.freeText(s, "robotsConfig: user_agent", { singleLine: "reject" });
189
187
  // robots.txt is a colon-delimited key/value format — a colon in the
190
188
  // user-agent value would shift the parser onto a different key.
191
189
  if (s.indexOf(":") !== -1) {
@@ -200,7 +198,7 @@ function _pathEntry(s, label) {
200
198
  "robotsConfig: " + label + " entry must be a string 1.." + MAX_PATH_LEN + " chars"
201
199
  );
202
200
  }
203
- if (CONTROL_BYTE_RE.test(s)) {
201
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject" })) {
204
202
  throw new TypeError("robotsConfig: " + label + " entry must not contain control bytes");
205
203
  }
206
204
  // robots.txt path entries are /-rooted absolute paths. Wildcards
@@ -258,9 +256,7 @@ function _ruleId(s) {
258
256
  "robotsConfig: rule_id must be a string 1.." + MAX_RULE_ID_LEN + " chars"
259
257
  );
260
258
  }
261
- if (CONTROL_BYTE_RE.test(s)) {
262
- throw new TypeError("robotsConfig: rule_id must not contain control bytes");
263
- }
259
+ textGuard.freeText(s, "robotsConfig: rule_id", { singleLine: "reject" });
264
260
  return s;
265
261
  }
266
262
 
@@ -270,9 +266,7 @@ function _sitemapUrl(u) {
270
266
  "robotsConfig: sitemap url must be a string 1.." + MAX_SITEMAP_URL_LEN + " chars"
271
267
  );
272
268
  }
273
- if (CONTROL_BYTE_RE.test(u)) {
274
- throw new TypeError("robotsConfig: sitemap url must not contain control bytes");
275
- }
269
+ textGuard.freeText(u, "robotsConfig: sitemap url", { singleLine: "reject" });
276
270
  // robots.txt only carries the URL itself, so the path-rooted form
277
271
  // promo-banners accepts isn't meaningful here — every crawler treats
278
272
  // the Sitemap: value as an absolute URL. https-only protects against
@@ -293,9 +287,7 @@ function _hostDirective(s) {
293
287
  "robotsConfig: host must be a string 1.." + MAX_HOST_LEN + " chars"
294
288
  );
295
289
  }
296
- if (CONTROL_BYTE_RE.test(s)) {
297
- throw new TypeError("robotsConfig: host must not contain control bytes");
298
- }
290
+ textGuard.freeText(s, "robotsConfig: host", { singleLine: "reject" });
299
291
  // The host directive is a bare hostname (optionally with :port) —
300
292
  // no scheme, no path. Refuse anything that looks like a URL so an
301
293
  // operator can't accidentally paste the full origin URL in.
@@ -104,6 +104,7 @@
104
104
  */
105
105
 
106
106
  var b = require("./vendor/blamejs");
107
+ var textGuard = require("./text-guard");
107
108
  var C = b.constants;
108
109
 
109
110
  // ---- constants ----------------------------------------------------------
@@ -122,7 +123,6 @@ var DEFAULT_LIMIT = 50;
122
123
  var MAX_LIMIT = 500;
123
124
  var MAX_DAYS_AHEAD = 365;
124
125
 
125
- var CONTROL_BYTE_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/;
126
126
 
127
127
  // FSM transition map. The keys are (from_status, action) → to_status.
128
128
  // Defined as a table so a misuse surfaces with the actual current
@@ -211,7 +211,7 @@ function _shortText(s, label, max) {
211
211
  throw new TypeError("salesTaxFilings: " + label +
212
212
  " must be a non-empty string <= " + max + " chars");
213
213
  }
214
- if (CONTROL_BYTE_RE.test(s)) {
214
+ if (textGuard.hasCodepointThreat(s)) {
215
215
  throw new TypeError("salesTaxFilings: " + label + " must not contain control bytes");
216
216
  }
217
217
  return s;
@@ -106,7 +106,6 @@ var ALLOWED_KINDS = ["categorical", "numeric_range", "boolean"];
106
106
  var ALLOWED_COLS = ["field", "kind", "buckets_json", "display_limit", "active"];
107
107
 
108
108
  // Refuse C0 control bytes + DEL on every operator-supplied string.
109
- var CONTROL_BYTE_RE = /[\x00-\x1f\x7f]/;
110
109
 
111
110
  // Operator-chosen identifier shape — lowercase alnum + hyphen +
112
111
  // underscore, must start with a letter. Same shape the rest of the
@@ -118,6 +117,7 @@ var KEY_RE = /^[a-z][a-z0-9_-]*$/;
118
117
  var FIELD_RE = /^[a-z][a-z0-9_-]*$/;
119
118
 
120
119
  var b = require("./vendor/blamejs");
120
+ var textGuard = require("./text-guard");
121
121
 
122
122
  // ---- validators ---------------------------------------------------------
123
123
 
@@ -175,7 +175,7 @@ function _label(s, fnLabel) {
175
175
  if (s.length > MAX_LABEL_LEN) {
176
176
  throw new TypeError(fnLabel + ": bucket label must be <= " + MAX_LABEL_LEN + " characters");
177
177
  }
178
- if (CONTROL_BYTE_RE.test(s)) {
178
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject" })) {
179
179
  throw new TypeError(fnLabel + ": bucket label must not contain control bytes");
180
180
  }
181
181
  return s;
@@ -291,7 +291,7 @@ function _appliedFilters(input, fnLabel) {
291
291
  if (s.length > MAX_VALUE_LEN) {
292
292
  throw new TypeError(fnLabel + ": applied_filters['" + k + "'][" + j + "] must be <= " + MAX_VALUE_LEN + " characters");
293
293
  }
294
- if (CONTROL_BYTE_RE.test(s)) {
294
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject" })) {
295
295
  throw new TypeError(fnLabel + ": applied_filters['" + k + "'][" + j + "] must not contain control bytes");
296
296
  }
297
297
  values.push(s);
@@ -318,7 +318,7 @@ function _value(raw, fnLabel) {
318
318
  if (s.length > MAX_VALUE_LEN) {
319
319
  throw new TypeError(fnLabel + ": value must be <= " + MAX_VALUE_LEN + " characters");
320
320
  }
321
- if (CONTROL_BYTE_RE.test(s)) {
321
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject" })) {
322
322
  throw new TypeError(fnLabel + ": value must not contain control bytes");
323
323
  }
324
324
  return s;
@@ -331,7 +331,7 @@ function _sessionId(s, fnLabel) {
331
331
  if (s.length > 256) {
332
332
  throw new TypeError(fnLabel + ": session_id must be <= 256 characters");
333
333
  }
334
- if (CONTROL_BYTE_RE.test(s)) {
334
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject" })) {
335
335
  throw new TypeError(fnLabel + ": session_id must not contain control bytes");
336
336
  }
337
337
  return s;
@@ -121,12 +121,9 @@ var SIGNAL_RE = /^[a-z][a-z0-9_-]*$/;
121
121
  // which covers SKU notation across every common upstream system
122
122
  // without opening the door to control bytes or whitespace.
123
123
  var PRODUCT_ID_RE = /^[A-Za-z0-9._:/-]+$/;
124
- var CONTROL_BYTE_RE = /[\x00-\x1f\x7f]/;
125
- var ZERO_WIDTH_RE = new RegExp(
126
- "[\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFEFF\\u061C]"
127
- );
128
124
 
129
125
  var b = require("./vendor/blamejs");
126
+ var textGuard = require("./text-guard");
130
127
 
131
128
  // ---- monotonic clock ---------------------------------------------------
132
129
  //
@@ -175,7 +172,7 @@ function _name(s, fnLabel) {
175
172
  if (s.length > MAX_NAME_LEN) {
176
173
  throw new TypeError(fnLabel + ": name must be <= " + MAX_NAME_LEN + " characters");
177
174
  }
178
- if (CONTROL_BYTE_RE.test(s) || ZERO_WIDTH_RE.test(s)) {
175
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject", zeroWidth: "reject" })) {
179
176
  throw new TypeError(fnLabel + ": name contains control / zero-width bytes");
180
177
  }
181
178
  return s;
@@ -226,7 +223,7 @@ function _normalizeQuery(s, fnLabel) {
226
223
  if (s.length > MAX_QUERY_LEN) {
227
224
  throw new TypeError(fnLabel + ": query must be <= " + MAX_QUERY_LEN + " characters");
228
225
  }
229
- if (CONTROL_BYTE_RE.test(s) || ZERO_WIDTH_RE.test(s)) {
226
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject", zeroWidth: "reject" })) {
230
227
  throw new TypeError(fnLabel + ": query contains control / zero-width bytes");
231
228
  }
232
229
  var normalized = s.toLowerCase().replace(/\s+/g, " ").trim();
@@ -270,7 +267,7 @@ function _sessionIdRaw(s, fnLabel) {
270
267
  if (s.length > MAX_SESSION_ID_LEN) {
271
268
  throw new TypeError(fnLabel + ": session_id must be <= " + MAX_SESSION_ID_LEN + " characters");
272
269
  }
273
- if (CONTROL_BYTE_RE.test(s) || ZERO_WIDTH_RE.test(s)) {
270
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject", zeroWidth: "reject" })) {
274
271
  throw new TypeError(fnLabel + ": session_id contains control / zero-width bytes");
275
272
  }
276
273
  return s;
@@ -102,18 +102,6 @@ var MAX_QUERY_LEN = 500;
102
102
  var ALLOWED_KINDS = ["bidirectional", "directional"];
103
103
  var ALLOWED_GROUP_COLS = ["kind", "terms_json"];
104
104
 
105
- // Refuse C0 control bytes + DEL. Tokens are single-line search terms;
106
- // any newline / tab in a synonym entry would either be malformed
107
- // operator input or an attempt to smuggle separator-confusion payload
108
- // into the search log.
109
- var CONTROL_BYTE_RE = /[\x00-\x1f\x7f]/;
110
- // Zero-width + direction-override family — same defense as
111
- // `supportTickets`. Spelled with \u escapes so the file stays
112
- // ESLint no-irregular-whitespace clean.
113
- var ZERO_WIDTH_RE = new RegExp(
114
- "[\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFEFF\\u061C]"
115
- );
116
-
117
105
  // Slug shape — operator-chosen identifier on synonym groups. Same
118
106
  // shape the rest of the shop uses: lowercase alnum + hyphen, must
119
107
  // start with a letter, 1..MAX_SLUG_LEN.
@@ -126,6 +114,7 @@ var TOKEN_SPLIT_RE = /[^a-z0-9-]+/g;
126
114
 
127
115
  // Framework handle (the vendored blamejs); index.js re-exports this as .framework.
128
116
  var b = require("./vendor/blamejs");
117
+ var textGuard = require("./text-guard");
129
118
 
130
119
  // ---- validators ---------------------------------------------------------
131
120
 
@@ -166,10 +155,10 @@ function _term(s, label, fnLabel) {
166
155
  if (trimmed.length > MAX_TERM_LEN) {
167
156
  throw new TypeError(fnLabel + ": " + label + " must be <= " + MAX_TERM_LEN + " characters");
168
157
  }
169
- if (CONTROL_BYTE_RE.test(trimmed)) {
158
+ if (textGuard.hasCodepointThreat(trimmed, { singleLine: "reject" })) {
170
159
  throw new TypeError(fnLabel + ": " + label + " contains control bytes");
171
160
  }
172
- if (ZERO_WIDTH_RE.test(trimmed)) {
161
+ if (textGuard.hasCodepointThreat(trimmed, { zeroWidth: "reject" })) {
173
162
  throw new TypeError(fnLabel + ": " + label + " contains zero-width / direction-override characters");
174
163
  }
175
164
  return trimmed;
@@ -247,13 +236,10 @@ function _queryString(s, fnLabel) {
247
236
  // give attackers a denial-of-search vector against legitimate
248
237
  // shoppers who happened to paste a stray BOM.
249
238
  function _sanitiseQuery(s) {
250
- return s
251
- .replace(/[\x00-\x1f\x7f]/g, " ")
252
- .replace(
253
- // Zero-width + direction-override family — see ZERO_WIDTH_RE.
254
- new RegExp("[\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFEFF\\u061C]", "g"),
255
- ""
256
- );
239
+ // Controls become a SPACE, not nothing: deleting them outright would weld
240
+ // the words on either side into one token. The invisible characters do get
241
+ // deleted — they sit inside a word rather than between two.
242
+ return textGuard.scrubInvisible(s.replace(/[\x00-\x1f\x7f]/g, " "));
257
243
  }
258
244
 
259
245
  function _tokenise(s) {
@@ -527,26 +527,6 @@ var _SCOPED_DIRECTIVES = {
527
527
  // default-src 'self', object-src 'none',
528
528
  // require-trusted-types-for 'script', frame-ancestors 'none', base-uri 'self'
529
529
 
530
- // Parse the vendored default CSP into an ordered directive map ONCE at
531
- // module load. The default is a `name a b; name c;` string; split on `;`,
532
- // the first token of each clause is the directive name, the rest its
533
- // source list.
534
- function _parseCsp(cspString) {
535
- var order = [];
536
- var map = {};
537
- String(cspString).split(";").forEach(function (clause) {
538
- var trimmed = clause.trim();
539
- if (!trimmed) return;
540
- var parts = trimmed.split(/\s+/);
541
- var name = parts[0];
542
- order.push(name);
543
- map[name] = parts.slice(1);
544
- });
545
- return { order: order, map: map };
546
- }
547
-
548
- var _DEFAULT_CSP_PARSED = _parseCsp(_vendoredSecurityHeaders.DEFAULT_CSP);
549
-
550
530
  /**
551
531
  * Build a route-scoped CSP string from the vendored strict default plus the
552
532
  * named providers' hosts. `keys` is an array of CSP_HOSTS keys
@@ -565,40 +545,51 @@ var _DEFAULT_CSP_PARSED = _parseCsp(_vendoredSecurityHeaders.DEFAULT_CSP);
565
545
  * which fails safe (the SDK is refused, not admitted too broadly).
566
546
  */
567
547
  function scopedCsp(keys) {
568
- // Clone the parsed default so the per-call mutation never leaks into the
569
- // module-level snapshot.
570
- var order = _DEFAULT_CSP_PARSED.order.slice();
571
- var map = {};
572
- _DEFAULT_CSP_PARSED.order.forEach(function (name) {
573
- map[name] = _DEFAULT_CSP_PARSED.map[name].slice();
574
- });
575
-
548
+ // Collect the hosts each named provider needs, per directive. Unknown keys
549
+ // fall out here, which is what keeps a mistyped key on the strict default
550
+ // rather than throwing mid-render.
551
+ var additions = {};
576
552
  if (Array.isArray(keys)) {
577
553
  keys.forEach(function (key) {
578
554
  var hostSet = CSP_HOSTS[key];
579
555
  if (!hostSet) return;
580
556
  Object.keys(_SCOPED_DIRECTIVES).forEach(function (directive) {
581
- var subKey = _SCOPED_DIRECTIVES[directive];
582
- var hosts = hostSet[subKey];
557
+ var hosts = hostSet[_SCOPED_DIRECTIVES[directive]];
583
558
  if (!hosts || !hosts.length) return;
584
- if (!map[directive]) {
585
- // The default omits frame-src (it relies on the default-src /
586
- // fenced-frame-src pair); create it from 'self' so admitting a
587
- // provider frame doesn't accidentally open it to everything.
588
- map[directive] = ["'self'"];
589
- order.push(directive);
590
- }
591
- hosts.forEach(function (h) {
592
- if (map[directive].indexOf(h) === -1) map[directive].push(h);
593
- });
559
+ additions[directive] = (additions[directive] || []).concat(hosts);
594
560
  });
595
561
  });
596
562
  }
597
563
 
598
- return order.map(function (name) {
599
- var srcs = map[name];
600
- return srcs.length ? (name + " " + srcs.join(" ")) : name;
601
- }).join("; ") + ";";
564
+ // b.csp.mergeDirectives owns the merge: append-and-dedupe per directive,
565
+ // seed a directive the base omits rather than leaving it wide open, and
566
+ // validate only what was added so the trusted default round-trips
567
+ // untouched. It replaces a CSP parser written here, which had to be kept
568
+ // in step with whatever shape the vendored default took.
569
+ //
570
+ // The primitive throws on a directive or source it will not accept. This
571
+ // runs per response while rendering a payment page, and the documented
572
+ // contract is that a bad input degrades to the strict default rather than
573
+ // failing the render — so a refusal is caught and answered with exactly
574
+ // that. Failing closed here means the provider is refused, never admitted
575
+ // more broadly than asked.
576
+ // The refusal is recorded rather than swallowed: it means a host in
577
+ // CSP_HOSTS is one the primitive will not accept, which is an operator
578
+ // configuration problem that would otherwise show up only as a payment SDK
579
+ // silently failing to load.
580
+ try {
581
+ return b.csp.mergeDirectives(undefined, additions);
582
+ } catch (e) {
583
+ b.audit.safeEmit({
584
+ action: "shop.security.scopedCsp.refused",
585
+ outcome: "failure",
586
+ metadata: {
587
+ keys: Array.isArray(keys) ? keys.join(",") : String(keys),
588
+ reason: (e && e.message) || "unknown",
589
+ },
590
+ });
591
+ return _vendoredSecurityHeaders.DEFAULT_CSP;
592
+ }
602
593
  }
603
594
 
604
595
  // ---- route-scoped Permissions-Policy (payment + passkey surfaces) --------
@@ -645,7 +636,10 @@ function scopedCsp(keys) {
645
636
  // top-level same-origin document). Quote-wrapped per RFC 9651 structured
646
637
  // fields. Single source — every page that enables the payment feature names
647
638
  // it here.
648
- var _PAYMENT_ALLOWLIST = 'payment=(self "https://js.stripe.com" "https://pay.google.com")';
639
+ // Allowlist VALUES, without the `feature=` prefix — that is the shape
640
+ // b.csp.mergePermissionsPolicy takes, and it keeps the feature name in exactly
641
+ // one place (the registry key) rather than repeated inside its own value.
642
+ var _PAYMENT_ALLOWLIST = '(self "https://js.stripe.com" "https://pay.google.com")';
649
643
 
650
644
  // WebAuthn assertion / attestation run in the page's OWN top-level document
651
645
  // (the islands call navigator.credentials.get / .create directly, never from
@@ -655,8 +649,8 @@ var _PAYMENT_ALLOWLIST = 'payment=(self "https://js.stripe.com" "https://pay.goo
655
649
  // still cannot drive WebAuthn. Single source — every passkey page names the
656
650
  // feature → allowlist mapping here.
657
651
  var _PASSKEY_FEATURE_ALLOWLIST = {
658
- "publickey-credentials-get": "publickey-credentials-get=(self)",
659
- "publickey-credentials-create": "publickey-credentials-create=(self)",
652
+ "publickey-credentials-get": "(self)",
653
+ "publickey-credentials-create": "(self)",
660
654
  };
661
655
 
662
656
  // Feature name → its scoped allowlist token. The pay surface relaxes
@@ -697,12 +691,25 @@ function scopedPermissionsPolicy(opts) {
697
691
  overrides[name] = _SCOPED_FEATURE_OVERRIDES[name];
698
692
  }
699
693
  });
700
- return _vendoredSecurityHeaders.DEFAULT_PERMISSIONS.map(function (entry) {
701
- var feature = entry.split("=")[0];
702
- return Object.prototype.hasOwnProperty.call(overrides, feature)
703
- ? overrides[feature]
704
- : entry;
705
- }).join(", ");
694
+
695
+ // b.csp.mergePermissionsPolicy applies the overrides onto the vendored
696
+ // denylist, replacing a map-and-rejoin over that list here. The registry
697
+ // filter above still runs first, so an unnamed feature cannot be relaxed and
698
+ // an unknown one is dropped rather than passed to a primitive that refuses
699
+ // it — which preserves the documented never-throw behaviour on a render
700
+ // path. A refusal is still possible if a registry VALUE is malformed, and
701
+ // that is an operator configuration error worth surfacing rather than
702
+ // hiding behind a silently strict header.
703
+ try {
704
+ return b.csp.mergePermissionsPolicy(undefined, overrides);
705
+ } catch (e) {
706
+ b.audit.safeEmit({
707
+ action: "shop.security.scopedPermissionsPolicy.refused",
708
+ outcome: "failure",
709
+ metadata: { features: features.join(","), reason: (e && e.message) || "unknown" },
710
+ });
711
+ return _vendoredSecurityHeaders.DEFAULT_PERMISSIONS.join(", ");
712
+ }
706
713
  }
707
714
 
708
715
  /**
@@ -759,7 +766,7 @@ function botGuardOpts() {
759
766
  // directory (e.g. /.well-known/apple-...-association/anything), re-opening
760
767
  // the guard on routes that aren't the single static association file.
761
768
  .concat(PUBLIC_WELL_KNOWN_PATHS.map(function (p) {
762
- return new RegExp("^" + p.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&") + "$");
769
+ return new RegExp("^" + b.codepointClass.escapeRegExp(p) + "$");
763
770
  }))
764
771
  .concat([/^\/admin(\/|$)/]),
765
772
  };
@@ -772,6 +779,28 @@ function _hasPrefix(pathname, prefixes) {
772
779
  return false;
773
780
  }
774
781
 
782
+ // Skip matchers for the request-lifecycle guards, built once.
783
+ //
784
+ // b.requestHelpers.makeSkipMatcher takes the REQUEST rather than a pathname
785
+ // the caller derived, which removes three copies of `req.pathname || req.url
786
+ // || "/"` and keeps the exemption correct if a guard is ever mounted somewhere
787
+ // the router has not already set `req.pathname` — the matcher strips the query
788
+ // string itself rather than trusting the caller to have done it.
789
+ //
790
+ // Two matchers because the semantics differ: a webhook path is a PREFIX (the
791
+ // processor may append to it) while the health path is EXACT (`/_/healthz`
792
+ // must not inherit the exemption).
793
+ var _skipWebhookPath = b.requestHelpers.makeSkipMatcher(
794
+ { skipPaths: WEBHOOK_PATHS.slice() }, "securityMiddleware.webhookSkip");
795
+ var _skipHealthPath = b.requestHelpers.makeSkipMatcher(
796
+ { skipPaths: [HEALTH_PATH], exact: true }, "securityMiddleware.healthSkip");
797
+
798
+ // Both guards exempt the same set: a server-to-server webhook authenticated by
799
+ // its own signature, and the liveness probe.
800
+ function _isUnguardedPath(req) {
801
+ return _skipWebhookPath(req) || _skipHealthPath(req);
802
+ }
803
+
775
804
  /**
776
805
  * Mount the per-route tight rate limiters + the fetch-metadata gate on
777
806
  * the router inside the operator's `routes(r)` chain. Call AFTER the
@@ -830,7 +859,7 @@ function mountRouteGuards(r) {
830
859
  });
831
860
  r.use(function csrfGuard(req, res, next) {
832
861
  var pathname = req.pathname || req.url || "/";
833
- if (_hasPrefix(pathname, WEBHOOK_PATHS) || pathname === HEALTH_PATH) return next();
862
+ if (_isUnguardedPath(req)) return next();
834
863
  if (isEdgeExemptPath(pathname)) return next();
835
864
  return csrfGate(req, res, next);
836
865
  });
@@ -852,8 +881,7 @@ function mountRouteGuards(r) {
852
881
  allowedNavigate: true,
853
882
  });
854
883
  r.use(function fetchMetadataGuard(req, res, next) {
855
- var pathname = req.pathname || req.url || "/";
856
- if (_hasPrefix(pathname, WEBHOOK_PATHS)) return next();
884
+ if (_skipWebhookPath(req)) return next();
857
885
  return fmGate(req, res, next);
858
886
  });
859
887
 
@@ -907,7 +935,7 @@ function mountRouteGuards(r) {
907
935
  r.use(function tightRateGuard(req, res, next) {
908
936
  var pathname = req.pathname || req.url || "/";
909
937
  // Never throttle the webhook or health paths.
910
- if (_hasPrefix(pathname, WEBHOOK_PATHS) || pathname === HEALTH_PATH) return next();
938
+ if (_isUnguardedPath(req)) return next();
911
939
  if (!_hasPrefix(pathname, TIGHT_PREFIXES)) return next();
912
940
  // `/products/`, `/gift-cards`, and `/orders/` carry GET reads (PDP,
913
941
  // balance page render, order confirmation page) that a shopper hits
@@ -129,12 +129,9 @@ var MIME_RE = /^[A-Za-z0-9!#$&^_.+\-]{1,127}\/[A-Za-z0-9!#$&^_
129
129
  // the shape vendors / purchase-orders use. Operator-rendered fields
130
130
  // refuse these to keep downstream dashboards / KYC printouts safe
131
131
  // from header-injection + visual-spoofing attacks.
132
- var CONTROL_BYTE_RE = /[\x00-\x1f\x7f]/;
133
- var ZERO_WIDTH_RE = new RegExp(
134
- "[\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFEFF\\u061C]"
135
- );
136
132
 
137
133
  var b = require("./vendor/blamejs");
134
+ var textGuard = require("./text-guard");
138
135
 
139
136
  // ---- validators ---------------------------------------------------------
140
137
 
@@ -157,12 +154,7 @@ function _businessName(s) {
157
154
  if (s.length > MAX_BUSINESS_NAME_LEN) {
158
155
  throw new TypeError("seller-signup: business_name must be <= " + MAX_BUSINESS_NAME_LEN + " characters");
159
156
  }
160
- if (CONTROL_BYTE_RE.test(s)) {
161
- throw new TypeError("seller-signup: business_name contains control bytes");
162
- }
163
- if (ZERO_WIDTH_RE.test(s)) {
164
- throw new TypeError("seller-signup: business_name contains zero-width / direction-override bytes");
165
- }
157
+ textGuard.freeText(s, "seller-signup: business_name", { singleLine: "reject", zeroWidth: "reject" });
166
158
  return s;
167
159
  }
168
160
 
@@ -219,9 +211,7 @@ function _businessAddress(value) {
219
211
  if (encoded.length > MAX_ADDRESS_JSON_LEN) {
220
212
  throw new TypeError("seller-signup: business_address JSON must be <= " + MAX_ADDRESS_JSON_LEN + " characters serialised");
221
213
  }
222
- if (CONTROL_BYTE_RE.test(encoded) || ZERO_WIDTH_RE.test(encoded)) {
223
- throw new TypeError("seller-signup: business_address contains control / zero-width bytes");
224
- }
214
+ textGuard.freeText(encoded, "seller-signup: business_address", { singleLine: "reject", zeroWidth: "reject" });
225
215
  return encoded;
226
216
  }
227
217
 
@@ -260,7 +250,7 @@ function _categoryFocus(value) {
260
250
  if (typeof value[i] !== "string" || !value[i].length) {
261
251
  throw new TypeError("seller-signup: category_focus[" + i + "] must be a non-empty string");
262
252
  }
263
- if (CONTROL_BYTE_RE.test(value[i]) || ZERO_WIDTH_RE.test(value[i])) {
253
+ if (textGuard.hasCodepointThreat(value[i], { singleLine: "reject", zeroWidth: "reject" })) {
264
254
  throw new TypeError("seller-signup: category_focus[" + i + "] contains control / zero-width bytes");
265
255
  }
266
256
  }
@@ -305,9 +295,7 @@ function _referencesJson(value) {
305
295
  if (encoded.length > MAX_REFERENCES_JSON_LEN) {
306
296
  throw new TypeError("seller-signup: references_json must be <= " + MAX_REFERENCES_JSON_LEN + " characters serialised");
307
297
  }
308
- if (CONTROL_BYTE_RE.test(encoded) || ZERO_WIDTH_RE.test(encoded)) {
309
- throw new TypeError("seller-signup: references_json contains control / zero-width bytes");
310
- }
298
+ textGuard.freeText(encoded, "seller-signup: references_json", { singleLine: "reject", zeroWidth: "reject" });
311
299
  return encoded;
312
300
  }
313
301
 
@@ -325,12 +313,10 @@ function _instructions(s) {
325
313
  if (s.length > MAX_INSTRUCTIONS_LEN) {
326
314
  throw new TypeError("seller-signup: instructions must be <= " + MAX_INSTRUCTIONS_LEN + " characters");
327
315
  }
328
- if (CONTROL_BYTE_RE.test(s.replace(/[\t\n\r]/g, ""))) {
316
+ if (textGuard.hasCodepointThreat(s)) {
329
317
  throw new TypeError("seller-signup: instructions contains control bytes");
330
318
  }
331
- if (ZERO_WIDTH_RE.test(s)) {
332
- throw new TypeError("seller-signup: instructions contains zero-width / direction-override bytes");
333
- }
319
+ textGuard.freeText(s, "seller-signup: instructions", { zeroWidth: "reject" });
334
320
  return s;
335
321
  }
336
322
 
@@ -341,12 +327,10 @@ function _rejectReason(s) {
341
327
  if (s.length > MAX_REJECT_REASON_LEN) {
342
328
  throw new TypeError("seller-signup: reason must be <= " + MAX_REJECT_REASON_LEN + " characters");
343
329
  }
344
- if (CONTROL_BYTE_RE.test(s.replace(/[\t\n\r]/g, ""))) {
330
+ if (textGuard.hasCodepointThreat(s)) {
345
331
  throw new TypeError("seller-signup: reason contains control bytes");
346
332
  }
347
- if (ZERO_WIDTH_RE.test(s)) {
348
- throw new TypeError("seller-signup: reason contains zero-width / direction-override bytes");
349
- }
333
+ textGuard.freeText(s, "seller-signup: reason", { zeroWidth: "reject" });
350
334
  return s;
351
335
  }
352
336
 
@@ -357,7 +341,7 @@ function _operatorId(s, label) {
357
341
  if (s.length > MAX_OPERATOR_ID_LEN) {
358
342
  throw new TypeError("seller-signup: " + label + " must be <= " + MAX_OPERATOR_ID_LEN + " characters");
359
343
  }
360
- if (CONTROL_BYTE_RE.test(s) || ZERO_WIDTH_RE.test(s)) {
344
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject", zeroWidth: "reject" })) {
361
345
  throw new TypeError("seller-signup: " + label + " contains control / zero-width bytes");
362
346
  }
363
347
  return s;
@@ -75,6 +75,7 @@
75
75
  */
76
76
 
77
77
  var b = require("./vendor/blamejs");
78
+ var textGuard = require("./text-guard");
78
79
 
79
80
  // ---- constants ----------------------------------------------------------
80
81
 
@@ -125,11 +126,6 @@ var PAGE_KEY_RE = /^[A-Za-z0-9][A-Za-z0-9:._\/-]{0,119}$/;
125
126
  var BADGE_SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
126
127
  var SEGMENT_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
127
128
 
128
- var CONTROL_BYTE_LINE_RE = /[\x00-\x1f\x7f]/;
129
- var CONTROL_BYTE_BLOCK_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/;
130
- var ZERO_WIDTH_RE = new RegExp(
131
- "[\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFEFF\\u061C]"
132
- );
133
129
 
134
130
  var ALLOWED_PATCH_COLUMNS = Object.freeze([
135
131
  "title",
@@ -176,12 +172,7 @@ function _title(s) {
176
172
  if (typeof s !== "string" || !s.length || s.length > MAX_TITLE_LEN) {
177
173
  throw new TypeError("sidebarWidgets: title must be a non-empty string <= " + MAX_TITLE_LEN + " chars");
178
174
  }
179
- if (CONTROL_BYTE_LINE_RE.test(s)) {
180
- throw new TypeError("sidebarWidgets: title must not contain control bytes (incl. CR/LF)");
181
- }
182
- if (ZERO_WIDTH_RE.test(s)) {
183
- throw new TypeError("sidebarWidgets: title must not contain zero-width / direction-override characters");
184
- }
175
+ textGuard.freeText(s, "sidebarWidgets: title", { singleLine: "reject", zeroWidth: "reject" });
185
176
  return s;
186
177
  }
187
178
 
@@ -260,10 +251,10 @@ function _line(s, label, maxLen) {
260
251
  if (typeof s !== "string" || !s.length || s.length > maxLen) {
261
252
  throw new TypeError("sidebarWidgets: " + label + " must be a non-empty string <= " + maxLen + " chars");
262
253
  }
263
- if (CONTROL_BYTE_LINE_RE.test(s)) {
254
+ if (textGuard.hasCodepointThreat(s, { singleLine: "reject" })) {
264
255
  throw new TypeError("sidebarWidgets: " + label + " must not contain control bytes (incl. CR/LF)");
265
256
  }
266
- if (ZERO_WIDTH_RE.test(s)) {
257
+ if (textGuard.hasCodepointThreat(s, { zeroWidth: "reject" })) {
267
258
  throw new TypeError("sidebarWidgets: " + label + " must not contain zero-width / direction-override characters");
268
259
  }
269
260
  return s;
@@ -273,10 +264,10 @@ function _block(s, label, maxLen) {
273
264
  if (typeof s !== "string" || !s.length || s.length > maxLen) {
274
265
  throw new TypeError("sidebarWidgets: " + label + " must be a non-empty string <= " + maxLen + " chars");
275
266
  }
276
- if (CONTROL_BYTE_BLOCK_RE.test(s)) {
267
+ if (textGuard.hasCodepointThreat(s)) {
277
268
  throw new TypeError("sidebarWidgets: " + label + " must not contain control bytes");
278
269
  }
279
- if (ZERO_WIDTH_RE.test(s)) {
270
+ if (textGuard.hasCodepointThreat(s, { zeroWidth: "reject" })) {
280
271
  throw new TypeError("sidebarWidgets: " + label + " must not contain zero-width / direction-override characters");
281
272
  }
282
273
  return s;