@paydock/client-sdk 1.145.0-beta → 1.147.0

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 (43) hide show
  1. package/README.md +129 -1
  2. package/bundles/index.cjs +746 -102
  3. package/bundles/index.cjs.d.ts +131 -14
  4. package/bundles/index.mjs +746 -103
  5. package/bundles/index.mjs.d.ts +131 -14
  6. package/bundles/types/api/api-base.d.ts +6 -0
  7. package/bundles/types/api/api-base.d.ts.map +1 -1
  8. package/bundles/types/api/api-charge-internal.d.ts +1 -5
  9. package/bundles/types/api/api-charge-internal.d.ts.map +1 -1
  10. package/bundles/types/canvas-3ds/canvas-3ds-event-map.d.ts +50 -0
  11. package/bundles/types/canvas-3ds/canvas-3ds-event-map.d.ts.map +1 -1
  12. package/bundles/types/canvas-3ds/canvas-3ds.d.ts +7 -5
  13. package/bundles/types/canvas-3ds/canvas-3ds.d.ts.map +1 -1
  14. package/bundles/types/canvas-3ds/index.d.ts +1 -1
  15. package/bundles/types/canvas-3ds/index.d.ts.map +1 -1
  16. package/bundles/types/canvas-3ds/services/gpayments-service.d.ts +117 -2
  17. package/bundles/types/canvas-3ds/services/gpayments-service.d.ts.map +1 -1
  18. package/bundles/types/canvas-3ds/services/standalone3ds-service.d.ts +6 -0
  19. package/bundles/types/canvas-3ds/services/standalone3ds-service.d.ts.map +1 -1
  20. package/bundles/types/components/iframe-event.d.ts +4 -3
  21. package/bundles/types/components/iframe-event.d.ts.map +1 -1
  22. package/bundles/types/components/iframe.d.ts +5 -0
  23. package/bundles/types/components/iframe.d.ts.map +1 -1
  24. package/bundles/types/components/param.d.ts +19 -0
  25. package/bundles/types/components/param.d.ts.map +1 -1
  26. package/bundles/types/index-cba.d.ts +1 -1
  27. package/bundles/types/index-cba.d.ts.map +1 -1
  28. package/bundles/types/index.d.ts +2 -2
  29. package/bundles/types/index.d.ts.map +1 -1
  30. package/bundles/types/widget/multi-widget.d.ts +19 -0
  31. package/bundles/types/widget/multi-widget.d.ts.map +1 -1
  32. package/bundles/widget.umd.js +746 -102
  33. package/bundles/widget.umd.js.d.ts +131 -14
  34. package/bundles/widget.umd.js.min.d.ts +131 -14
  35. package/bundles/widget.umd.min.js +1 -1
  36. package/docs/api-canvas3ds.md +10 -8
  37. package/docs/api-checkout-button.md +15 -0
  38. package/docs/api-ps-widget.md +15 -0
  39. package/docs/api-widget.md +15 -0
  40. package/docs/canvas3ds-examples.md +43 -1
  41. package/docs/widget-examples.md +41 -0
  42. package/package.json +15 -9
  43. package/slate.md +84 -1
@@ -1869,7 +1869,7 @@
1869
1869
  version: 'x-sdk-version',
1870
1870
  type: 'x-sdk-type'
1871
1871
  });
1872
- SDK._version = 'v1.145.0-beta';
1872
+ SDK._version = 'v1.147.0';
1873
1873
 
1874
1874
  var ACCESS_HEADER_NAME = {
1875
1875
  accessToken: 'x-access-token',
@@ -4725,6 +4725,15 @@
4725
4725
  this.env.setEnv(env, alias);
4726
4726
  return this;
4727
4727
  }
4728
+ /**
4729
+ * Origin (`scheme://host[:port]`) of the API this client talks to, for the current env/alias.
4730
+ * Used to validate the `origin` of postMessages the API itself sends to the page.
4731
+ */
4732
+ }, {
4733
+ key: "getApiOrigin",
4734
+ value: function getApiOrigin() {
4735
+ return ApiBase.toOrigin(this.env.getConf().url);
4736
+ }
4728
4737
  }, {
4729
4738
  key: "requestObservable",
4730
4739
  value: function requestObservable(method, url, requestBody) {
@@ -4937,6 +4946,18 @@
4937
4946
  environment: this.env.getEnv()
4938
4947
  };
4939
4948
  }
4949
+ }], [{
4950
+ key: "toOrigin",
4951
+ value: function toOrigin(url) {
4952
+ try {
4953
+ return new URL(url).origin;
4954
+ } catch (_a) {
4955
+ // Not a parsable URL: the returned string is not an origin and will never match a
4956
+ // MessageEvent.origin — surface the misconfiguration instead of failing silently.
4957
+ console.warn("[paydock/client-sdk] cannot derive an origin from configured URL \"".concat(url, "\""));
4958
+ return url.replace(/\/+$/, '');
4959
+ }
4960
+ }
4940
4961
  }]);
4941
4962
  }();
4942
4963
 
@@ -4997,7 +5018,6 @@
4997
5018
 
4998
5019
  var WALLET_CAPTURE_LINK = '/v1/charges/wallet/capture';
4999
5020
  var WALLET_CALLBACK_LINK = '/v1/charges/wallet/callback';
5000
- var STANDALONE_3DS_PROCESS_LINK = '/v1/charges/standalone-3ds/process';
5001
5021
  var STANDALONE_3DS_HANDLE_LINK = '/v1/charges/standalone-3ds/handle';
5002
5022
  var ApiChargeInternal = /*#__PURE__*/function () {
5003
5023
  function ApiChargeInternal(api) {
@@ -5014,11 +5034,6 @@
5014
5034
  value: function walletCallback(payload) {
5015
5035
  return this.api.getClientPromise('POST', WALLET_CALLBACK_LINK).send(payload);
5016
5036
  }
5017
- }, {
5018
- key: "standalone3dsProcess",
5019
- value: function standalone3dsProcess(payload) {
5020
- return this.api.getClientPromise('POST', STANDALONE_3DS_PROCESS_LINK).send(payload);
5021
- }
5022
5037
  }, {
5023
5038
  key: "standalone3dsHandle",
5024
5039
  value: function standalone3dsHandle() {
@@ -5157,6 +5172,10 @@
5157
5172
  _classCallCheck(this, IFrame);
5158
5173
  this.container = container;
5159
5174
  }
5175
+ /**
5176
+ * @param options.onLoad Called on every `load` of the iframe (initial document and each
5177
+ * subsequent navigation). Attached before `src` is set so a fast load is never missed.
5178
+ */
5160
5179
  return _createClass(IFrame, [{
5161
5180
  key: "load",
5162
5181
  value: function load(link) {
@@ -5165,6 +5184,9 @@
5165
5184
  if (!this.container.isExist() || this.isExist()) return;
5166
5185
  var iFrame = document.createElement('iframe');
5167
5186
  if (options.title) iFrame.title = options.title;
5187
+ if (options.onLoad) {
5188
+ iFrame.addEventListener('load', options.onLoad);
5189
+ }
5168
5190
  if (iframeClass) iFrame.classList.add(iframeClass);
5169
5191
  // Set additional attributes before src and DOM insertion so that
5170
5192
  // Permissions-Policy (e.g. allow="payment") is in place when the
@@ -5305,14 +5327,14 @@
5305
5327
  data = JSON.parse(event.data);
5306
5328
  } catch (error) {}
5307
5329
  if (!data) return;
5308
- _this.emit(data);
5330
+ _this.emit(data, event.origin);
5309
5331
  });
5310
5332
  }
5311
5333
  return _createClass(IFrameEvent, [{
5312
5334
  key: "emit",
5313
- value: function emit(data) {
5335
+ value: function emit(data, origin) {
5314
5336
  for (var key in this.listeners) {
5315
- if (this.listeners[key].event === data.event && data.widget_id === this.listeners[key].widget_id) this.listeners[key].listener.apply(this, [data]);
5337
+ if (this.listeners[key].event === data.event && data.widget_id === this.listeners[key].widget_id) this.listeners[key].listener.apply(this, [data, origin]);
5316
5338
  }
5317
5339
  }
5318
5340
  }, {
@@ -5385,6 +5407,20 @@
5385
5407
  DECOUPLED: 'chargeAuthDecoupled',
5386
5408
  /** Challenge required — issuer demands user interaction. Payload: `Canvas3dsAuthPayload`. */
5387
5409
  CHALLENGE: 'chargeAuthChallenge',
5410
+ /**
5411
+ * The challenge iframe fired its FIRST `load` after `chargeAuthChallenge` (the ACS page has painted),
5412
+ * or the `CHALLENGE_LOADED_FALLBACK_MS` safety fallback elapsed without one. Emitted exactly once per
5413
+ * challenge; never emitted for a decoupled challenge (no challenge iframe). Payload: `Canvas3dsChallengeLoadedPayload`.
5414
+ */
5415
+ CHALLENGE_LOADED: 'chargeAuthChallengeLoaded',
5416
+ /**
5417
+ * The issuer delivered the final authentication result to the 3DS Server (the shopper finished the
5418
+ * challenge, or approved a decoupled authentication) and the SDK is now obtaining the outcome. Emitted at
5419
+ * most once per authentication, always before the terminal event. Detected through the `secondary_url`
5420
+ * result monitor (`source: 'poll'`) or, when the callback message arrives first, right before the outcome
5421
+ * it carries (`source: 'callback'`). Payload: `Canvas3dsChallengeCompletedPayload`.
5422
+ */
5423
+ CHALLENGE_COMPLETED: 'chargeAuthChallengeCompleted',
5388
5424
  /** Informational signal emitted by the GPayments flow. Internal — not part of the public typed surface. */
5389
5425
  INFO: 'chargeAuthInfo',
5390
5426
  /** Error during the flow (network, parsing, etc.). Payload: `Canvas3dsErrorPayload`. */
@@ -5396,13 +5432,56 @@
5396
5432
  * backwards-compatible internal usage.
5397
5433
  */
5398
5434
  var CANVAS_3DS_EVENT = GPAYMENTS_EVENT;
5435
+ /**
5436
+ * Upper bound on how long `chargeAuthChallengeLoaded` waits for the challenge iframe's first `load`.
5437
+ * When it elapses the event is emitted with `reason: 'timeout'` so a merchant loader is never held
5438
+ * forever; the real `load` arriving afterwards is the paint and is simply ignored.
5439
+ */
5440
+ var CHALLENGE_LOADED_FALLBACK_MS = 2500;
5441
+ /**
5442
+ * Interval of the `secondary_url` (GPayments `resultMonUrl`) poll while an ACS challenge is on screen.
5443
+ * The monitor flips to `AuthResultReady` when the issuer's RReq reaches the 3DS Server — before the ACS has
5444
+ * even returned its final page to the browser — so this poll is what makes `chargeAuthChallengeCompleted`
5445
+ * land before the shopper sees any post-submit page. GPayments recommends 2 s and leaves the interval to the
5446
+ * requestor; 1 s matches the cadence of GPayments' own monitoring frame.
5447
+ */
5448
+ var CHALLENGE_RESULT_POLL_INTERVAL_MS = 1000;
5449
+ /**
5450
+ * Interval of the `secondary_url` poll for a decoupled challenge (shopper approves out-of-band, possibly
5451
+ * minutes later; nothing to cover on screen) — the GPayments-recommended 2 s.
5452
+ */
5453
+ var DECOUPLED_RESULT_POLL_INTERVAL_MS = 2000;
5454
+ /** The result-monitor request failed at transport level (network, abort, timeout) — retried, not fatal. */
5455
+ var ResultMonitorTransportError = /*#__PURE__*/function (_Error) {
5456
+ function ResultMonitorTransportError() {
5457
+ var _this;
5458
+ _classCallCheck(this, ResultMonitorTransportError);
5459
+ _this = _callSuper(this, ResultMonitorTransportError, ['Standalone 3DS result monitor request failed']);
5460
+ _this.name = 'ResultMonitorTransportError';
5461
+ return _this;
5462
+ }
5463
+ _inherits(ResultMonitorTransportError, _Error);
5464
+ return _createClass(ResultMonitorTransportError);
5465
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
5399
5466
  var GPaymentsService = /*#__PURE__*/function () {
5400
5467
  function GPaymentsService(container, api, eventEmitter) {
5468
+ var trustedOrigins = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
5401
5469
  _classCallCheck(this, GPaymentsService);
5402
5470
  this.container = container;
5403
5471
  this.api = api;
5404
5472
  this.eventEmitter = eventEmitter;
5473
+ this.trustedOrigins = trustedOrigins;
5405
5474
  this.resultRead = false;
5475
+ /** `chargeAuthChallengeLoaded` already emitted for the current challenge (by `load` or by the fallback). */
5476
+ this.challengeLoadedEmitted = false;
5477
+ /** `chargeAuthChallengeCompleted` already emitted for the current authentication (poll or callback). */
5478
+ this.challengeCompletedEmitted = false;
5479
+ /** Set once a terminal event was emitted: no lifecycle event may follow (reset when a new challenge starts). */
5480
+ this.challengeLifecycleClosed = false;
5481
+ this.challengeLoadedTimer = null;
5482
+ this.resultPollTimer = null;
5483
+ /** One-shot guard for the `chargeAuth` leg — the callback message may be delivered more than once. */
5484
+ this.authHandled = false;
5406
5485
  this.iFrameEvent = new IFrameEvent(window);
5407
5486
  }
5408
5487
  return _createClass(GPaymentsService, [{
@@ -5422,6 +5501,7 @@
5422
5501
  key: "initializeIFrames",
5423
5502
  value: function initializeIFrames(initializationUrl, secondaryUrl, title) {
5424
5503
  var hideAuthorization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
5504
+ var onLoad = arguments.length > 4 ? arguments[4] : undefined;
5425
5505
  var container = this.container.getElement();
5426
5506
  if (!container) {
5427
5507
  return;
@@ -5432,7 +5512,8 @@
5432
5512
  this.browserAndChallengeContainer = new Container('#paydock_authorization_iframe');
5433
5513
  this.iFrameAuthorization = new IFrame(this.browserAndChallengeContainer);
5434
5514
  this.iFrameAuthorization.load(initializationUrl, {
5435
- title: title
5515
+ title: title,
5516
+ onLoad: onLoad
5436
5517
  });
5437
5518
  if (secondaryUrl) {
5438
5519
  var divSecondaryURL = document.createElement('div');
@@ -5466,25 +5547,192 @@
5466
5547
  }, {
5467
5548
  key: "setupIFrameEvents",
5468
5549
  value: function setupIFrameEvents(widgetId) {
5469
- var _this = this;
5470
- this.iFrameEvent.on(EVENT$4.CHARGE_AUTH, widgetId, function (data) {
5550
+ var _this2 = this;
5551
+ this.iFrameEvent.on(EVENT$4.CHARGE_AUTH, widgetId, function (data, origin) {
5471
5552
  if (data.status === IFRAME_STATUS.SKIPPED || data.status === IFRAME_STATUS.FINISHED) {
5553
+ // this channel is spoofable — any frame that knows the charge_3ds_id can post to it.
5554
+ // A message from an unknown sender must never terminate a live authentication: ignore it.
5555
+ if (!_this2.isTrustedOrigin(origin)) {
5556
+ return;
5557
+ }
5558
+ // one-shot: the callback message can be delivered more than once (it is posted to both
5559
+ // `parent` and `top`) — a duplicate must not re-emit events or duplicate challenge iframes
5560
+ if (_this2.authHandled) {
5561
+ return;
5562
+ }
5563
+ _this2.authHandled = true;
5472
5564
  if (data.info) {
5473
- _this.eventEmitter.emit(GPAYMENTS_EVENT.INFO, {
5565
+ _this2.eventEmitter.emit(GPAYMENTS_EVENT.INFO, {
5474
5566
  info: data.info
5475
5567
  });
5476
5568
  }
5477
- _this.performAuthentication(data);
5569
+ _this2.removeIframes();
5570
+ if (typeof data.process_status === 'string') {
5571
+ // the API already ran the authentication inside the callback: no /process call needed
5572
+ _this2.handleAuthenticationOutcome({
5573
+ status: data.process_status,
5574
+ result: data.result,
5575
+ error: data.error
5576
+ }, data.charge_3ds_id);
5577
+ } else {
5578
+ // The API always runs the authentication inside the callback (PAYRAC-2480). A trusted
5579
+ // message without the outcome means an outdated API — fail, never verify via /process.
5580
+ _this2.finishChallengeLifecycle();
5581
+ _this2.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this2.parseError({
5582
+ message: 'Standalone 3DS authentication outcome missing from the callback message'
5583
+ }, data.charge_3ds_id));
5584
+ }
5478
5585
  } else if (data.status === IFRAME_STATUS.TIMEOUT || data.status === IFRAME_STATUS.INVALID) {
5479
- _this.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this.parseHandleResponse({
5586
+ _this2.finishChallengeLifecycle();
5587
+ _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this2.parseHandleResponse({
5480
5588
  status: data.status
5481
5589
  }, data.charge_3ds_id));
5482
5590
  }
5483
5591
  });
5484
- this.iFrameEvent.on(EVENT$4.CHARGE_AUTH_SUCCESS, widgetId, function (data) {
5485
- _this.processResult(data.charge_3ds_id);
5592
+ this.iFrameEvent.on(EVENT$4.CHARGE_AUTH_SUCCESS, widgetId, function (data, origin) {
5593
+ // the callback iframe reached Paydock with `AuthResultReady`: the issuer has answered. Announce it
5594
+ // before the outcome so merchants always see completed → terminal, whichever transport won.
5595
+ _this2.emitChallengeCompleted(data.charge_3ds_id, 'callback');
5596
+ if (_this2.hasChainedOutcome(data, origin)) {
5597
+ // the API already fetched the challenge result inside the callback: no GET /handle needed
5598
+ _this2.handleResultOutcome({
5599
+ status: data.process_status,
5600
+ result: data.result,
5601
+ error: data.error
5602
+ }, data.charge_3ds_id);
5603
+ } else {
5604
+ _this2.processResult(data.charge_3ds_id);
5605
+ }
5606
+ });
5607
+ }
5608
+ /**
5609
+ * A message carries a processed outcome only when it has `process_status` AND comes from a trusted
5610
+ * origin. Used by the result leg: an untrusted `process_status` is never acted upon — the SDK falls
5611
+ * back to `GET /handle` (still needed for decoupled challenges / polling). The authentication leg
5612
+ * ignores untrusted senders outright, before this check.
5613
+ */
5614
+ }, {
5615
+ key: "hasChainedOutcome",
5616
+ value: function hasChainedOutcome(data, origin) {
5617
+ return typeof data.process_status === 'string' && this.isTrustedOrigin(origin);
5618
+ }
5619
+ }, {
5620
+ key: "isTrustedOrigin",
5621
+ value: function isTrustedOrigin(origin) {
5622
+ // 'null' is the serialized opaque origin (e.g. a sandboxed iframe) — never trust it, even if a
5623
+ // misconfigured env URL were ever to put the literal string 'null' into the trusted list
5624
+ return typeof origin === 'string' && origin !== 'null' && this.trustedOrigins.includes(origin);
5625
+ }
5626
+ }, {
5627
+ key: "removeIframes",
5628
+ value: function removeIframes() {
5629
+ var _a, _b;
5630
+ this.clearChallengeLoadedTimer();
5631
+ (_a = this.iFrameAuthorization) === null || _a === void 0 ? void 0 : _a.remove();
5632
+ (_b = this.iFrameSecondaryUrl) === null || _b === void 0 ? void 0 : _b.remove();
5633
+ }
5634
+ }, {
5635
+ key: "clearChallengeLoadedTimer",
5636
+ value: function clearChallengeLoadedTimer() {
5637
+ if (this.challengeLoadedTimer !== null) {
5638
+ clearTimeout(this.challengeLoadedTimer);
5639
+ this.challengeLoadedTimer = null;
5640
+ }
5641
+ }
5642
+ /**
5643
+ * Challenge iframe lifecycle (`chargeAuthChallengeLoaded`).
5644
+ *
5645
+ * The challenge iframe is cross-origin, but its `load` event still fires when the ACS page finishes loading:
5646
+ * the first one means the page painted (merchants can drop their loader). A fallback timer
5647
+ * (`armChallengeLoadedFallback`) guarantees `chargeAuthChallengeLoaded` within `CHALLENGE_LOADED_FALLBACK_MS`
5648
+ * even if no `load` ever fires; a late paint after that is simply ignored. Later `load`s are NOT a usable
5649
+ * signal for "the shopper submitted": the post-submit hops are HTTP redirects and self-submitting pages whose
5650
+ * loads abort, and the final callback page posts its message before its own `load` — so the post-submit
5651
+ * moment is `chargeAuthChallengeCompleted`, driven by the `secondary_url` result monitor instead.
5652
+ *
5653
+ * Nothing is emitted once the flow reached a terminal outcome (`finishChallengeLifecycle`), and a
5654
+ * decoupled challenge (no challenge iframe) never emits `chargeAuthChallengeLoaded`.
5655
+ *
5656
+ * Resets the per-challenge state and returns the `load` handler to attach to the challenge iframe.
5657
+ */
5658
+ }, {
5659
+ key: "startChallengeLifecycle",
5660
+ value: function startChallengeLifecycle(charge3dsId) {
5661
+ var _this3 = this;
5662
+ this.clearChallengeLoadedTimer();
5663
+ this.challengeLoadedEmitted = false;
5664
+ this.challengeCompletedEmitted = false;
5665
+ this.challengeLifecycleClosed = false;
5666
+ return function () {
5667
+ var _a;
5668
+ if (_this3.challengeLifecycleClosed || _this3.challengeLoadedEmitted || !((_a = _this3.iFrameAuthorization) === null || _a === void 0 ? void 0 : _a.isExist())) {
5669
+ return;
5670
+ }
5671
+ _this3.clearChallengeLoadedTimer();
5672
+ _this3.emitChallengeLoaded(charge3dsId, 'load');
5673
+ };
5674
+ }
5675
+ /**
5676
+ * Arms the `chargeAuthChallengeLoaded` fallback — only when a challenge iframe actually exists (the
5677
+ * container may be gone, or `IFrame.load` may have no-op'd on an already-present iframe).
5678
+ */
5679
+ }, {
5680
+ key: "armChallengeLoadedFallback",
5681
+ value: function armChallengeLoadedFallback(charge3dsId) {
5682
+ var _this4 = this;
5683
+ var _a;
5684
+ if (!((_a = this.iFrameAuthorization) === null || _a === void 0 ? void 0 : _a.isExist())) {
5685
+ return;
5686
+ }
5687
+ this.challengeLoadedTimer = setTimeout(function () {
5688
+ _this4.challengeLoadedTimer = null;
5689
+ if (_this4.challengeLifecycleClosed || _this4.challengeLoadedEmitted) {
5690
+ return;
5691
+ }
5692
+ _this4.emitChallengeLoaded(charge3dsId, 'timeout');
5693
+ }, CHALLENGE_LOADED_FALLBACK_MS);
5694
+ }
5695
+ }, {
5696
+ key: "emitChallengeLoaded",
5697
+ value: function emitChallengeLoaded(charge3dsId, reason) {
5698
+ this.challengeLoadedEmitted = true;
5699
+ this.eventEmitter.emit(GPAYMENTS_EVENT.CHALLENGE_LOADED, {
5700
+ charge_3ds_id: charge3dsId,
5701
+ reason: reason
5702
+ });
5703
+ }
5704
+ /**
5705
+ * `chargeAuthChallengeCompleted` — once per authentication, never after a terminal event. Idempotent so the
5706
+ * poll and the callback message can both call it: the first transport to notice the issuer's result wins.
5707
+ */
5708
+ }, {
5709
+ key: "emitChallengeCompleted",
5710
+ value: function emitChallengeCompleted(charge3dsId, source) {
5711
+ if (this.challengeLifecycleClosed || this.challengeCompletedEmitted) {
5712
+ return;
5713
+ }
5714
+ this.challengeCompletedEmitted = true;
5715
+ this.eventEmitter.emit(GPAYMENTS_EVENT.CHALLENGE_COMPLETED, {
5716
+ charge_3ds_id: charge3dsId,
5717
+ source: source
5486
5718
  });
5487
5719
  }
5720
+ /** Call before emitting any terminal event: no lifecycle event may follow it, and the result poll stops. */
5721
+ }, {
5722
+ key: "finishChallengeLifecycle",
5723
+ value: function finishChallengeLifecycle() {
5724
+ this.clearChallengeLoadedTimer();
5725
+ this.stopResultPolling();
5726
+ this.challengeLifecycleClosed = true;
5727
+ }
5728
+ }, {
5729
+ key: "stopResultPolling",
5730
+ value: function stopResultPolling() {
5731
+ if (this.resultPollTimer !== null) {
5732
+ clearTimeout(this.resultPollTimer);
5733
+ this.resultPollTimer = null;
5734
+ }
5735
+ }
5488
5736
  }, {
5489
5737
  key: "parseResultData",
5490
5738
  value: function parseResultData(_ref2, charge3dsId) {
@@ -5518,24 +5766,49 @@
5518
5766
  }, {
5519
5767
  key: "processResult",
5520
5768
  value: function processResult(charge3dsId) {
5521
- var _this2 = this;
5769
+ var _this5 = this;
5522
5770
  if (this.resultRead) {
5523
5771
  return;
5524
5772
  }
5525
5773
  this.resultRead = true;
5774
+ this.finishChallengeLifecycle();
5526
5775
  this.api.charge().standalone3dsHandle().then(function (result) {
5527
5776
  var _a;
5528
- _this2.iFrameAuthorization.remove();
5529
- (_a = _this2.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.remove();
5777
+ _this5.iFrameAuthorization.remove();
5778
+ (_a = _this5.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.remove();
5530
5779
  if (result.status === PROCESS_STANDALONE_3DS_STATUS.SUCCESS) {
5531
- _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this2.parseResultData(result, charge3dsId));
5780
+ _this5.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this5.parseResultData(result, charge3dsId));
5532
5781
  } else {
5533
- _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this2.parseResultData(result, charge3dsId));
5782
+ _this5.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this5.parseResultData(result, charge3dsId));
5534
5783
  }
5535
5784
  }, function (err) {
5536
- _this2.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this2.parseError(err, charge3dsId));
5785
+ _this5.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this5.parseError(err, charge3dsId));
5537
5786
  });
5538
5787
  }
5788
+ /** Final (post-challenge) outcome delivered by the API through the callback message. */
5789
+ }, {
5790
+ key: "handleResultOutcome",
5791
+ value: function handleResultOutcome(_ref4, charge3dsId) {
5792
+ var status = _ref4.status,
5793
+ error = _ref4.error;
5794
+ if (this.resultRead) {
5795
+ return;
5796
+ }
5797
+ this.resultRead = true;
5798
+ this.finishChallengeLifecycle();
5799
+ this.removeIframes();
5800
+ if (status === PROCESS_STANDALONE_3DS_STATUS.SUCCESS) {
5801
+ this.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, this.parseResultData({
5802
+ status: status
5803
+ }, charge3dsId));
5804
+ } else if (status === PROCESS_STANDALONE_3DS_STATUS.ERROR) {
5805
+ this.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, this.parseError(error, charge3dsId));
5806
+ } else {
5807
+ this.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, this.parseResultData({
5808
+ status: status
5809
+ }, charge3dsId));
5810
+ }
5811
+ }
5539
5812
  }, {
5540
5813
  key: "externalAPI",
5541
5814
  value: function externalAPI(method, url) {
@@ -5549,60 +5822,106 @@
5549
5822
  reject(error);
5550
5823
  }
5551
5824
  };
5825
+ // without these a failed request left the promise pending forever and the poll silently dead
5826
+ var fail = function fail() {
5827
+ return reject(new ResultMonitorTransportError());
5828
+ };
5829
+ request.onerror = fail;
5830
+ request.onabort = fail;
5831
+ request.ontimeout = fail;
5552
5832
  request.send();
5553
5833
  });
5554
5834
  }
5835
+ /**
5836
+ * Polls the GPayments result monitor (`secondary_url`) until `AuthResultReady`. It is the primary source of
5837
+ * `chargeAuthChallengeCompleted` (the monitor flips as soon as the issuer's RReq reaches the 3DS Server) and
5838
+ * the fallback transport for the outcome itself (`GET /handle`) when the callback message never arrives —
5839
+ * the only transport for decoupled challenges. Stops once an outcome was obtained or the lifecycle closed.
5840
+ * Transport failures are retried on the same cadence; an unparsable body or an unknown event is fatal.
5841
+ */
5555
5842
  }, {
5556
5843
  key: "doPolling",
5557
- value: function doPolling(url, charge3dsId) {
5558
- var _this3 = this;
5844
+ value: function doPolling(url, charge3dsId, intervalMs) {
5845
+ var _this6 = this;
5846
+ this.stopResultPolling();
5847
+ if (this.resultRead || this.challengeLifecycleClosed) {
5848
+ return;
5849
+ }
5850
+ var schedule = function schedule() {
5851
+ _this6.resultPollTimer = setTimeout(function () {
5852
+ _this6.resultPollTimer = null;
5853
+ _this6.doPolling(url, charge3dsId, intervalMs);
5854
+ }, intervalMs);
5855
+ };
5559
5856
  this.externalAPI('GET', url).then(function (data) {
5857
+ if (_this6.resultRead || _this6.challengeLifecycleClosed) {
5858
+ return;
5859
+ }
5560
5860
  if (!data.event || data.event === 'AuthResultNotReady') {
5561
- setTimeout(function () {
5562
- _this3.doPolling(url, charge3dsId);
5563
- }, 2000);
5861
+ schedule();
5564
5862
  } else if (data.event === 'AuthResultReady') {
5565
- _this3.processResult(charge3dsId);
5863
+ _this6.emitChallengeCompleted(charge3dsId, 'poll');
5864
+ _this6.processResult(charge3dsId);
5566
5865
  } else {
5567
5866
  throw new Error('Event not supported');
5568
5867
  }
5569
5868
  })["catch"](function (err) {
5570
- return _this3.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this3.parseError(err, charge3dsId));
5869
+ if (err instanceof ResultMonitorTransportError) {
5870
+ if (!_this6.resultRead && !_this6.challengeLifecycleClosed) {
5871
+ schedule();
5872
+ }
5873
+ return;
5874
+ }
5875
+ _this6.finishChallengeLifecycle();
5876
+ _this6.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this6.parseError(err, charge3dsId));
5571
5877
  });
5572
5878
  }
5879
+ /**
5880
+ * Branches on the authentication outcome delivered by the API through the callback message
5881
+ * (`process_status` → `status`; same shape as the `/process` response body).
5882
+ */
5573
5883
  }, {
5574
- key: "performAuthentication",
5575
- value: function performAuthentication(_ref4) {
5576
- var _this4 = this;
5577
- var charge_3ds_id = _ref4.charge_3ds_id;
5578
- var _a;
5579
- this.iFrameAuthorization.remove();
5580
- (_a = this.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.remove();
5581
- this.api.charge().standalone3dsProcess({
5582
- charge_3ds_id: charge_3ds_id
5583
- }).then(function (authenticationResult) {
5584
- var _a, _b;
5585
- if (authenticationResult.status === AUTHENTICATION_STATUS.SUCCESS) {
5586
- _this4.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
5587
- } else if (authenticationResult.status === AUTHENTICATION_STATUS.PENDING) {
5588
- if ((_a = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _a === void 0 ? void 0 : _a.challenge) {
5589
- _this4.eventEmitter.emit(GPAYMENTS_EVENT.CHALLENGE, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
5590
- _this4.initializeIFrames(authenticationResult.result.challenge_url, undefined, 'Authentication Challenge', false);
5591
- if (authenticationResult.result.secondary_url) {
5592
- _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
5593
- }
5594
- } else if ((_b = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _b === void 0 ? void 0 : _b.decoupled_challenge) {
5595
- _this4.eventEmitter.emit(GPAYMENTS_EVENT.DECOUPLED, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
5596
- if (authenticationResult.result.secondary_url) {
5597
- _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
5598
- }
5884
+ key: "handleAuthenticationOutcome",
5885
+ value: function handleAuthenticationOutcome(authenticationResult, charge_3ds_id) {
5886
+ var _a, _b, _c;
5887
+ if (authenticationResult.status !== AUTHENTICATION_STATUS.PENDING) {
5888
+ // terminal outcome — a later `chargeAuthSuccess` message or poll must not emit a second result
5889
+ this.resultRead = true;
5890
+ }
5891
+ if (authenticationResult.status === AUTHENTICATION_STATUS.SUCCESS) {
5892
+ this.finishChallengeLifecycle();
5893
+ this.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, this.parseHandleResponse(authenticationResult, charge_3ds_id));
5894
+ } else if (authenticationResult.status === AUTHENTICATION_STATUS.PENDING) {
5895
+ if ((_a = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _a === void 0 ? void 0 : _a.challenge) {
5896
+ this.eventEmitter.emit(GPAYMENTS_EVENT.CHALLENGE, this.parseHandleResponse(authenticationResult, charge_3ds_id));
5897
+ var onChallengeLoad = this.startChallengeLifecycle(charge_3ds_id);
5898
+ this.initializeIFrames(authenticationResult.result.challenge_url, undefined, 'Authentication Challenge', false, onChallengeLoad);
5899
+ this.armChallengeLoadedFallback(charge_3ds_id);
5900
+ if (authenticationResult.result.secondary_url) {
5901
+ this.doPolling(authenticationResult.result.secondary_url, charge_3ds_id, CHALLENGE_RESULT_POLL_INTERVAL_MS);
5902
+ }
5903
+ } else if ((_b = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _b === void 0 ? void 0 : _b.decoupled_challenge) {
5904
+ this.challengeCompletedEmitted = false;
5905
+ this.challengeLifecycleClosed = false;
5906
+ this.eventEmitter.emit(GPAYMENTS_EVENT.DECOUPLED, this.parseHandleResponse(authenticationResult, charge_3ds_id));
5907
+ if (authenticationResult.result.secondary_url) {
5908
+ this.doPolling(authenticationResult.result.secondary_url, charge_3ds_id, DECOUPLED_RESULT_POLL_INTERVAL_MS);
5599
5909
  }
5600
5910
  } else {
5601
- return _this4.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
5602
- }
5603
- }, function (err) {
5604
- _this4.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this4.parseError(err, charge_3ds_id));
5605
- });
5911
+ // pending but nothing to run (no challenge delivered) — fail rather than hang silently
5912
+ // with the iframes already removed and no further message ever coming
5913
+ this.resultRead = true;
5914
+ this.finishChallengeLifecycle();
5915
+ this.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, this.parseHandleResponse(authenticationResult, charge_3ds_id));
5916
+ }
5917
+ } else if (authenticationResult.status === AUTHENTICATION_STATUS.ERROR) {
5918
+ // the API rejected the authentication, or could not run it inside the callback
5919
+ this.finishChallengeLifecycle();
5920
+ this.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, this.parseError((_c = authenticationResult.error) !== null && _c !== void 0 ? _c : authenticationResult, charge_3ds_id));
5921
+ } else {
5922
+ this.finishChallengeLifecycle();
5923
+ this.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, this.parseHandleResponse(authenticationResult, charge_3ds_id));
5924
+ }
5606
5925
  }
5607
5926
  }]);
5608
5927
  }();
@@ -5629,10 +5948,27 @@
5629
5948
  api.setEnv(this.env, this.alias);
5630
5949
  switch (tokenData.service_type) {
5631
5950
  case STANDALONE_3DS_GATEWAYS.GPAYMENTS:
5632
- new GPaymentsService(this.container, api, this.eventEmitter).load(tokenData, options.title);
5951
+ new GPaymentsService(this.container, api, this.eventEmitter, this.getTrustedMessageOrigins(api)).load(tokenData, options.title);
5633
5952
  break;
5634
5953
  }
5635
5954
  }
5955
+ /**
5956
+ * Origins allowed to deliver a processed 3DS outcome to the page via postMessage: the Paydock API
5957
+ * (inline callback page) and the Paydock widget (remote-app landing page), for the current env/alias.
5958
+ */
5959
+ }, {
5960
+ key: "getTrustedMessageOrigins",
5961
+ value: function getTrustedMessageOrigins(api) {
5962
+ var origins = [api.getApiOrigin()];
5963
+ try {
5964
+ var widgetEnv = new Env(WIDGET_URL, this.env);
5965
+ widgetEnv.setEnv(this.env, this.alias);
5966
+ origins.push(ApiBase.toOrigin(widgetEnv.getConf().url));
5967
+ } catch (_a) {
5968
+ // widget origin unknown for this env — the API origin is enough
5969
+ }
5970
+ return origins;
5971
+ }
5636
5972
  }, {
5637
5973
  key: "setEnv",
5638
5974
  value: function setEnv(env, alias) {
@@ -5801,11 +6137,13 @@
5801
6137
  * @const STANDALONE_3DS_EVENT
5802
6138
  *
5803
6139
  * @type {object}
5804
- * @param {string} CHARGE_AUTH_SUCCESS=chargeAuthSuccess
5805
- * @param {string} CHARGE_AUTH_REJECT=chargeAuthReject
5806
- * @param {string} CHARGE_AUTH_DECOUPLED=chargeAuthDecoupled
5807
- * @param {string} CHARGE_AUTH_CHALLENGE=chargeAuthChallenge
5808
- * @param {string} CHARGE_AUTH_INFO=chargeAuthInfo
6140
+ * @param {string} AUTH_SUCCESS=chargeAuthSuccess
6141
+ * @param {string} AUTH_ERROR=chargeAuthReject
6142
+ * @param {string} DECOUPLED=chargeAuthDecoupled
6143
+ * @param {string} CHALLENGE=chargeAuthChallenge
6144
+ * @param {string} CHALLENGE_LOADED=chargeAuthChallengeLoaded - challenge iframe painted (first `load`, or 2.5 s fallback); reveal your challenge UI here
6145
+ * @param {string} CHALLENGE_COMPLETED=chargeAuthChallengeCompleted - the shopper finished the challenge (issuer result delivered to the 3DS Server); cover the challenge iframe with your own loader until the terminal event
6146
+ * @param {string} INFO=chargeAuthInfo
5809
6147
  * @param {string} ERROR=error
5810
6148
  */
5811
6149
  /**
@@ -6187,6 +6525,24 @@
6187
6525
  EFTPOS_WHITE: 'eftpos_white',
6188
6526
  UNIONPAY: 'unionpay'
6189
6527
  };
6528
+ /**
6529
+ * Card schemes the widget is able to resolve from a card number, and therefore the only values
6530
+ * `setAllowedCardSchemes` accepts. This is a separate vocabulary from SUPPORTED_CARD_TYPES, which drives the
6531
+ * card icons: it omits the icon-only variants `visa_white` / `eftpos_white`, and the `laser` / `maestro`
6532
+ * identifiers the widget can never resolve — allowing those would be configuration that can never match.
6533
+ */
6534
+ var CARD_SCHEME = {
6535
+ AMEX: 'amex',
6536
+ AUSBC: 'ausbc',
6537
+ DINERS: 'diners',
6538
+ DISCOVER: 'discover',
6539
+ EFTPOS: 'eftpos',
6540
+ JAPCB: 'japcb',
6541
+ MASTERCARD: 'mastercard',
6542
+ SOLO: 'solo',
6543
+ UNIONPAY: 'unionpay',
6544
+ VISA: 'visa'
6545
+ };
6190
6546
  var SUPPORTED_CHECKOUT_META_COLLECTION = [].concat([
6191
6547
  // Paypal
6192
6548
  'brand_name', 'cart_border_color', 'reference', 'email', 'hdr_img', 'logo_img', 'pay_flow_color', 'first_name', 'last_name', 'address_line', 'address_line2', 'address_city', 'address_state', 'address_postcode', 'address_country', 'phone', 'hide_shipping_address'], [
@@ -8371,7 +8727,7 @@
8371
8727
  }]);
8372
8728
  }(WalletService);
8373
8729
 
8374
- /*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */
8730
+ /*! @license DOMPurify 3.4.13 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.13/LICENSE */
8375
8731
 
8376
8732
  var purify_cjs;
8377
8733
  var hasRequiredPurify_cjs;
@@ -8691,7 +9047,7 @@
8691
9047
  const text = freeze(['#text']);
8692
9048
 
8693
9049
  const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'command', 'commandfor', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns']);
8694
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
9050
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dominant-baseline', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-orientation', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
8695
9051
  const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
8696
9052
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
8697
9053
 
@@ -8804,7 +9160,7 @@
8804
9160
  function createDOMPurify() {
8805
9161
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
8806
9162
  const DOMPurify = root => createDOMPurify(root);
8807
- DOMPurify.version = '3.4.11';
9163
+ DOMPurify.version = '3.4.13';
8808
9164
  DOMPurify.removed = [];
8809
9165
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
8810
9166
  // Not running in a browser, provide a factory function
@@ -8835,6 +9191,7 @@
8835
9191
  const getAttributes = lookupGetter(ElementPrototype, 'attributes');
8836
9192
  const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
8837
9193
  const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
9194
+ const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, 'ownerDocument') : null;
8838
9195
  // As per issue #47, the web-components registry is inherited by a
8839
9196
  // new document created via createHTMLDocument. As per the spec
8840
9197
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -9486,6 +9843,13 @@
9486
9843
  * @param root the in-place root to empty
9487
9844
  */
9488
9845
  const _neutralizeRoot = function _neutralizeRoot(root) {
9846
+ /* Strip every disallowed attribute (on* handlers included) off the whole
9847
+ subtree BEFORE detaching anything. Detaching first would hand back
9848
+ handler-bearing originals (e.g. an already-loading `<img onerror>`)
9849
+ whose queued resource event still fires in page scope after we throw.
9850
+ Clobber-safe reads; a doomed clobbered node's own attributes are
9851
+ irrelevant while its non-clobbered descendants are reached and scrubbed. */
9852
+ _neutralizeSubtree(root);
9489
9853
  const childNodes = getChildNodes(root);
9490
9854
  if (childNodes) {
9491
9855
  const snapshot = [];
@@ -9613,6 +9977,82 @@
9613
9977
  }
9614
9978
  }
9615
9979
  };
9980
+ /**
9981
+ * _neutralizePatchLinkage
9982
+ *
9983
+ * IN_PLACE entry pre-pass (declarative-partial-updates / streaming
9984
+ * hardening, https://github.com/WICG/declarative-partial-updates).
9985
+ *
9986
+ * The main walk strips patch linkage (`for`/`patchsrc`) and removes range
9987
+ * markers (PIs / markup comments) node-by-node, in document order, AS it
9988
+ * reaches each node. On a live in-place root that leaves a window: from the
9989
+ * moment the root is connected until the walk arrives at a given node, that
9990
+ * node's linkage is live. A patch applied on connection/stream can fire as
9991
+ * a microtask during the walk and inject or teleport an unsanitized DOM
9992
+ * range into a region the iterator has already passed and will not revisit,
9993
+ * so the post-return "tree is sanitized" contract is violated. Sweep the
9994
+ * whole tree once up front and sever every linkage before the walk begins,
9995
+ * closing that window.
9996
+ *
9997
+ * This CANNOT undo a patch that already fired before sanitize ran — that is
9998
+ * the irreducible "do not IN_PLACE a live-connected attacker tree" caveat —
9999
+ * but it closes everything from sanitize-start onward. Gated on SAFE_FOR_XML
10000
+ * to group with the rest of the declarative-partial-updates handling and
10001
+ * stay overridable, consistent with the codebase.
10002
+ *
10003
+ * Clobber-safe traversal (cached childNodes getter); per-node try/catch so a
10004
+ * clobbered root cannot defeat the sweep of its non-clobbered descendants.
10005
+ *
10006
+ * NOTE (pending real-Chrome confirmation, see test/declarative-patch-probe
10007
+ * .html Q1): this mirrors the existing policy of keeping `for` on
10008
+ * <label>/<output>. If the shipping feature can drive a patch through a
10009
+ * surviving `for`-on-label/output + `id` pair, this pre-pass and the
10010
+ * attribute check at _isBasicCustomElement's caller must additionally drop
10011
+ * that pair on the IN_PLACE path. Left as-is until the taxonomy is verified.
10012
+ *
10013
+ * @param root the in-place root to sweep
10014
+ */
10015
+ const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
10016
+ if (!SAFE_FOR_XML) {
10017
+ return;
10018
+ }
10019
+ const stack = [root];
10020
+ while (stack.length > 0) {
10021
+ const node = stack.pop();
10022
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
10023
+ /* Remove range markers (the target side of a patch linkage): every
10024
+ processing instruction, and any markup-bearing comment. */
10025
+ if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
10026
+ try {
10027
+ remove(node);
10028
+ } catch (_) {
10029
+ /* Best-effort */
10030
+ }
10031
+ continue;
10032
+ }
10033
+ /* Strip patch-source attributes (the source side) off elements. */
10034
+ if (nodeType === NODE_TYPE.element) {
10035
+ const element = node;
10036
+ const lcTag = transformCaseFunc(getNodeName ? getNodeName(node) : node.nodeName);
10037
+ try {
10038
+ if (element.hasAttribute && element.hasAttribute('patchsrc')) {
10039
+ element.removeAttribute('patchsrc');
10040
+ }
10041
+ if (element.hasAttribute && element.hasAttribute('for') && lcTag !== 'label' && lcTag !== 'output') {
10042
+ element.removeAttribute('for');
10043
+ }
10044
+ } catch (_) {
10045
+ /* Clobbered removeAttribute/hasAttribute on a doomed node — ignore */
10046
+ }
10047
+ }
10048
+ const childNodes = getChildNodes(node);
10049
+ if (childNodes) {
10050
+ for (let i = childNodes.length - 1; i >= 0; --i) {
10051
+ stack.push(childNodes[i]);
10052
+ }
10053
+ }
10054
+ }
10055
+ };
9616
10056
  /**
9617
10057
  * _initDocument
9618
10058
  *
@@ -9670,7 +10110,17 @@
9670
10110
  * @return The created NodeIterator
9671
10111
  */
9672
10112
  const _createNodeIterator = function _createNodeIterator(root) {
9673
- return createNodeIterator.call(root.ownerDocument || root, root,
10113
+ /* Read ownerDocument through the cached Node.prototype getter, never the
10114
+ direct property. HTMLFormElement has [LegacyOverrideBuiltIns], so a
10115
+ clobbering child (<input name="ownerDocument"> or a form-associated
10116
+ external input) shadows the prototype getter and makes a direct read
10117
+ return that <input>. createNodeIterator.call(<input>, ...) then throws
10118
+ "Illegal invocation", and on the IN_PLACE path that throw lands before
10119
+ the walk's fail-closed barrier - leaving the caller's live tree, with
10120
+ any already-armed handler in it, un-neutralized. The cached getter
10121
+ returns the real Document regardless of the clobber. */
10122
+ const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
10123
+ return createNodeIterator.call(doc || root, root,
9674
10124
  // eslint-disable-next-line no-bitwise
9675
10125
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
9676
10126
  };
@@ -9710,7 +10160,11 @@
9710
10160
  const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
9711
10161
  var _node$querySelectorAl;
9712
10162
  node.normalize();
9713
- const walker = createNodeIterator.call(node.ownerDocument || node, node,
10163
+ /* Clobber-safe ownerDocument read, same reasoning as _createNodeIterator:
10164
+ under SAFE_FOR_TEMPLATES this runs on the live IN_PLACE root, which may
10165
+ carry a form-named-getter override of ownerDocument. */
10166
+ const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
10167
+ const walker = createNodeIterator.call(doc || node, node,
9714
10168
  // eslint-disable-next-line no-bitwise
9715
10169
  NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
9716
10170
  let currentNode = walker.nextNode();
@@ -9863,15 +10317,21 @@
9863
10317
  /**
9864
10318
  * Handle a node whose tag is forbidden or not allowlisted: keep
9865
10319
  * allowed custom elements (false return exits _sanitizeElements
9866
- * early - namespace/fallback checks and the afterSanitizeElements
9867
- * hook are intentionally skipped for kept custom elements), else
9868
- * hoist content per KEEP_CONTENT and remove.
10320
+ * early - the namespace and fallback-tag removal checks are
10321
+ * intentionally skipped for kept custom elements), else hoist
10322
+ * content per KEEP_CONTENT and remove.
10323
+ *
10324
+ * A kept custom element is the ONLY case in which this function
10325
+ * returns false, so the caller uses that return value to run the
10326
+ * afterSanitizeElements hook on the kept element and keep the
10327
+ * element-hook lifecycle consistent with normal allowlisted
10328
+ * elements (GHSA-c2j3-45gr-mqc4).
9869
10329
  *
9870
10330
  * @param currentNode the disallowed node
9871
10331
  * @param tagName the node's transformCaseFunc'd tag name
9872
10332
  * @return true if the node was removed, false if kept
9873
10333
  */
9874
- const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
10334
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
9875
10335
  /* Check if we have a custom element to handle */
9876
10336
  if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
9877
10337
  if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
@@ -9894,27 +10354,26 @@
9894
10354
  const childNodes = getChildNodes(currentNode);
9895
10355
  if (childNodes && parentNode) {
9896
10356
  const childCount = childNodes.length;
9897
- /* In-place: hoist the *original* children so the iterator visits
9898
- and sanitises them through the same allowlist pass as every other
9899
- node. The caller built the tree in the live document, so the
9900
- originals carry already-queued resource events (`<img onerror>`,
9901
- `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
9902
- those originals detached but still armed, firing in page scope
9903
- while the returned tree looked clean. Moving is safe in-place: the
9904
- root is pre-validated as an allowed tag and so is never the node
9905
- being removed, which keeps `parentNode` inside the iterator root
9906
- and the relocated child inside the serialised tree.
9907
- Otherwise (string / DOM-copy paths): clone. The iterator is rooted
9908
- at — and the result serialised from — `body`, so a restrictive
9909
- ALLOWED_TAGS that removes `body` itself must leave its content in
9910
- place, which only cloning does; and those paths parse into an
9911
- inert document, so their discarded originals never had a queued
9912
- event to neutralise.
10357
+ /* Hoist by moving each child up one level rather than deep-cloning
10358
+ it. Moving transfers every descendant exactly once, so a chain of
10359
+ nested disallowed elements costs O(n) instead of the O(n^2) that
10360
+ re-cloning the shrinking subtree at each level produced; it also
10361
+ empties the removed original, so `DOMPurify.removed` no longer
10362
+ pins whole subtrees. Moving preserves the in-place guarantee too:
10363
+ an original carrying already-queued resource events (`<img
10364
+ onerror>`, `<video>`/`<audio>` error, lazy/`onload`, …) is
10365
+ relocated and sanitised rather than left detached but still armed.
10366
+ The sole case that must clone is removing the walk root itself.
10367
+ The result is serialised from the root's subtree, so a restrictive
10368
+ ALLOWED_TAGS that strips the root (`body` on the string path) must
10369
+ leave the content inside it, which only cloning does. In IN_PLACE
10370
+ the root is pre-validated as an allowed tag and so is never removed
10371
+ here, so that path always takes the move branch.
9913
10372
  `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
9914
10373
  valid whether we move (drops the trailing entry) or clone (leaves
9915
10374
  the list intact). */
9916
10375
  for (let i = childCount - 1; i >= 0; --i) {
9917
- const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
10376
+ const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
9918
10377
  parentNode.insertBefore(hoisted, getNextSibling(currentNode));
9919
10378
  }
9920
10379
  }
@@ -9922,6 +10381,26 @@
9922
10381
  _forceRemove(currentNode);
9923
10382
  return true;
9924
10383
  };
10384
+ /**
10385
+ * Fork a hook-mutable allowlist off its shared binding the first time a
10386
+ * (possibly lazily-installed) uponSanitize* hook is about to see it, so the
10387
+ * hook cannot widen the per-instance default or the setConfig binding by
10388
+ * reference and leak past the call. Returns the set unchanged once it is
10389
+ * already call-local, so repeated calls across elements are idempotent.
10390
+ *
10391
+ * @param hookList the uponSanitize* hook array for this event
10392
+ * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
10393
+ * @param defaultSet the per-instance DEFAULT_ALLOWED_* constant
10394
+ * @param setConfigSet the captured setConfig() binding, or null
10395
+ * @return a call-local clone if a hook is present and set is still shared,
10396
+ * else set unchanged
10397
+ */
10398
+ const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
10399
+ if (hookList.length === 0) {
10400
+ return set;
10401
+ }
10402
+ return set === defaultSet || set === setConfigSet ? clone(set) : set;
10403
+ };
9925
10404
  /**
9926
10405
  * _sanitizeElements
9927
10406
  *
@@ -9931,9 +10410,20 @@
9931
10410
  * @param currentNode to check for permission to exist
9932
10411
  * @return true if node was killed, false if left alive
9933
10412
  */
9934
- const _sanitizeElements = function _sanitizeElements(currentNode) {
10413
+ // eslint-disable-next-line complexity
10414
+ const _sanitizeElements = function _sanitizeElements(currentNode, root) {
9935
10415
  /* Execute a hook if present */
9936
10416
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
10417
+ /* A hook may have detached the node - treat it as removed (see the
10418
+ detached-node comment after the uponSanitizeElement hook below). On
10419
+ the IN_PLACE path, neutralize the detached subtree first so a queued
10420
+ resource handler on it cannot fire in page scope after we return. */
10421
+ if (currentNode !== root && getParentNode(currentNode) === null) {
10422
+ if (IN_PLACE) {
10423
+ _neutralizeSubtree(currentNode);
10424
+ }
10425
+ return true;
10426
+ }
9937
10427
  /* Check if element is clobbered or can clobber */
9938
10428
  if (_isClobbered(currentNode)) {
9939
10429
  _forceRemove(currentNode);
@@ -9941,11 +10431,47 @@
9941
10431
  }
9942
10432
  /* Now let's check the element's type and name */
9943
10433
  const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
10434
+ /* Close the pre-walk clone-guard's timing gap: an uponSanitizeElement
10435
+ hook may have been installed after that guard sampled the hook arrays
10436
+ (e.g. lazily from beforeSanitizeElements), leaving ALLOWED_TAGS still
10437
+ aliasing a shared binding that a widening hook would mutate by
10438
+ reference. Fork it before exposing it to the hook. */
10439
+ ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
9944
10440
  /* Execute a hook if present */
9945
10441
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
9946
10442
  tagName,
9947
10443
  allowedTags: ALLOWED_TAGS
9948
10444
  });
10445
+ /* A hook may have detached the node from the tree — a long-standing
10446
+ user pattern (issue #469; draw.io-style foreignObject filtering).
10447
+ Per the cached, unclobberable parentNode getter the node is
10448
+ genuinely out of the tree, so it can reach neither the serialized
10449
+ output nor an IN_PLACE live tree; treat it as removed and stop
10450
+ processing it. Without this guard, the unsafe-node / namespace
10451
+ checks below would call _forceRemove on a parentless node and hit
10452
+ the REPORT-3 fail-closed throw — which exists for nodes DOMPurify
10453
+ wants gone but *cannot* detach (clobbered / parentless roots), the
10454
+ opposite of a node that is already safely gone. The walk root is
10455
+ exempt: a detached IN_PLACE root is legitimate input and must still
10456
+ be fully sanitized, and a kill-decision on it must keep hitting the
10457
+ REPORT-3 throw. Nodes detached by hooks stay the hook's
10458
+ responsibility for placement: they are not recorded in
10459
+ DOMPurify.removed, so the post-walk IN_PLACE pass (which iterates
10460
+ DOMPurify.removed) does not reach them. But a hook-detached subtree
10461
+ can still hold a queued resource-event handler - e.g. an <img onload>
10462
+ that began loading when the caller built the live tree - which fires
10463
+ in page scope after sanitize returns even though the handler never
10464
+ reached the returned tree. That is the audit-5 F1 hazard, and the
10465
+ documented node.remove() hook pattern walks straight into it. So on
10466
+ the IN_PLACE path we neutralize the detached subtree inline here,
10467
+ stripping its non-allow-listed attributes before returning, exactly
10468
+ as the post-walk pass does for _forceRemove'd subtrees. */
10469
+ if (currentNode !== root && getParentNode(currentNode) === null) {
10470
+ if (IN_PLACE) {
10471
+ _neutralizeSubtree(currentNode);
10472
+ }
10473
+ return true;
10474
+ }
9949
10475
  /* Remove mXSS vectors, processing instructions and risky comments */
9950
10476
  if (_isUnsafeNode(currentNode, tagName)) {
9951
10477
  _forceRemove(currentNode);
@@ -9953,7 +10479,22 @@
9953
10479
  }
9954
10480
  /* Remove element if anything forbids its presence */
9955
10481
  if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
9956
- return _sanitizeDisallowedNode(currentNode, tagName);
10482
+ const removed = _sanitizeDisallowedNode(currentNode, tagName, root);
10483
+ /* A false return means the node is a custom element kept via
10484
+ CUSTOM_ELEMENT_HANDLING - the only keep path through
10485
+ _sanitizeDisallowedNode. Run afterSanitizeElements on it so the
10486
+ element-hook lifecycle matches normal allowlisted elements: a
10487
+ security policy applied in this hook (e.g. stripping an attribute
10488
+ from every surviving element) must not silently skip kept custom
10489
+ elements (GHSA-c2j3-45gr-mqc4). This mirrors the normal-element
10490
+ tail below - the hook runs, then the walker's subsequent
10491
+ _sanitizeAttributes pass sanitizes the element's attributes. The
10492
+ deliberately skipped namespace and fallback-tag removal checks stay
10493
+ skipped; they are removal decisions, not the hook contract. */
10494
+ if (removed === false) {
10495
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
10496
+ }
10497
+ return removed;
9957
10498
  }
9958
10499
  /* Check whether element has a valid namespace.
9959
10500
  Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
@@ -10000,6 +10541,33 @@
10000
10541
  if (FORBID_ATTR[lcName]) {
10001
10542
  return false;
10002
10543
  }
10544
+ /* Reject declarative-partial-updates patch-linkage attributes
10545
+ (https://github.com/WICG/declarative-partial-updates).
10546
+ Empirical note (Chrome 150, verified — see
10547
+ test/declarative-patch-probe-v3.html): expansion is NOT applied after
10548
+ sanitization. For the string path it fires during sanitize()'s own
10549
+ parse, so the walk sees and sanitizes the fully materialized expanded
10550
+ tree — teleports into MathML/SVG integration points included; a
10551
+ weaponized `<template for>`->`<img onerror>` comes back with the handler
10552
+ stripped. For the IN_PLACE path it fires on connection, before the walk.
10553
+ Either way DOMPurify is NOT blind to the patch.
10554
+ This removal is therefore defense-in-depth rather than the sole barrier:
10555
+ it prevents live linkage from surviving into the OUTPUT and re-expanding
10556
+ in the caller's context, and keeps behaviour deterministic if a future
10557
+ engine defers expansion. `for` is legitimate only on <label>/<output>;
10558
+ anywhere else (notably <template for>) it links the element to a patch
10559
+ target and teleports or removes an arbitrary DOM range by id/marker name.
10560
+ `patchsrc` fetches remote markup and is treated as a script-loading
10561
+ mechanism (CSP). Gated on SAFE_FOR_XML so the removal groups with the
10562
+ other structural-threat checks and stays overridable, consistent with
10563
+ the rest of the codebase. PI range markers are already removed by
10564
+ _isUnsafeNode. */
10565
+ if (SAFE_FOR_XML && lcName === 'patchsrc') {
10566
+ return false;
10567
+ }
10568
+ if (SAFE_FOR_XML && lcName === 'for' && lcTag !== 'label' && lcTag !== 'output') {
10569
+ return false;
10570
+ }
10003
10571
  /* Make sure attribute cannot clobber */
10004
10572
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
10005
10573
  return false;
@@ -10116,6 +10684,9 @@
10116
10684
  if (!attributes || _isClobbered(currentNode)) {
10117
10685
  return;
10118
10686
  }
10687
+ /* Same lazy-install guard as uponSanitizeElement (see there): fork the
10688
+ attribute allowlist off its shared binding before a hook can see it. */
10689
+ ALLOWED_ATTR = _forkSharedAllowlist(hooks.uponSanitizeAttribute, ALLOWED_ATTR, DEFAULT_ALLOWED_ATTR, SET_CONFIG_ALLOWED_ATTR);
10119
10690
  const hookEvent = {
10120
10691
  attrName: '',
10121
10692
  attrValue: '',
@@ -10209,7 +10780,7 @@
10209
10780
  /* Execute a hook if present */
10210
10781
  _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
10211
10782
  /* Sanitize tags and elements */
10212
- _sanitizeElements(shadowNode);
10783
+ _sanitizeElements(shadowNode, fragment);
10213
10784
  /* Check attributes next */
10214
10785
  _sanitizeAttributes(shadowNode);
10215
10786
  /* Deep shadow DOM detected.
@@ -10400,6 +10971,11 @@
10400
10971
  keep using and whose return value they ignore — unsanitized. REPORT-2. */
10401
10972
  const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
10402
10973
  if (inPlace) {
10974
+ /* Declarative-partial-updates / streaming pre-pass: sever every patch
10975
+ linkage across the live tree BEFORE the walk, so no patch can fire
10976
+ mid-walk and inject into an already-processed region. Runs first, so
10977
+ it also covers the forbidden/clobbered roots that throw below. */
10978
+ _neutralizePatchLinkage(dirty);
10403
10979
  /* Do some early pre-sanitization to avoid unsafe root nodes.
10404
10980
  Read nodeName through the cached prototype getter — a clobbering
10405
10981
  child named "nodeName" on the form root would otherwise shadow
@@ -10409,6 +10985,9 @@
10409
10985
  if (typeof nn === 'string') {
10410
10986
  const tagName = transformCaseFunc(nn);
10411
10987
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
10988
+ /* Fail closed on a live root: neutralize handlers/children before
10989
+ throwing, exactly as the mid-walk abort path does. */
10990
+ _neutralizeRoot(dirty);
10412
10991
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
10413
10992
  }
10414
10993
  }
@@ -10423,6 +11002,10 @@
10423
11002
  the application unsanitized. Refuse to sanitize such a root
10424
11003
  the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
10425
11004
  if (_isClobbered(dirty)) {
11005
+ /* Fail closed on a live clobbered root before throwing.
11006
+ _neutralizeRoot's reads are clobber-safe (cached getters); the
11007
+ form's non-clobbered descendants, e.g. an armed <img>, are scrubbed. */
11008
+ _neutralizeRoot(dirty);
10426
11009
  throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
10427
11010
  }
10428
11011
  /* Sanitize attached shadow roots before the main iterator runs.
@@ -10475,20 +11058,24 @@
10475
11058
  _forceRemove(body.firstChild);
10476
11059
  }
10477
11060
  /* Get node iterator */
10478
- const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
11061
+ const walkRoot = inPlace ? dirty : body;
10479
11062
  /* Now start iterating over the created document.
10480
11063
  The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
10481
11064
  engine/custom-element mutation can detach a node mid-walk so
10482
11065
  `_forceRemove`'s parentless guard throws, aborting the loop. Without the
10483
11066
  barrier the caller's in-place tree would be left half-sanitized with the
10484
- unvisited tail still armed. On any throw we fail closed — strip the
10485
- in-place root bare — then rethrow so the existing throw contract is
10486
- preserved. (String/DOM-copy paths never return the partial body, so the
10487
- propagating throw is already fail-closed there.) */
11067
+ unvisited tail still armed. _createNodeIterator itself is inside the
11068
+ barrier too: constructing the iterator dereferences the root's document,
11069
+ and any failure there (e.g. an exotic/clobbered root) must still fail
11070
+ closed rather than skip the neutralize. On any throw we fail closed -
11071
+ strip the in-place root bare - then rethrow so the existing throw
11072
+ contract is preserved. (String/DOM-copy paths never return the partial
11073
+ body, so the propagating throw is already fail-closed there.) */
10488
11074
  try {
11075
+ const nodeIterator = _createNodeIterator(walkRoot);
10489
11076
  while (currentNode = nodeIterator.nextNode()) {
10490
11077
  /* Sanitize tags and elements */
10491
- _sanitizeElements(currentNode);
11078
+ _sanitizeElements(currentNode, walkRoot);
10492
11079
  /* Check attributes next */
10493
11080
  _sanitizeAttributes(currentNode);
10494
11081
  /* Shadow DOM detected, sanitize it.
@@ -10502,6 +11089,14 @@
10502
11089
  } catch (error) {
10503
11090
  if (inPlace) {
10504
11091
  _neutralizeRoot(dirty);
11092
+ /* Nodes _forceRemove'd earlier in the aborted walk are already
11093
+ detached from the root, so _neutralizeRoot's subtree pass does not
11094
+ reach them. Defuse them too, mirroring the success-path loop below. */
11095
+ arrayForEach(DOMPurify.removed, entry => {
11096
+ if (entry.element) {
11097
+ _neutralizeSubtree(entry.element);
11098
+ }
11099
+ });
10505
11100
  }
10506
11101
  throw error;
10507
11102
  }
@@ -14928,6 +15523,54 @@
14928
15523
  validate_card_types: validateCardNumberInput
14929
15524
  });
14930
15525
  }
15526
+ /**
15527
+ * Current method restricts which card schemes the card number input accepts, without changing which card
15528
+ * icons the widget displays. Scheme identifiers are matched case-insensitively and ignoring surrounding
15529
+ * whitespace; unsupported identifiers are ignored with a warning, so a list in which every identifier is
15530
+ * unsupported applies no restriction at all.
15531
+ *
15532
+ * Takes precedence over setSupportedCardIcons: when a non-empty list is supplied here, it is the only list
15533
+ * used for validation and the validateCardNumberInput flag of setSupportedCardIcons no longer affects it.
15534
+ * Calling this method more than once replaces the previous list rather than merging with it.
15535
+ *
15536
+ * Must be called before load().
15537
+ *
15538
+ * @example
15539
+ *
15540
+ * widget.setAllowedCardSchemes(['visa', 'mastercard']);
15541
+ *
15542
+ * @param {string[]} schemes - [CARD_SCHEME]{@link CARD_SCHEME}
15543
+ */
15544
+ }, {
15545
+ key: "setAllowedCardSchemes",
15546
+ value: function setAllowedCardSchemes(schemes) {
15547
+ var vocabulary = ObjectHelper.values(CARD_SCHEME);
15548
+ var allowedSchemes = [];
15549
+ var _iterator = _createForOfIteratorHelper(Array.isArray(schemes) ? schemes : []),
15550
+ _step;
15551
+ try {
15552
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
15553
+ var entry = _step.value;
15554
+ var scheme = typeof entry === 'string' ? entry.trim().toLowerCase() : '';
15555
+ if (vocabulary.indexOf(scheme) === -1) {
15556
+ console.warn("Widget::setAllowedCardSchemes: unsupported card scheme ".concat(entry));
15557
+ continue;
15558
+ }
15559
+ if (allowedSchemes.indexOf(scheme) === -1) {
15560
+ allowedSchemes.push(scheme);
15561
+ }
15562
+ }
15563
+ } catch (err) {
15564
+ _iterator.e(err);
15565
+ } finally {
15566
+ _iterator.f();
15567
+ }
15568
+ if (allowedSchemes.length) {
15569
+ this.link.setParams({
15570
+ allowed_card_schemes: allowedSchemes.join(',')
15571
+ });
15572
+ }
15573
+ }
14931
15574
  /**
14932
15575
  * Current method can hide prevent the widget from showing the error messages
14933
15576
  *
@@ -46179,6 +46822,7 @@
46179
46822
  exports.ApplePayOpenWalletButton = ApplePayOpenWalletButton;
46180
46823
  exports.ApplePayWalletButtonExpress = ApplePayWalletButtonExpress;
46181
46824
  exports.CANVAS_3DS_EVENT = CANVAS_3DS_EVENT;
46825
+ exports.CARD_SCHEME = CARD_SCHEME;
46182
46826
  exports.CHECKOUT_BUTTON_EVENT = CHECKOUT_BUTTON_EVENT;
46183
46827
  exports.CHECKOUT_EVENT = EVENT$2;
46184
46828
  exports.Canvas3ds = Canvas3ds;