@paydock/client-sdk 1.144.1-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.
- package/README.md +551 -32
- package/bundles/index.cjs +2683 -599
- package/bundles/index.cjs.d.ts +322 -21
- package/bundles/index.mjs +2683 -600
- package/bundles/index.mjs.d.ts +322 -21
- package/bundles/types/api/api-base.d.ts +6 -0
- package/bundles/types/api/api-base.d.ts.map +1 -1
- package/bundles/types/api/api-charge-internal.d.ts +1 -5
- package/bundles/types/api/api-charge-internal.d.ts.map +1 -1
- package/bundles/types/canvas-3ds/canvas-3ds-event-map.d.ts +50 -0
- package/bundles/types/canvas-3ds/canvas-3ds-event-map.d.ts.map +1 -1
- package/bundles/types/canvas-3ds/canvas-3ds.d.ts +7 -5
- package/bundles/types/canvas-3ds/canvas-3ds.d.ts.map +1 -1
- package/bundles/types/canvas-3ds/index.d.ts +1 -1
- package/bundles/types/canvas-3ds/index.d.ts.map +1 -1
- package/bundles/types/canvas-3ds/services/gpayments-service.d.ts +117 -2
- package/bundles/types/canvas-3ds/services/gpayments-service.d.ts.map +1 -1
- package/bundles/types/canvas-3ds/services/standalone3ds-service.d.ts +6 -0
- package/bundles/types/canvas-3ds/services/standalone3ds-service.d.ts.map +1 -1
- package/bundles/types/components/iframe-event.d.ts +4 -3
- package/bundles/types/components/iframe-event.d.ts.map +1 -1
- package/bundles/types/components/iframe.d.ts +5 -0
- package/bundles/types/components/iframe.d.ts.map +1 -1
- package/bundles/types/components/param.d.ts +19 -0
- package/bundles/types/components/param.d.ts.map +1 -1
- package/bundles/types/helper/browser.d.ts.map +1 -1
- package/bundles/types/helper/element-id.d.ts +3 -1
- package/bundles/types/helper/element-id.d.ts.map +1 -1
- package/bundles/types/helper/uuid.d.ts.map +1 -1
- package/bundles/types/index-cba.d.ts +1 -1
- package/bundles/types/index-cba.d.ts.map +1 -1
- package/bundles/types/index.d.ts +2 -2
- package/bundles/types/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/apple-pay-open-wallet-button.d.ts +41 -0
- package/bundles/types/open-wallets/apple-pay-open-wallet-button.d.ts.map +1 -1
- package/bundles/types/open-wallets/base/open-wallet-buttons.d.ts +10 -0
- package/bundles/types/open-wallets/base/open-wallet-buttons.d.ts.map +1 -1
- package/bundles/types/open-wallets/base/service-config-cache.d.ts +23 -0
- package/bundles/types/open-wallets/base/service-config-cache.d.ts.map +1 -0
- package/bundles/types/open-wallets/google-pay-open-wallet-button.d.ts +33 -1
- package/bundles/types/open-wallets/google-pay-open-wallet-button.d.ts.map +1 -1
- package/bundles/types/open-wallets/index.d.ts +82 -1
- package/bundles/types/open-wallets/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/apple-pay/apple-pay-availability.interface.d.ts +41 -0
- package/bundles/types/open-wallets/interfaces/apple-pay/apple-pay-availability.interface.d.ts.map +1 -0
- package/bundles/types/open-wallets/interfaces/apple-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/interfaces/apple-pay/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/google-pay/google-pay-availability.interface.d.ts +25 -0
- package/bundles/types/open-wallets/interfaces/google-pay/google-pay-availability.interface.d.ts.map +1 -0
- package/bundles/types/open-wallets/interfaces/google-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/interfaces/google-pay/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/index.d.ts +3 -0
- package/bundles/types/open-wallets/interfaces/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/open-wallet-availability.interface.d.ts +31 -0
- package/bundles/types/open-wallets/interfaces/open-wallet-availability.interface.d.ts.map +1 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay-availability.d.ts +58 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay-availability.d.ts.map +1 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts +8 -10
- package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/apple-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/services/apple-pay/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/google-pay/google-pay-availability.d.ts +53 -0
- package/bundles/types/open-wallets/services/google-pay/google-pay-availability.d.ts.map +1 -0
- package/bundles/types/open-wallets/services/google-pay/google-pay.open-wallet.service.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/google-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/services/google-pay/index.d.ts.map +1 -1
- package/bundles/types/widget/multi-widget.d.ts +19 -0
- package/bundles/types/widget/multi-widget.d.ts.map +1 -1
- package/bundles/widget.umd.js +2683 -599
- package/bundles/widget.umd.js.d.ts +322 -21
- package/bundles/widget.umd.js.min.d.ts +322 -21
- package/bundles/widget.umd.min.js +1 -1
- package/docs/api-canvas3ds.md +10 -8
- package/docs/api-checkout-button.md +15 -0
- package/docs/api-ps-widget.md +15 -0
- package/docs/api-widget.md +15 -0
- package/docs/canvas3ds-examples.md +43 -1
- package/docs/open-wallet-buttons-examples.md +170 -2
- package/docs/open-wallet-buttons.md +252 -29
- package/docs/widget-examples.md +41 -0
- package/package.json +20 -11
- package/slate.md +254 -3
package/bundles/widget.umd.js
CHANGED
|
@@ -834,16 +834,28 @@
|
|
|
834
834
|
value: function getBrowserName() {
|
|
835
835
|
var sUsrAg = navigator.userAgent;
|
|
836
836
|
// "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
|
|
837
|
-
if (sUsrAg.indexOf('Firefox') > -1)
|
|
838
|
-
|
|
837
|
+
if (sUsrAg.indexOf('Firefox') > -1) {
|
|
838
|
+
return 'Mozilla Firefox';
|
|
839
|
+
}
|
|
840
|
+
if (sUsrAg.indexOf('Opera') > -1) {
|
|
841
|
+
return 'Opera';
|
|
842
|
+
}
|
|
839
843
|
// "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Zoom 3.6.0; wbx 1.0.0; rv:11.0) like Gecko"
|
|
840
|
-
if (sUsrAg.indexOf('Trident') > -1)
|
|
844
|
+
if (sUsrAg.indexOf('Trident') > -1) {
|
|
845
|
+
return 'Microsoft Internet Explorer';
|
|
846
|
+
}
|
|
841
847
|
// "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
|
|
842
|
-
if (sUsrAg.indexOf('Edge') > -1)
|
|
848
|
+
if (sUsrAg.indexOf('Edge') > -1) {
|
|
849
|
+
return 'Microsoft Edge';
|
|
850
|
+
}
|
|
843
851
|
// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36"
|
|
844
|
-
if (sUsrAg.indexOf('Chrome') > -1)
|
|
852
|
+
if (sUsrAg.indexOf('Chrome') > -1) {
|
|
853
|
+
return 'Google Chrome or Chromium';
|
|
854
|
+
}
|
|
845
855
|
// "Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1 980x1306"
|
|
846
|
-
if (sUsrAg.indexOf('Safari') > -1)
|
|
856
|
+
if (sUsrAg.indexOf('Safari') > -1) {
|
|
857
|
+
return 'Apple Safari';
|
|
858
|
+
}
|
|
847
859
|
return 'unknown';
|
|
848
860
|
}
|
|
849
861
|
}, {
|
|
@@ -874,11 +886,13 @@
|
|
|
874
886
|
}, {
|
|
875
887
|
key: "getBrowserInfo",
|
|
876
888
|
value: function getBrowserInfo() {
|
|
877
|
-
|
|
889
|
+
// Bound the user-agent length before running any regex to avoid
|
|
890
|
+
// pathological backtracking (ReDoS) on maliciously long inputs.
|
|
891
|
+
var ua = (navigator.userAgent || '').slice(0, 256);
|
|
878
892
|
var M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
879
|
-
var tem;
|
|
880
|
-
if (/trident/i.test(M[1])) {
|
|
881
|
-
tem = /\brv[ :](\d+)
|
|
893
|
+
var tem = null;
|
|
894
|
+
if (/trident/i.test(M[1] || '')) {
|
|
895
|
+
tem = ua.match(/\brv[ :](\d+)/) || [];
|
|
882
896
|
return {
|
|
883
897
|
name: 'IE',
|
|
884
898
|
version: tem[1] || ''
|
|
@@ -894,8 +908,8 @@
|
|
|
894
908
|
}
|
|
895
909
|
}
|
|
896
910
|
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
|
897
|
-
|
|
898
|
-
if (
|
|
911
|
+
tem = ua.match(/version\/(\d+)/i);
|
|
912
|
+
if (tem != null) {
|
|
899
913
|
M.splice(1, 1, tem[1]);
|
|
900
914
|
}
|
|
901
915
|
return {
|
|
@@ -1855,7 +1869,7 @@
|
|
|
1855
1869
|
version: 'x-sdk-version',
|
|
1856
1870
|
type: 'x-sdk-type'
|
|
1857
1871
|
});
|
|
1858
|
-
SDK._version = 'v1.
|
|
1872
|
+
SDK._version = 'v1.147.0';
|
|
1859
1873
|
|
|
1860
1874
|
var ACCESS_HEADER_NAME = {
|
|
1861
1875
|
accessToken: 'x-access-token',
|
|
@@ -4711,6 +4725,15 @@
|
|
|
4711
4725
|
this.env.setEnv(env, alias);
|
|
4712
4726
|
return this;
|
|
4713
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
|
+
}
|
|
4714
4737
|
}, {
|
|
4715
4738
|
key: "requestObservable",
|
|
4716
4739
|
value: function requestObservable(method, url, requestBody) {
|
|
@@ -4923,6 +4946,18 @@
|
|
|
4923
4946
|
environment: this.env.getEnv()
|
|
4924
4947
|
};
|
|
4925
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
|
+
}
|
|
4926
4961
|
}]);
|
|
4927
4962
|
}();
|
|
4928
4963
|
|
|
@@ -4983,7 +5018,6 @@
|
|
|
4983
5018
|
|
|
4984
5019
|
var WALLET_CAPTURE_LINK = '/v1/charges/wallet/capture';
|
|
4985
5020
|
var WALLET_CALLBACK_LINK = '/v1/charges/wallet/callback';
|
|
4986
|
-
var STANDALONE_3DS_PROCESS_LINK = '/v1/charges/standalone-3ds/process';
|
|
4987
5021
|
var STANDALONE_3DS_HANDLE_LINK = '/v1/charges/standalone-3ds/handle';
|
|
4988
5022
|
var ApiChargeInternal = /*#__PURE__*/function () {
|
|
4989
5023
|
function ApiChargeInternal(api) {
|
|
@@ -5000,11 +5034,6 @@
|
|
|
5000
5034
|
value: function walletCallback(payload) {
|
|
5001
5035
|
return this.api.getClientPromise('POST', WALLET_CALLBACK_LINK).send(payload);
|
|
5002
5036
|
}
|
|
5003
|
-
}, {
|
|
5004
|
-
key: "standalone3dsProcess",
|
|
5005
|
-
value: function standalone3dsProcess(payload) {
|
|
5006
|
-
return this.api.getClientPromise('POST', STANDALONE_3DS_PROCESS_LINK).send(payload);
|
|
5007
|
-
}
|
|
5008
5037
|
}, {
|
|
5009
5038
|
key: "standalone3dsHandle",
|
|
5010
5039
|
value: function standalone3dsHandle() {
|
|
@@ -5143,6 +5172,10 @@
|
|
|
5143
5172
|
_classCallCheck(this, IFrame);
|
|
5144
5173
|
this.container = container;
|
|
5145
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
|
+
*/
|
|
5146
5179
|
return _createClass(IFrame, [{
|
|
5147
5180
|
key: "load",
|
|
5148
5181
|
value: function load(link) {
|
|
@@ -5151,6 +5184,9 @@
|
|
|
5151
5184
|
if (!this.container.isExist() || this.isExist()) return;
|
|
5152
5185
|
var iFrame = document.createElement('iframe');
|
|
5153
5186
|
if (options.title) iFrame.title = options.title;
|
|
5187
|
+
if (options.onLoad) {
|
|
5188
|
+
iFrame.addEventListener('load', options.onLoad);
|
|
5189
|
+
}
|
|
5154
5190
|
if (iframeClass) iFrame.classList.add(iframeClass);
|
|
5155
5191
|
// Set additional attributes before src and DOM insertion so that
|
|
5156
5192
|
// Permissions-Policy (e.g. allow="payment") is in place when the
|
|
@@ -5291,14 +5327,14 @@
|
|
|
5291
5327
|
data = JSON.parse(event.data);
|
|
5292
5328
|
} catch (error) {}
|
|
5293
5329
|
if (!data) return;
|
|
5294
|
-
_this.emit(data);
|
|
5330
|
+
_this.emit(data, event.origin);
|
|
5295
5331
|
});
|
|
5296
5332
|
}
|
|
5297
5333
|
return _createClass(IFrameEvent, [{
|
|
5298
5334
|
key: "emit",
|
|
5299
|
-
value: function emit(data) {
|
|
5335
|
+
value: function emit(data, origin) {
|
|
5300
5336
|
for (var key in this.listeners) {
|
|
5301
|
-
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]);
|
|
5302
5338
|
}
|
|
5303
5339
|
}
|
|
5304
5340
|
}, {
|
|
@@ -5371,6 +5407,20 @@
|
|
|
5371
5407
|
DECOUPLED: 'chargeAuthDecoupled',
|
|
5372
5408
|
/** Challenge required — issuer demands user interaction. Payload: `Canvas3dsAuthPayload`. */
|
|
5373
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',
|
|
5374
5424
|
/** Informational signal emitted by the GPayments flow. Internal — not part of the public typed surface. */
|
|
5375
5425
|
INFO: 'chargeAuthInfo',
|
|
5376
5426
|
/** Error during the flow (network, parsing, etc.). Payload: `Canvas3dsErrorPayload`. */
|
|
@@ -5382,13 +5432,56 @@
|
|
|
5382
5432
|
* backwards-compatible internal usage.
|
|
5383
5433
|
*/
|
|
5384
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));
|
|
5385
5466
|
var GPaymentsService = /*#__PURE__*/function () {
|
|
5386
5467
|
function GPaymentsService(container, api, eventEmitter) {
|
|
5468
|
+
var trustedOrigins = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
5387
5469
|
_classCallCheck(this, GPaymentsService);
|
|
5388
5470
|
this.container = container;
|
|
5389
5471
|
this.api = api;
|
|
5390
5472
|
this.eventEmitter = eventEmitter;
|
|
5473
|
+
this.trustedOrigins = trustedOrigins;
|
|
5391
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;
|
|
5392
5485
|
this.iFrameEvent = new IFrameEvent(window);
|
|
5393
5486
|
}
|
|
5394
5487
|
return _createClass(GPaymentsService, [{
|
|
@@ -5408,6 +5501,7 @@
|
|
|
5408
5501
|
key: "initializeIFrames",
|
|
5409
5502
|
value: function initializeIFrames(initializationUrl, secondaryUrl, title) {
|
|
5410
5503
|
var hideAuthorization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
5504
|
+
var onLoad = arguments.length > 4 ? arguments[4] : undefined;
|
|
5411
5505
|
var container = this.container.getElement();
|
|
5412
5506
|
if (!container) {
|
|
5413
5507
|
return;
|
|
@@ -5418,7 +5512,8 @@
|
|
|
5418
5512
|
this.browserAndChallengeContainer = new Container('#paydock_authorization_iframe');
|
|
5419
5513
|
this.iFrameAuthorization = new IFrame(this.browserAndChallengeContainer);
|
|
5420
5514
|
this.iFrameAuthorization.load(initializationUrl, {
|
|
5421
|
-
title: title
|
|
5515
|
+
title: title,
|
|
5516
|
+
onLoad: onLoad
|
|
5422
5517
|
});
|
|
5423
5518
|
if (secondaryUrl) {
|
|
5424
5519
|
var divSecondaryURL = document.createElement('div');
|
|
@@ -5452,25 +5547,192 @@
|
|
|
5452
5547
|
}, {
|
|
5453
5548
|
key: "setupIFrameEvents",
|
|
5454
5549
|
value: function setupIFrameEvents(widgetId) {
|
|
5455
|
-
var
|
|
5456
|
-
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) {
|
|
5457
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;
|
|
5458
5564
|
if (data.info) {
|
|
5459
|
-
|
|
5565
|
+
_this2.eventEmitter.emit(GPAYMENTS_EVENT.INFO, {
|
|
5460
5566
|
info: data.info
|
|
5461
5567
|
});
|
|
5462
5568
|
}
|
|
5463
|
-
|
|
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
|
+
}
|
|
5464
5585
|
} else if (data.status === IFRAME_STATUS.TIMEOUT || data.status === IFRAME_STATUS.INVALID) {
|
|
5465
|
-
|
|
5586
|
+
_this2.finishChallengeLifecycle();
|
|
5587
|
+
_this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this2.parseHandleResponse({
|
|
5466
5588
|
status: data.status
|
|
5467
5589
|
}, data.charge_3ds_id));
|
|
5468
5590
|
}
|
|
5469
5591
|
});
|
|
5470
|
-
this.iFrameEvent.on(EVENT$4.CHARGE_AUTH_SUCCESS, widgetId, function (data) {
|
|
5471
|
-
|
|
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
|
|
5472
5718
|
});
|
|
5473
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
|
+
}
|
|
5474
5736
|
}, {
|
|
5475
5737
|
key: "parseResultData",
|
|
5476
5738
|
value: function parseResultData(_ref2, charge3dsId) {
|
|
@@ -5504,24 +5766,49 @@
|
|
|
5504
5766
|
}, {
|
|
5505
5767
|
key: "processResult",
|
|
5506
5768
|
value: function processResult(charge3dsId) {
|
|
5507
|
-
var
|
|
5769
|
+
var _this5 = this;
|
|
5508
5770
|
if (this.resultRead) {
|
|
5509
5771
|
return;
|
|
5510
5772
|
}
|
|
5511
5773
|
this.resultRead = true;
|
|
5774
|
+
this.finishChallengeLifecycle();
|
|
5512
5775
|
this.api.charge().standalone3dsHandle().then(function (result) {
|
|
5513
5776
|
var _a;
|
|
5514
|
-
|
|
5515
|
-
(_a =
|
|
5777
|
+
_this5.iFrameAuthorization.remove();
|
|
5778
|
+
(_a = _this5.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.remove();
|
|
5516
5779
|
if (result.status === PROCESS_STANDALONE_3DS_STATUS.SUCCESS) {
|
|
5517
|
-
|
|
5780
|
+
_this5.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this5.parseResultData(result, charge3dsId));
|
|
5518
5781
|
} else {
|
|
5519
|
-
|
|
5782
|
+
_this5.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this5.parseResultData(result, charge3dsId));
|
|
5520
5783
|
}
|
|
5521
5784
|
}, function (err) {
|
|
5522
|
-
|
|
5785
|
+
_this5.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this5.parseError(err, charge3dsId));
|
|
5523
5786
|
});
|
|
5524
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
|
+
}
|
|
5525
5812
|
}, {
|
|
5526
5813
|
key: "externalAPI",
|
|
5527
5814
|
value: function externalAPI(method, url) {
|
|
@@ -5535,60 +5822,106 @@
|
|
|
5535
5822
|
reject(error);
|
|
5536
5823
|
}
|
|
5537
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;
|
|
5538
5832
|
request.send();
|
|
5539
5833
|
});
|
|
5540
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
|
+
*/
|
|
5541
5842
|
}, {
|
|
5542
5843
|
key: "doPolling",
|
|
5543
|
-
value: function doPolling(url, charge3dsId) {
|
|
5544
|
-
var
|
|
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
|
+
};
|
|
5545
5856
|
this.externalAPI('GET', url).then(function (data) {
|
|
5857
|
+
if (_this6.resultRead || _this6.challengeLifecycleClosed) {
|
|
5858
|
+
return;
|
|
5859
|
+
}
|
|
5546
5860
|
if (!data.event || data.event === 'AuthResultNotReady') {
|
|
5547
|
-
|
|
5548
|
-
_this3.doPolling(url, charge3dsId);
|
|
5549
|
-
}, 2000);
|
|
5861
|
+
schedule();
|
|
5550
5862
|
} else if (data.event === 'AuthResultReady') {
|
|
5551
|
-
|
|
5863
|
+
_this6.emitChallengeCompleted(charge3dsId, 'poll');
|
|
5864
|
+
_this6.processResult(charge3dsId);
|
|
5552
5865
|
} else {
|
|
5553
5866
|
throw new Error('Event not supported');
|
|
5554
5867
|
}
|
|
5555
5868
|
})["catch"](function (err) {
|
|
5556
|
-
|
|
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));
|
|
5557
5877
|
});
|
|
5558
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
|
+
*/
|
|
5559
5883
|
}, {
|
|
5560
|
-
key: "
|
|
5561
|
-
value: function
|
|
5562
|
-
var
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
if (authenticationResult.
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
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);
|
|
5585
5909
|
}
|
|
5586
5910
|
} else {
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
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
|
+
}
|
|
5592
5925
|
}
|
|
5593
5926
|
}]);
|
|
5594
5927
|
}();
|
|
@@ -5615,10 +5948,27 @@
|
|
|
5615
5948
|
api.setEnv(this.env, this.alias);
|
|
5616
5949
|
switch (tokenData.service_type) {
|
|
5617
5950
|
case STANDALONE_3DS_GATEWAYS.GPAYMENTS:
|
|
5618
|
-
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);
|
|
5619
5952
|
break;
|
|
5620
5953
|
}
|
|
5621
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
|
+
}
|
|
5622
5972
|
}, {
|
|
5623
5973
|
key: "setEnv",
|
|
5624
5974
|
value: function setEnv(env, alias) {
|
|
@@ -5654,12 +6004,12 @@
|
|
|
5654
6004
|
return _createClass(Uuid, null, [{
|
|
5655
6005
|
key: "generate",
|
|
5656
6006
|
value: function generate() {
|
|
5657
|
-
if (typeof window !==
|
|
6007
|
+
if (typeof window !== 'undefined' && typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues !== 'undefined') {
|
|
5658
6008
|
var buf = new Uint16Array(8);
|
|
5659
6009
|
window.crypto.getRandomValues(buf);
|
|
5660
|
-
return
|
|
6010
|
+
return Uuid.hash(buf[0]) + Uuid.hash(buf[1]) + '-' + Uuid.hash(buf[2]) + '-' + Uuid.hash(buf[3]) + '-' + Uuid.hash(buf[4]) + '-' + Uuid.hash(buf[5]) + Uuid.hash(buf[6]) + Uuid.hash(buf[7]);
|
|
5661
6011
|
} else {
|
|
5662
|
-
return
|
|
6012
|
+
return Uuid.random() + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + Uuid.random() + Uuid.random();
|
|
5663
6013
|
}
|
|
5664
6014
|
}
|
|
5665
6015
|
}, {
|
|
@@ -5667,14 +6017,22 @@
|
|
|
5667
6017
|
value: function hash(number) {
|
|
5668
6018
|
var hash = number.toString(16);
|
|
5669
6019
|
while (hash.length < 4) {
|
|
5670
|
-
hash =
|
|
6020
|
+
hash = '0' + hash;
|
|
5671
6021
|
}
|
|
5672
6022
|
return hash;
|
|
5673
6023
|
}
|
|
5674
6024
|
}, {
|
|
5675
6025
|
key: "random",
|
|
5676
6026
|
value: function random() {
|
|
5677
|
-
|
|
6027
|
+
var value;
|
|
6028
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
6029
|
+
var buf = new Uint16Array(1);
|
|
6030
|
+
crypto.getRandomValues(buf);
|
|
6031
|
+
value = buf[0] / 0x10000;
|
|
6032
|
+
} else {
|
|
6033
|
+
value = Math.random();
|
|
6034
|
+
}
|
|
6035
|
+
return Math.floor((1 + value) * 0x10000).toString(16).substring(1);
|
|
5678
6036
|
}
|
|
5679
6037
|
}]);
|
|
5680
6038
|
}();
|
|
@@ -5779,11 +6137,13 @@
|
|
|
5779
6137
|
* @const STANDALONE_3DS_EVENT
|
|
5780
6138
|
*
|
|
5781
6139
|
* @type {object}
|
|
5782
|
-
* @param {string}
|
|
5783
|
-
* @param {string}
|
|
5784
|
-
* @param {string}
|
|
5785
|
-
* @param {string}
|
|
5786
|
-
* @param {string}
|
|
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
|
|
5787
6147
|
* @param {string} ERROR=error
|
|
5788
6148
|
*/
|
|
5789
6149
|
/**
|
|
@@ -6165,6 +6525,24 @@
|
|
|
6165
6525
|
EFTPOS_WHITE: 'eftpos_white',
|
|
6166
6526
|
UNIONPAY: 'unionpay'
|
|
6167
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
|
+
};
|
|
6168
6546
|
var SUPPORTED_CHECKOUT_META_COLLECTION = [].concat([
|
|
6169
6547
|
// Paypal
|
|
6170
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'], [
|
|
@@ -8349,7 +8727,7 @@
|
|
|
8349
8727
|
}]);
|
|
8350
8728
|
}(WalletService);
|
|
8351
8729
|
|
|
8352
|
-
/*! @license DOMPurify 3.4.
|
|
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 */
|
|
8353
8731
|
|
|
8354
8732
|
var purify_cjs;
|
|
8355
8733
|
var hasRequiredPurify_cjs;
|
|
@@ -8358,22 +8736,63 @@
|
|
|
8358
8736
|
if (hasRequiredPurify_cjs) return purify_cjs;
|
|
8359
8737
|
hasRequiredPurify_cjs = 1;
|
|
8360
8738
|
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
|
|
8376
|
-
|
|
8739
|
+
function _arrayLikeToArray(r, a) {
|
|
8740
|
+
(null == a || a > r.length) && (a = r.length);
|
|
8741
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8742
|
+
return n;
|
|
8743
|
+
}
|
|
8744
|
+
function _arrayWithHoles(r) {
|
|
8745
|
+
if (Array.isArray(r)) return r;
|
|
8746
|
+
}
|
|
8747
|
+
function _iterableToArrayLimit(r, l) {
|
|
8748
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
8749
|
+
if (null != t) {
|
|
8750
|
+
var e,
|
|
8751
|
+
n,
|
|
8752
|
+
i,
|
|
8753
|
+
u,
|
|
8754
|
+
a = [],
|
|
8755
|
+
f = true,
|
|
8756
|
+
o = false;
|
|
8757
|
+
try {
|
|
8758
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
8759
|
+
} catch (r) {
|
|
8760
|
+
o = true, n = r;
|
|
8761
|
+
} finally {
|
|
8762
|
+
try {
|
|
8763
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
8764
|
+
} finally {
|
|
8765
|
+
if (o) throw n;
|
|
8766
|
+
}
|
|
8767
|
+
}
|
|
8768
|
+
return a;
|
|
8769
|
+
}
|
|
8770
|
+
}
|
|
8771
|
+
function _nonIterableRest() {
|
|
8772
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
8773
|
+
}
|
|
8774
|
+
function _slicedToArray(r, e) {
|
|
8775
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
8776
|
+
}
|
|
8777
|
+
function _unsupportedIterableToArray(r, a) {
|
|
8778
|
+
if (r) {
|
|
8779
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
8780
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
8781
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
8782
|
+
}
|
|
8783
|
+
}
|
|
8784
|
+
|
|
8785
|
+
const entries = Object.entries,
|
|
8786
|
+
setPrototypeOf = Object.setPrototypeOf,
|
|
8787
|
+
isFrozen = Object.isFrozen,
|
|
8788
|
+
getPrototypeOf = Object.getPrototypeOf,
|
|
8789
|
+
getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
8790
|
+
let freeze = Object.freeze,
|
|
8791
|
+
seal = Object.seal,
|
|
8792
|
+
create = Object.create; // eslint-disable-line import/no-mutable-exports
|
|
8793
|
+
let _ref = typeof Reflect !== 'undefined' && Reflect,
|
|
8794
|
+
apply = _ref.apply,
|
|
8795
|
+
construct = _ref.construct;
|
|
8377
8796
|
if (!freeze) {
|
|
8378
8797
|
freeze = function freeze(x) {
|
|
8379
8798
|
return x;
|
|
@@ -8405,13 +8824,19 @@
|
|
|
8405
8824
|
const arrayPop = unapply(Array.prototype.pop);
|
|
8406
8825
|
const arrayPush = unapply(Array.prototype.push);
|
|
8407
8826
|
const arraySplice = unapply(Array.prototype.splice);
|
|
8827
|
+
const arrayIsArray = Array.isArray;
|
|
8408
8828
|
const stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
8409
8829
|
const stringToString = unapply(String.prototype.toString);
|
|
8410
8830
|
const stringMatch = unapply(String.prototype.match);
|
|
8411
8831
|
const stringReplace = unapply(String.prototype.replace);
|
|
8412
8832
|
const stringIndexOf = unapply(String.prototype.indexOf);
|
|
8413
8833
|
const stringTrim = unapply(String.prototype.trim);
|
|
8834
|
+
const numberToString = unapply(Number.prototype.toString);
|
|
8835
|
+
const booleanToString = unapply(Boolean.prototype.toString);
|
|
8836
|
+
const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
|
|
8837
|
+
const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
|
|
8414
8838
|
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
8839
|
+
const objectToString = unapply(Object.prototype.toString);
|
|
8415
8840
|
const regExpTest = unapply(RegExp.prototype.test);
|
|
8416
8841
|
const typeErrorCreate = unconstruct(TypeError);
|
|
8417
8842
|
/**
|
|
@@ -8461,6 +8886,9 @@
|
|
|
8461
8886
|
// Prevent prototype setters from intercepting set as a this value.
|
|
8462
8887
|
setPrototypeOf(set, null);
|
|
8463
8888
|
}
|
|
8889
|
+
if (!arrayIsArray(array)) {
|
|
8890
|
+
return set;
|
|
8891
|
+
}
|
|
8464
8892
|
let l = array.length;
|
|
8465
8893
|
while (l--) {
|
|
8466
8894
|
let element = array[l];
|
|
@@ -8501,10 +8929,13 @@
|
|
|
8501
8929
|
*/
|
|
8502
8930
|
function clone(object) {
|
|
8503
8931
|
const newObject = create(null);
|
|
8504
|
-
for (const
|
|
8932
|
+
for (const _ref2 of entries(object)) {
|
|
8933
|
+
var _ref3 = _slicedToArray(_ref2, 2);
|
|
8934
|
+
const property = _ref3[0];
|
|
8935
|
+
const value = _ref3[1];
|
|
8505
8936
|
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
8506
8937
|
if (isPropertyExist) {
|
|
8507
|
-
if (
|
|
8938
|
+
if (arrayIsArray(value)) {
|
|
8508
8939
|
newObject[property] = cleanArray(value);
|
|
8509
8940
|
} else if (value && typeof value === 'object' && value.constructor === Object) {
|
|
8510
8941
|
newObject[property] = clone(value);
|
|
@@ -8515,6 +8946,58 @@
|
|
|
8515
8946
|
}
|
|
8516
8947
|
return newObject;
|
|
8517
8948
|
}
|
|
8949
|
+
/**
|
|
8950
|
+
* Convert non-node values into strings without depending on direct property access.
|
|
8951
|
+
*
|
|
8952
|
+
* @param value - The value to stringify.
|
|
8953
|
+
* @returns A string representation of the provided value.
|
|
8954
|
+
*/
|
|
8955
|
+
function stringifyValue(value) {
|
|
8956
|
+
switch (typeof value) {
|
|
8957
|
+
case 'string':
|
|
8958
|
+
{
|
|
8959
|
+
return value;
|
|
8960
|
+
}
|
|
8961
|
+
case 'number':
|
|
8962
|
+
{
|
|
8963
|
+
return numberToString(value);
|
|
8964
|
+
}
|
|
8965
|
+
case 'boolean':
|
|
8966
|
+
{
|
|
8967
|
+
return booleanToString(value);
|
|
8968
|
+
}
|
|
8969
|
+
case 'bigint':
|
|
8970
|
+
{
|
|
8971
|
+
return bigintToString ? bigintToString(value) : '0';
|
|
8972
|
+
}
|
|
8973
|
+
case 'symbol':
|
|
8974
|
+
{
|
|
8975
|
+
return symbolToString ? symbolToString(value) : 'Symbol()';
|
|
8976
|
+
}
|
|
8977
|
+
case 'undefined':
|
|
8978
|
+
{
|
|
8979
|
+
return objectToString(value);
|
|
8980
|
+
}
|
|
8981
|
+
case 'function':
|
|
8982
|
+
case 'object':
|
|
8983
|
+
{
|
|
8984
|
+
if (value === null) {
|
|
8985
|
+
return objectToString(value);
|
|
8986
|
+
}
|
|
8987
|
+
const valueAsRecord = value;
|
|
8988
|
+
const valueToString = lookupGetter(valueAsRecord, 'toString');
|
|
8989
|
+
if (typeof valueToString === 'function') {
|
|
8990
|
+
const stringified = valueToString(valueAsRecord);
|
|
8991
|
+
return typeof stringified === 'string' ? stringified : objectToString(stringified);
|
|
8992
|
+
}
|
|
8993
|
+
return objectToString(value);
|
|
8994
|
+
}
|
|
8995
|
+
default:
|
|
8996
|
+
{
|
|
8997
|
+
return objectToString(value);
|
|
8998
|
+
}
|
|
8999
|
+
}
|
|
9000
|
+
}
|
|
8518
9001
|
/**
|
|
8519
9002
|
* This method automatically checks if the prop is function or getter and behaves accordingly.
|
|
8520
9003
|
*
|
|
@@ -8540,6 +9023,14 @@
|
|
|
8540
9023
|
}
|
|
8541
9024
|
return fallbackValue;
|
|
8542
9025
|
}
|
|
9026
|
+
function isRegex(value) {
|
|
9027
|
+
try {
|
|
9028
|
+
regExpTest(value, '');
|
|
9029
|
+
return true;
|
|
9030
|
+
} catch (_unused) {
|
|
9031
|
+
return false;
|
|
9032
|
+
}
|
|
9033
|
+
}
|
|
8543
9034
|
|
|
8544
9035
|
const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
|
|
8545
9036
|
const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
|
|
@@ -8555,15 +9046,14 @@
|
|
|
8555
9046
|
const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
|
|
8556
9047
|
const text = freeze(['#text']);
|
|
8557
9048
|
|
|
8558
|
-
const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', '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'
|
|
8559
|
-
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']);
|
|
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']);
|
|
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']);
|
|
8560
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']);
|
|
8561
9052
|
const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
|
|
8562
9053
|
|
|
8563
|
-
|
|
8564
|
-
const
|
|
8565
|
-
const
|
|
8566
|
-
const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
|
|
9054
|
+
const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
|
|
9055
|
+
const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
|
|
9056
|
+
const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
|
|
8567
9057
|
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
|
|
8568
9058
|
const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
|
|
8569
9059
|
const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
|
|
@@ -8573,30 +9063,31 @@
|
|
|
8573
9063
|
);
|
|
8574
9064
|
const DOCTYPE_NAME = seal(/^html$/i);
|
|
8575
9065
|
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
9066
|
+
// Markup-significant character probes used by _sanitizeElements.
|
|
9067
|
+
// Shared module-level instances are safe despite the sticky /g flags:
|
|
9068
|
+
// unapply() resets lastIndex for RegExp receivers before every call.
|
|
9069
|
+
const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
|
|
9070
|
+
const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
9071
|
+
const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
9072
|
+
const SELF_CLOSING_TAG = seal(/\/>/i);
|
|
8576
9073
|
|
|
8577
|
-
var EXPRESSIONS = /*#__PURE__*/Object.freeze({
|
|
8578
|
-
__proto__: null,
|
|
8579
|
-
ARIA_ATTR: ARIA_ATTR,
|
|
8580
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE,
|
|
8581
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT,
|
|
8582
|
-
DATA_ATTR: DATA_ATTR,
|
|
8583
|
-
DOCTYPE_NAME: DOCTYPE_NAME,
|
|
8584
|
-
ERB_EXPR: ERB_EXPR,
|
|
8585
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI,
|
|
8586
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
|
|
8587
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR,
|
|
8588
|
-
TMPLIT_EXPR: TMPLIT_EXPR
|
|
8589
|
-
});
|
|
8590
|
-
|
|
8591
|
-
/* eslint-disable @typescript-eslint/indent */
|
|
8592
9074
|
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
|
|
8593
9075
|
const NODE_TYPE = {
|
|
8594
9076
|
element: 1,
|
|
9077
|
+
attribute: 2,
|
|
8595
9078
|
text: 3,
|
|
9079
|
+
cdataSection: 4,
|
|
9080
|
+
entityReference: 5,
|
|
8596
9081
|
// Deprecated
|
|
8597
|
-
|
|
9082
|
+
entityNode: 6,
|
|
9083
|
+
// Deprecated
|
|
9084
|
+
processingInstruction: 7,
|
|
8598
9085
|
comment: 8,
|
|
8599
|
-
document: 9
|
|
9086
|
+
document: 9,
|
|
9087
|
+
documentType: 10,
|
|
9088
|
+
documentFragment: 11,
|
|
9089
|
+
notation: 12 // Deprecated
|
|
9090
|
+
};
|
|
8600
9091
|
const getGlobal = function getGlobal() {
|
|
8601
9092
|
return typeof window === 'undefined' ? null : window;
|
|
8602
9093
|
};
|
|
@@ -8651,10 +9142,25 @@
|
|
|
8651
9142
|
uponSanitizeShadowNode: []
|
|
8652
9143
|
};
|
|
8653
9144
|
};
|
|
9145
|
+
/**
|
|
9146
|
+
* Resolve a set-valued configuration option: a fresh set built from
|
|
9147
|
+
* cfg[key] when it is an own array property (seeded with a clone of
|
|
9148
|
+
* options.base when given, case-normalized via options.transform),
|
|
9149
|
+
* the fallback set otherwise.
|
|
9150
|
+
*
|
|
9151
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
9152
|
+
* @param key the configuration property to read
|
|
9153
|
+
* @param fallback the set to use when the option is absent or not an array
|
|
9154
|
+
* @param options transform and optional base set to merge into
|
|
9155
|
+
* @returns the resolved set
|
|
9156
|
+
*/
|
|
9157
|
+
const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
9158
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
9159
|
+
};
|
|
8654
9160
|
function createDOMPurify() {
|
|
8655
9161
|
let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
|
8656
9162
|
const DOMPurify = root => createDOMPurify(root);
|
|
8657
|
-
DOMPurify.version = '3.4.
|
|
9163
|
+
DOMPurify.version = '3.4.13';
|
|
8658
9164
|
DOMPurify.removed = [];
|
|
8659
9165
|
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
8660
9166
|
// Not running in a browser, provide a factory function
|
|
@@ -8662,28 +9168,30 @@
|
|
|
8662
9168
|
DOMPurify.isSupported = false;
|
|
8663
9169
|
return DOMPurify;
|
|
8664
9170
|
}
|
|
8665
|
-
let
|
|
8666
|
-
document
|
|
8667
|
-
} = window;
|
|
9171
|
+
let document = window.document;
|
|
8668
9172
|
const originalDocument = document;
|
|
8669
9173
|
const currentScript = originalDocument.currentScript;
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
NamedNodeMap
|
|
8677
|
-
HTMLFormElement
|
|
8678
|
-
DOMParser,
|
|
8679
|
-
trustedTypes
|
|
8680
|
-
} = window;
|
|
9174
|
+
window.DocumentFragment;
|
|
9175
|
+
const HTMLTemplateElement = window.HTMLTemplateElement,
|
|
9176
|
+
Node = window.Node,
|
|
9177
|
+
Element = window.Element,
|
|
9178
|
+
NodeFilter = window.NodeFilter,
|
|
9179
|
+
_window$NamedNodeMap = window.NamedNodeMap;
|
|
9180
|
+
_window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
|
|
9181
|
+
window.HTMLFormElement;
|
|
9182
|
+
const DOMParser = window.DOMParser,
|
|
9183
|
+
trustedTypes = window.trustedTypes;
|
|
8681
9184
|
const ElementPrototype = Element.prototype;
|
|
8682
9185
|
const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
|
|
8683
9186
|
const remove = lookupGetter(ElementPrototype, 'remove');
|
|
8684
9187
|
const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
|
|
8685
9188
|
const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
|
|
8686
9189
|
const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
|
|
9190
|
+
const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
|
|
9191
|
+
const getAttributes = lookupGetter(ElementPrototype, 'attributes');
|
|
9192
|
+
const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
|
|
9193
|
+
const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
|
|
9194
|
+
const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, 'ownerDocument') : null;
|
|
8687
9195
|
// As per issue #47, the web-components registry is inherited by a
|
|
8688
9196
|
// new document created via createHTMLDocument. As per the spec
|
|
8689
9197
|
// (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
|
|
@@ -8698,33 +9206,74 @@
|
|
|
8698
9206
|
}
|
|
8699
9207
|
let trustedTypesPolicy;
|
|
8700
9208
|
let emptyHTML = '';
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
9209
|
+
// The instance's own internal Trusted Types policy. Unlike a caller-supplied
|
|
9210
|
+
// `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
|
|
9211
|
+
// on duplicate policy names — and is the only policy allowed to persist
|
|
9212
|
+
// across configurations and survive `clearConfig()`.
|
|
9213
|
+
let defaultTrustedTypesPolicy;
|
|
9214
|
+
let defaultTrustedTypesPolicyResolved = false;
|
|
9215
|
+
// Tracks whether we are already inside a call to the configured Trusted Types
|
|
9216
|
+
// policy (`createHTML` or `createScriptURL`). If a supplied policy callback
|
|
9217
|
+
// itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
|
|
9218
|
+
// re-enter the policy and recurse until the stack overflows. We detect that
|
|
9219
|
+
// re-entry and throw a clear, actionable error instead. The guard is shared
|
|
9220
|
+
// across both callbacks, because either one re-entering `sanitize` triggers
|
|
9221
|
+
// the same unbounded recursion.
|
|
9222
|
+
let IN_TRUSTED_TYPES_POLICY = 0;
|
|
9223
|
+
const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
|
|
9224
|
+
if (IN_TRUSTED_TYPES_POLICY > 0) {
|
|
9225
|
+
throw typeErrorCreate('A configured TRUSTED_TYPES_POLICY callback (createHTML or ' + 'createScriptURL) must not call DOMPurify.sanitize, as that causes ' + 'infinite recursion. Do not pass a policy whose callbacks wrap ' + 'DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted ' + 'Types" section of the README.');
|
|
9226
|
+
}
|
|
9227
|
+
};
|
|
9228
|
+
const _createTrustedHTML = function _createTrustedHTML(html) {
|
|
9229
|
+
_assertNotInTrustedTypesPolicy();
|
|
9230
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
9231
|
+
try {
|
|
9232
|
+
return trustedTypesPolicy.createHTML(html);
|
|
9233
|
+
} finally {
|
|
9234
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
9235
|
+
}
|
|
9236
|
+
};
|
|
9237
|
+
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
9238
|
+
_assertNotInTrustedTypesPolicy();
|
|
9239
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
9240
|
+
try {
|
|
9241
|
+
return trustedTypesPolicy.createScriptURL(scriptUrl);
|
|
9242
|
+
} finally {
|
|
9243
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
9244
|
+
}
|
|
9245
|
+
};
|
|
9246
|
+
// Lazily resolve (and cache) the instance's internal default policy.
|
|
9247
|
+
// Resolution is attempted at most once: a successful `createPolicy` cannot be
|
|
9248
|
+
// repeated (Trusted Types throws on duplicate names), and a failed or
|
|
9249
|
+
// unsupported attempt must not be retried on every parse.
|
|
9250
|
+
const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
|
|
9251
|
+
if (!defaultTrustedTypesPolicyResolved) {
|
|
9252
|
+
defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
9253
|
+
defaultTrustedTypesPolicyResolved = true;
|
|
9254
|
+
}
|
|
9255
|
+
return defaultTrustedTypesPolicy;
|
|
9256
|
+
};
|
|
9257
|
+
const _document = document,
|
|
9258
|
+
implementation = _document.implementation,
|
|
9259
|
+
createNodeIterator = _document.createNodeIterator,
|
|
9260
|
+
createDocumentFragment = _document.createDocumentFragment,
|
|
9261
|
+
getElementsByTagName = _document.getElementsByTagName;
|
|
9262
|
+
const importNode = originalDocument.importNode;
|
|
8710
9263
|
let hooks = _createHooksMap();
|
|
8711
9264
|
/**
|
|
8712
9265
|
* Expose whether this browser supports running the full DOMPurify.
|
|
8713
9266
|
*/
|
|
8714
9267
|
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
|
|
8715
|
-
const
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
|
|
8723
|
-
|
|
8724
|
-
} = EXPRESSIONS;
|
|
8725
|
-
let {
|
|
8726
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
8727
|
-
} = EXPRESSIONS;
|
|
9268
|
+
const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
|
|
9269
|
+
ERB_EXPR$1 = ERB_EXPR,
|
|
9270
|
+
TMPLIT_EXPR$1 = TMPLIT_EXPR,
|
|
9271
|
+
DATA_ATTR$1 = DATA_ATTR,
|
|
9272
|
+
ARIA_ATTR$1 = ARIA_ATTR,
|
|
9273
|
+
IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
|
|
9274
|
+
ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
|
|
9275
|
+
CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
|
|
9276
|
+
let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
|
|
8728
9277
|
/**
|
|
8729
9278
|
* We consider the elements and attributes below to be safe. Ideally
|
|
8730
9279
|
* don't add any new ones but feel free to remove unwanted ones.
|
|
@@ -8801,6 +9350,13 @@
|
|
|
8801
9350
|
let WHOLE_DOCUMENT = false;
|
|
8802
9351
|
/* Track whether config is already set on this instance of DOMPurify. */
|
|
8803
9352
|
let SET_CONFIG = false;
|
|
9353
|
+
/* Pristine allowlist bindings captured at setConfig() time. On the
|
|
9354
|
+
* persistent-config path sanitize() restores the sets from these before
|
|
9355
|
+
* the per-walk hook clone-guard, so a hook's in-call widening cannot
|
|
9356
|
+
* carry across calls. Null until setConfig() is called; reset by
|
|
9357
|
+
* clearConfig(). */
|
|
9358
|
+
let SET_CONFIG_ALLOWED_TAGS = null;
|
|
9359
|
+
let SET_CONFIG_ALLOWED_ATTR = null;
|
|
8804
9360
|
/* Decide if all elements (e.g. style, script) must be children of
|
|
8805
9361
|
* document.body. By default, browsers might move them to document.head */
|
|
8806
9362
|
let FORCE_BODY = false;
|
|
@@ -8843,7 +9399,17 @@
|
|
|
8843
9399
|
let USE_PROFILES = {};
|
|
8844
9400
|
/* Tags to ignore content of when KEEP_CONTENT is true */
|
|
8845
9401
|
let FORBID_CONTENTS = null;
|
|
8846
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
9402
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
9403
|
+
// <selectedcontent> mirrors the selected <option>'s subtree, cloned by
|
|
9404
|
+
// the UA (customizable <select>) — including any on* handlers — and the
|
|
9405
|
+
// engine re-mirrors synchronously whenever a removal changes which
|
|
9406
|
+
// option/selectedcontent is current, even inside DOMPurify's inert
|
|
9407
|
+
// DOMParser document. Hoisting its children on removal re-inserts a fresh
|
|
9408
|
+
// mirror target ahead of the walk, which the engine refills, looping
|
|
9409
|
+
// forever (DoS) and amplifying output. Dropping its content on removal
|
|
9410
|
+
// (rather than hoisting) breaks that cascade; the content is a duplicate
|
|
9411
|
+
// of the option, which is sanitized on its own. See campaign-3 F1/F6.
|
|
9412
|
+
'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
|
|
8847
9413
|
/* Tags that are safe for data: URIs */
|
|
8848
9414
|
let DATA_URI_TAGS = null;
|
|
8849
9415
|
const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
|
|
@@ -8859,8 +9425,10 @@
|
|
|
8859
9425
|
/* Allowed XHTML+XML namespaces */
|
|
8860
9426
|
let ALLOWED_NAMESPACES = null;
|
|
8861
9427
|
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
8862
|
-
|
|
8863
|
-
let
|
|
9428
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
|
|
9429
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
9430
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
|
|
9431
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
|
|
8864
9432
|
// Certain elements are allowed in both SVG and HTML
|
|
8865
9433
|
// namespace. We need to specify them explicitly
|
|
8866
9434
|
// so that they don't get erroneously deleted from
|
|
@@ -8902,15 +9470,33 @@
|
|
|
8902
9470
|
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
|
|
8903
9471
|
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
|
|
8904
9472
|
/* Set configuration parameters */
|
|
8905
|
-
ALLOWED_TAGS =
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
9473
|
+
ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
|
|
9474
|
+
transform: transformCaseFunc
|
|
9475
|
+
});
|
|
9476
|
+
ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
|
|
9477
|
+
transform: transformCaseFunc
|
|
9478
|
+
});
|
|
9479
|
+
ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
|
|
9480
|
+
transform: stringToString
|
|
9481
|
+
});
|
|
9482
|
+
URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
|
|
9483
|
+
transform: transformCaseFunc,
|
|
9484
|
+
base: DEFAULT_URI_SAFE_ATTRIBUTES
|
|
9485
|
+
});
|
|
9486
|
+
DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
|
|
9487
|
+
transform: transformCaseFunc,
|
|
9488
|
+
base: DEFAULT_DATA_URI_TAGS
|
|
9489
|
+
});
|
|
9490
|
+
FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
|
|
9491
|
+
transform: transformCaseFunc
|
|
9492
|
+
});
|
|
9493
|
+
FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
|
|
9494
|
+
transform: transformCaseFunc
|
|
9495
|
+
});
|
|
9496
|
+
FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
|
|
9497
|
+
transform: transformCaseFunc
|
|
9498
|
+
});
|
|
9499
|
+
USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
8914
9500
|
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
|
|
8915
9501
|
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
|
|
8916
9502
|
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
@@ -8926,20 +9512,22 @@
|
|
|
8926
9512
|
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
|
|
8927
9513
|
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
|
|
8928
9514
|
IN_PLACE = cfg.IN_PLACE || false; // Default false
|
|
8929
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP
|
|
8930
|
-
NAMESPACE = cfg.NAMESPACE
|
|
8931
|
-
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS
|
|
8932
|
-
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
9515
|
+
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
|
|
9516
|
+
NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
|
|
9517
|
+
MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS); // Default built-in map
|
|
9518
|
+
HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS); // Default built-in map
|
|
9519
|
+
const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
|
|
9520
|
+
CUSTOM_ELEMENT_HANDLING = create(null);
|
|
9521
|
+
if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
|
|
9522
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
|
|
8936
9523
|
}
|
|
8937
|
-
if (
|
|
8938
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck =
|
|
9524
|
+
if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
|
|
9525
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
|
|
8939
9526
|
}
|
|
8940
|
-
if (
|
|
8941
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements =
|
|
9527
|
+
if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
|
|
9528
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
|
|
8942
9529
|
}
|
|
9530
|
+
seal(CUSTOM_ELEMENT_HANDLING);
|
|
8943
9531
|
if (SAFE_FOR_TEMPLATES) {
|
|
8944
9532
|
ALLOW_DATA_ATTR = false;
|
|
8945
9533
|
}
|
|
@@ -8975,36 +9563,36 @@
|
|
|
8975
9563
|
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
8976
9564
|
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
8977
9565
|
/* Merge configuration parameters */
|
|
8978
|
-
if (cfg
|
|
9566
|
+
if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
|
|
8979
9567
|
if (typeof cfg.ADD_TAGS === 'function') {
|
|
8980
9568
|
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
8981
|
-
} else {
|
|
9569
|
+
} else if (arrayIsArray(cfg.ADD_TAGS)) {
|
|
8982
9570
|
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
8983
9571
|
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
8984
9572
|
}
|
|
8985
9573
|
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
8986
9574
|
}
|
|
8987
9575
|
}
|
|
8988
|
-
if (cfg
|
|
9576
|
+
if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
|
|
8989
9577
|
if (typeof cfg.ADD_ATTR === 'function') {
|
|
8990
9578
|
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
8991
|
-
} else {
|
|
9579
|
+
} else if (arrayIsArray(cfg.ADD_ATTR)) {
|
|
8992
9580
|
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
8993
9581
|
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
8994
9582
|
}
|
|
8995
9583
|
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
8996
9584
|
}
|
|
8997
9585
|
}
|
|
8998
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
9586
|
+
if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
|
|
8999
9587
|
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
9000
9588
|
}
|
|
9001
|
-
if (cfg.FORBID_CONTENTS) {
|
|
9589
|
+
if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
|
|
9002
9590
|
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
9003
9591
|
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
9004
9592
|
}
|
|
9005
9593
|
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
9006
9594
|
}
|
|
9007
|
-
if (cfg.ADD_FORBID_CONTENTS) {
|
|
9595
|
+
if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
|
|
9008
9596
|
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
9009
9597
|
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
9010
9598
|
}
|
|
@@ -9023,6 +9611,13 @@
|
|
|
9023
9611
|
addToSet(ALLOWED_TAGS, ['tbody']);
|
|
9024
9612
|
delete FORBID_TAGS.tbody;
|
|
9025
9613
|
}
|
|
9614
|
+
// Re-derive the active Trusted Types policy from this configuration on
|
|
9615
|
+
// every parse. The active policy must never be sticky closure state that
|
|
9616
|
+
// outlives the config that set it: a caller-supplied policy left in place
|
|
9617
|
+
// after `clearConfig()` — or after a later call that supplied none, or
|
|
9618
|
+
// `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
|
|
9619
|
+
// `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
|
|
9620
|
+
// See GHSA-vxr8-fq34-vvx9.
|
|
9026
9621
|
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
9027
9622
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
|
|
9028
9623
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
@@ -9030,18 +9625,45 @@
|
|
|
9030
9625
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
|
|
9031
9626
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
9032
9627
|
}
|
|
9033
|
-
//
|
|
9628
|
+
// A caller-supplied policy applies to this configuration only.
|
|
9629
|
+
const previousTrustedTypesPolicy = trustedTypesPolicy;
|
|
9034
9630
|
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
9035
|
-
// Sign local variables required by `sanitize`.
|
|
9036
|
-
|
|
9631
|
+
// Sign local variables required by `sanitize`. If the supplied policy's
|
|
9632
|
+
// `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
|
|
9633
|
+
// throws via the re-entrancy guard. Restore the previous policy first so
|
|
9634
|
+
// the instance is not left in a poisoned state. See #1422.
|
|
9635
|
+
try {
|
|
9636
|
+
emptyHTML = _createTrustedHTML('');
|
|
9637
|
+
} catch (error) {
|
|
9638
|
+
trustedTypesPolicy = previousTrustedTypesPolicy;
|
|
9639
|
+
throw error;
|
|
9640
|
+
}
|
|
9641
|
+
} else if (cfg.TRUSTED_TYPES_POLICY === null) {
|
|
9642
|
+
// Explicit opt-out for this call: perform no Trusted Types signing and
|
|
9643
|
+
// create nothing (so a strict `trusted-types` CSP that disallows a
|
|
9644
|
+
// `dompurify` policy can still call `sanitize` from inside its own
|
|
9645
|
+
// policy — see #1422). Resetting to `undefined` rather than a sticky
|
|
9646
|
+
// `null` also drops any previously retained caller policy, so it cannot
|
|
9647
|
+
// resurface on a later call, while still allowing the next config-less
|
|
9648
|
+
// call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
|
|
9649
|
+
trustedTypesPolicy = undefined;
|
|
9650
|
+
emptyHTML = '';
|
|
9037
9651
|
} else {
|
|
9038
|
-
//
|
|
9652
|
+
// No policy supplied: keep the currently active policy if one is set — a
|
|
9653
|
+
// previously supplied policy is intentionally sticky across config-less
|
|
9654
|
+
// calls — otherwise fall back to the instance's own internal policy,
|
|
9655
|
+
// created at most once. (A policy supplied for a *single* call still
|
|
9656
|
+
// lingers by design; what must not linger is a policy whose configuration
|
|
9657
|
+
// has been torn down via `clearConfig()`, which restores the default.)
|
|
9039
9658
|
if (trustedTypesPolicy === undefined) {
|
|
9040
|
-
trustedTypesPolicy =
|
|
9659
|
+
trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
9041
9660
|
}
|
|
9042
|
-
//
|
|
9043
|
-
|
|
9044
|
-
|
|
9661
|
+
// Sign internal variables only when a policy is active. A falsy policy
|
|
9662
|
+
// (Trusted Types unsupported, creation failed, or an explicit opt-out)
|
|
9663
|
+
// leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
|
|
9664
|
+
// a non-policy and throw. See #1422.
|
|
9665
|
+
if (trustedTypesPolicy && typeof emptyHTML === 'string') {
|
|
9666
|
+
emptyHTML = _createTrustedHTML('');
|
|
9045
9667
|
}
|
|
9046
9668
|
}
|
|
9047
9669
|
// Prevent further manipulation of configuration.
|
|
@@ -9056,6 +9678,77 @@
|
|
|
9056
9678
|
* correctly. */
|
|
9057
9679
|
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
9058
9680
|
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
9681
|
+
/**
|
|
9682
|
+
* Namespace rules for an element in the SVG namespace.
|
|
9683
|
+
*
|
|
9684
|
+
* @param tagName the element's lowercase tag name
|
|
9685
|
+
* @param parent the (possibly simulated) parent node
|
|
9686
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9687
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9688
|
+
*/
|
|
9689
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
|
|
9690
|
+
// The only way to switch from HTML namespace to SVG
|
|
9691
|
+
// is via <svg>. If it happens via any other tag, then
|
|
9692
|
+
// it should be killed.
|
|
9693
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9694
|
+
return tagName === 'svg';
|
|
9695
|
+
}
|
|
9696
|
+
// The only way to switch from MathML to SVG is via <svg>
|
|
9697
|
+
// if the parent is either <annotation-xml> or a MathML
|
|
9698
|
+
// text integration point.
|
|
9699
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
9700
|
+
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
9701
|
+
}
|
|
9702
|
+
// We only allow elements that are defined in SVG
|
|
9703
|
+
// spec. All others are disallowed in SVG namespace.
|
|
9704
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
9705
|
+
};
|
|
9706
|
+
/**
|
|
9707
|
+
* Namespace rules for an element in the MathML namespace.
|
|
9708
|
+
*
|
|
9709
|
+
* @param tagName the element's lowercase tag name
|
|
9710
|
+
* @param parent the (possibly simulated) parent node
|
|
9711
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9712
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9713
|
+
*/
|
|
9714
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
|
|
9715
|
+
// The only way to switch from HTML namespace to MathML
|
|
9716
|
+
// is via <math>. If it happens via any other tag, then
|
|
9717
|
+
// it should be killed.
|
|
9718
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9719
|
+
return tagName === 'math';
|
|
9720
|
+
}
|
|
9721
|
+
// The only way to switch from SVG to MathML is via
|
|
9722
|
+
// <math> and HTML integration points
|
|
9723
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
9724
|
+
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
9725
|
+
}
|
|
9726
|
+
// We only allow elements that are defined in MathML
|
|
9727
|
+
// spec. All others are disallowed in MathML namespace.
|
|
9728
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
9729
|
+
};
|
|
9730
|
+
/**
|
|
9731
|
+
* Namespace rules for an element in the HTML namespace.
|
|
9732
|
+
*
|
|
9733
|
+
* @param tagName the element's lowercase tag name
|
|
9734
|
+
* @param parent the (possibly simulated) parent node
|
|
9735
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9736
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9737
|
+
*/
|
|
9738
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
|
|
9739
|
+
// The only way to switch from SVG to HTML is via
|
|
9740
|
+
// HTML integration points, and from MathML to HTML
|
|
9741
|
+
// is via MathML text integration points
|
|
9742
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
9743
|
+
return false;
|
|
9744
|
+
}
|
|
9745
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
9746
|
+
return false;
|
|
9747
|
+
}
|
|
9748
|
+
// We disallow tags that are specific for MathML
|
|
9749
|
+
// or SVG and should never appear in HTML namespace
|
|
9750
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
9751
|
+
};
|
|
9059
9752
|
/**
|
|
9060
9753
|
* @param element a DOM element whose namespace is being checked
|
|
9061
9754
|
* @returns Return false if the element has a
|
|
@@ -9078,51 +9771,13 @@
|
|
|
9078
9771
|
return false;
|
|
9079
9772
|
}
|
|
9080
9773
|
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
9081
|
-
|
|
9082
|
-
// is via <svg>. If it happens via any other tag, then
|
|
9083
|
-
// it should be killed.
|
|
9084
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9085
|
-
return tagName === 'svg';
|
|
9086
|
-
}
|
|
9087
|
-
// The only way to switch from MathML to SVG is via`
|
|
9088
|
-
// svg if parent is either <annotation-xml> or MathML
|
|
9089
|
-
// text integration points.
|
|
9090
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
9091
|
-
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
9092
|
-
}
|
|
9093
|
-
// We only allow elements that are defined in SVG
|
|
9094
|
-
// spec. All others are disallowed in SVG namespace.
|
|
9095
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
9774
|
+
return _checkSvgNamespace(tagName, parent, parentTagName);
|
|
9096
9775
|
}
|
|
9097
9776
|
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
9098
|
-
|
|
9099
|
-
// is via <math>. If it happens via any other tag, then
|
|
9100
|
-
// it should be killed.
|
|
9101
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9102
|
-
return tagName === 'math';
|
|
9103
|
-
}
|
|
9104
|
-
// The only way to switch from SVG to MathML is via
|
|
9105
|
-
// <math> and HTML integration points
|
|
9106
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
9107
|
-
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
9108
|
-
}
|
|
9109
|
-
// We only allow elements that are defined in MathML
|
|
9110
|
-
// spec. All others are disallowed in MathML namespace.
|
|
9111
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
9777
|
+
return _checkMathMlNamespace(tagName, parent, parentTagName);
|
|
9112
9778
|
}
|
|
9113
9779
|
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
9114
|
-
|
|
9115
|
-
// HTML integration points, and from MathML to HTML
|
|
9116
|
-
// is via MathML text integration points
|
|
9117
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
9118
|
-
return false;
|
|
9119
|
-
}
|
|
9120
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
9121
|
-
return false;
|
|
9122
|
-
}
|
|
9123
|
-
// We disallow tags that are specific for MathML
|
|
9124
|
-
// or SVG and should never appear in HTML namespace
|
|
9125
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
9780
|
+
return _checkHtmlNamespace(tagName, parent, parentTagName);
|
|
9126
9781
|
}
|
|
9127
9782
|
// For XHTML and XML documents that support custom namespaces
|
|
9128
9783
|
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
@@ -9147,7 +9802,81 @@
|
|
|
9147
9802
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
9148
9803
|
getParentNode(node).removeChild(node);
|
|
9149
9804
|
} catch (_) {
|
|
9805
|
+
/* The normal detach failed — this is reached for a parentless node
|
|
9806
|
+
(getParentNode() is null, so .removeChild throws). Element.prototype
|
|
9807
|
+
.remove() is itself a spec no-op on a parentless node, so a recorded
|
|
9808
|
+
"removal" would otherwise hand the caller back an intact,
|
|
9809
|
+
payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
|
|
9810
|
+
the style-with-element-child rule decided to kill). Fail closed by
|
|
9811
|
+
throwing — exactly as a clobbered root does at the IN_PLACE entry —
|
|
9812
|
+
rather than trying to "neutralize" the node via its own methods.
|
|
9813
|
+
Neutralizing would mean calling getAttributeNames()/removeAttribute()
|
|
9814
|
+
on the node, both of which a <form> root can clobber via a named child
|
|
9815
|
+
(and _isClobbered does not even probe getAttributeNames), so the
|
|
9816
|
+
neutralize step could itself be silently defeated, leaving the payload
|
|
9817
|
+
intact. A throw touches only the cached, clobber-safe remove() and
|
|
9818
|
+
getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
|
|
9819
|
+
to every root-kill reason. REPORT-3.
|
|
9820
|
+
This lives inside the catch, so it never fires for a normally-removed
|
|
9821
|
+
in-tree node: those have a parent, removeChild() succeeds, and the
|
|
9822
|
+
catch is not entered. Only a kept (parentless) root reaches here. */
|
|
9150
9823
|
remove(node);
|
|
9824
|
+
if (!getParentNode(node)) {
|
|
9825
|
+
throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
|
|
9826
|
+
}
|
|
9827
|
+
}
|
|
9828
|
+
};
|
|
9829
|
+
/**
|
|
9830
|
+
* _neutralizeRoot
|
|
9831
|
+
*
|
|
9832
|
+
* Fail-closed teardown of an in-place root after the sanitize walk aborts
|
|
9833
|
+
* (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
|
|
9834
|
+
* custom element's reaction detaches a node so `_forceRemove`'s deliberate
|
|
9835
|
+
* parentless guard throws, or any other re-entrant engine mutation — would
|
|
9836
|
+
* otherwise leave the caller's *live* tree half-sanitized, with everything
|
|
9837
|
+
* after the abort point still carrying its handlers. There is no safe way
|
|
9838
|
+
* to resume the walk (the tree mutated under us), so we strip the root bare:
|
|
9839
|
+
* remove every child and every attribute, then let the caller's catch see
|
|
9840
|
+
* the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
|
|
9841
|
+
* getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
|
|
9842
|
+
*
|
|
9843
|
+
* @param root the in-place root to empty
|
|
9844
|
+
*/
|
|
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);
|
|
9853
|
+
const childNodes = getChildNodes(root);
|
|
9854
|
+
if (childNodes) {
|
|
9855
|
+
const snapshot = [];
|
|
9856
|
+
arrayForEach(childNodes, child => {
|
|
9857
|
+
arrayPush(snapshot, child);
|
|
9858
|
+
});
|
|
9859
|
+
arrayForEach(snapshot, child => {
|
|
9860
|
+
try {
|
|
9861
|
+
remove(child);
|
|
9862
|
+
} catch (_) {
|
|
9863
|
+
/* Best-effort teardown; a still-attached child is handled below */
|
|
9864
|
+
}
|
|
9865
|
+
});
|
|
9866
|
+
}
|
|
9867
|
+
const attributes = getAttributes(root);
|
|
9868
|
+
if (attributes) {
|
|
9869
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
9870
|
+
const attribute = attributes[i];
|
|
9871
|
+
const name = attribute && attribute.name;
|
|
9872
|
+
if (typeof name === 'string') {
|
|
9873
|
+
try {
|
|
9874
|
+
root.removeAttribute(name);
|
|
9875
|
+
} catch (_) {
|
|
9876
|
+
/* Clobbered removeAttribute — ignore (fail-closed best effort) */
|
|
9877
|
+
}
|
|
9878
|
+
}
|
|
9879
|
+
}
|
|
9151
9880
|
}
|
|
9152
9881
|
};
|
|
9153
9882
|
/**
|
|
@@ -9182,6 +9911,148 @@
|
|
|
9182
9911
|
}
|
|
9183
9912
|
}
|
|
9184
9913
|
};
|
|
9914
|
+
/**
|
|
9915
|
+
* _stripDisallowedAttributes
|
|
9916
|
+
*
|
|
9917
|
+
* Removes every attribute the active configuration does not allow from a
|
|
9918
|
+
* single element, using the same allowlist as the main attribute pass (so
|
|
9919
|
+
* `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
|
|
9920
|
+
* neutralise nodes that are being discarded from an in-place tree.
|
|
9921
|
+
*
|
|
9922
|
+
* @param element the element to strip
|
|
9923
|
+
*/
|
|
9924
|
+
const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
|
|
9925
|
+
const attributes = getAttributes(element);
|
|
9926
|
+
if (!attributes) {
|
|
9927
|
+
return;
|
|
9928
|
+
}
|
|
9929
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
9930
|
+
const attribute = attributes[i];
|
|
9931
|
+
const name = attribute && attribute.name;
|
|
9932
|
+
if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
|
|
9933
|
+
continue;
|
|
9934
|
+
}
|
|
9935
|
+
try {
|
|
9936
|
+
element.removeAttribute(name);
|
|
9937
|
+
} catch (_) {
|
|
9938
|
+
/* Clobbered removeAttribute on a doomed node — ignore */
|
|
9939
|
+
}
|
|
9940
|
+
}
|
|
9941
|
+
};
|
|
9942
|
+
/**
|
|
9943
|
+
* _neutralizeSubtree
|
|
9944
|
+
*
|
|
9945
|
+
* Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
|
|
9946
|
+
* move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
|
|
9947
|
+
* namespace, comment, processing-instruction and KEEP_CONTENT:false removals
|
|
9948
|
+
* all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
|
|
9949
|
+
* those dropped nodes are detached from the caller's LIVE tree but a
|
|
9950
|
+
* handler-bearing original among them (an `<img onerror>`/`<video>` that was
|
|
9951
|
+
* loading) keeps its queued resource event, which fires in page scope after
|
|
9952
|
+
* sanitize returns. This walks a removed subtree and strips every attribute
|
|
9953
|
+
* the active configuration does not allow — so `on*` handlers are cancelled
|
|
9954
|
+
* through the SAME allowlist that governs kept nodes, not a separate `/^on/`
|
|
9955
|
+
* blocklist. Run synchronously before sanitize returns, i.e. before any
|
|
9956
|
+
* queued event can fire. Hook-free by design: these nodes leave the output,
|
|
9957
|
+
* so firing attribute hooks for them would be surprising. Clobber-safe reads;
|
|
9958
|
+
* a doomed clobbered node may shadow `removeAttribute` (its own attributes are
|
|
9959
|
+
* irrelevant — it is discarded — while its non-clobbered descendants, e.g.
|
|
9960
|
+
* the `<img>`, are reached and scrubbed).
|
|
9961
|
+
*
|
|
9962
|
+
* @param root the root of a removed subtree to neutralise
|
|
9963
|
+
*/
|
|
9964
|
+
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
9965
|
+
const stack = [root];
|
|
9966
|
+
while (stack.length > 0) {
|
|
9967
|
+
const node = stack.pop();
|
|
9968
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
9969
|
+
if (nodeType === NODE_TYPE.element) {
|
|
9970
|
+
_stripDisallowedAttributes(node);
|
|
9971
|
+
}
|
|
9972
|
+
const childNodes = getChildNodes(node);
|
|
9973
|
+
if (childNodes) {
|
|
9974
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
9975
|
+
stack.push(childNodes[i]);
|
|
9976
|
+
}
|
|
9977
|
+
}
|
|
9978
|
+
}
|
|
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
|
+
};
|
|
9185
10056
|
/**
|
|
9186
10057
|
* _initDocument
|
|
9187
10058
|
*
|
|
@@ -9203,7 +10074,7 @@
|
|
|
9203
10074
|
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
|
|
9204
10075
|
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
|
|
9205
10076
|
}
|
|
9206
|
-
const dirtyPayload = trustedTypesPolicy ?
|
|
10077
|
+
const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
|
|
9207
10078
|
/*
|
|
9208
10079
|
* Use the DOMParser API by default, fallback later if needs be
|
|
9209
10080
|
* DOMParser not work for svg when has multiple root element.
|
|
@@ -9239,33 +10110,297 @@
|
|
|
9239
10110
|
* @return The created NodeIterator
|
|
9240
10111
|
*/
|
|
9241
10112
|
const _createNodeIterator = function _createNodeIterator(root) {
|
|
9242
|
-
|
|
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,
|
|
9243
10124
|
// eslint-disable-next-line no-bitwise
|
|
9244
10125
|
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
9245
10126
|
};
|
|
10127
|
+
/**
|
|
10128
|
+
* Replace template expression syntax (mustache, ERB, template
|
|
10129
|
+
* literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
|
|
10130
|
+
* sites. Order matters: mustache, then ERB, then template literal.
|
|
10131
|
+
*
|
|
10132
|
+
* @param value the string to scrub
|
|
10133
|
+
* @returns the scrubbed string
|
|
10134
|
+
*/
|
|
10135
|
+
const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
|
|
10136
|
+
value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
|
|
10137
|
+
value = stringReplace(value, ERB_EXPR$1, ' ');
|
|
10138
|
+
value = stringReplace(value, TMPLIT_EXPR$1, ' ');
|
|
10139
|
+
return value;
|
|
10140
|
+
};
|
|
10141
|
+
/**
|
|
10142
|
+
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
|
|
10143
|
+
* character data of an element subtree. Used as the final safety net for
|
|
10144
|
+
* SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
|
|
10145
|
+
* which only form after text-node normalization (e.g. fragments split across
|
|
10146
|
+
* stripped elements) cannot survive into a template-evaluating framework.
|
|
10147
|
+
*
|
|
10148
|
+
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
|
|
10149
|
+
* in place rather than round-tripping through innerHTML. This preserves
|
|
10150
|
+
* descendant node references (important for IN_PLACE callers), avoids a
|
|
10151
|
+
* serialize/reparse cycle, and reads literal character data — which means
|
|
10152
|
+
* `<%...%>` in text content matches the ERB regex against its real bytes
|
|
10153
|
+
* instead of the HTML-entity-escaped form innerHTML would produce.
|
|
10154
|
+
*
|
|
10155
|
+
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
|
|
10156
|
+
* attributes is performed during the per-node `_sanitizeAttributes` pass.
|
|
10157
|
+
*
|
|
10158
|
+
* @param node The root element whose character data should be scrubbed.
|
|
10159
|
+
*/
|
|
10160
|
+
const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
|
|
10161
|
+
var _node$querySelectorAl;
|
|
10162
|
+
node.normalize();
|
|
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,
|
|
10168
|
+
// eslint-disable-next-line no-bitwise
|
|
10169
|
+
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
10170
|
+
let currentNode = walker.nextNode();
|
|
10171
|
+
while (currentNode) {
|
|
10172
|
+
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
10173
|
+
currentNode = walker.nextNode();
|
|
10174
|
+
}
|
|
10175
|
+
// NodeIterator does not descend into <template>.content per the DOM spec,
|
|
10176
|
+
// so we must explicitly recurse into each template's content fragment,
|
|
10177
|
+
// mirroring the approach used by _sanitizeShadowDOM.
|
|
10178
|
+
const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
|
|
10179
|
+
if (templates) {
|
|
10180
|
+
arrayForEach(templates, tmpl => {
|
|
10181
|
+
if (_isDocumentFragment(tmpl.content)) {
|
|
10182
|
+
_scrubTemplateExpressions2(tmpl.content);
|
|
10183
|
+
}
|
|
10184
|
+
});
|
|
10185
|
+
}
|
|
10186
|
+
};
|
|
9246
10187
|
/**
|
|
9247
10188
|
* _isClobbered
|
|
9248
10189
|
*
|
|
10190
|
+
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
|
|
10191
|
+
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
10192
|
+
* `name` attribute matching a prototype property shadows that property
|
|
10193
|
+
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
10194
|
+
* during attribute sanitization to refuse clobbered forms.
|
|
10195
|
+
*
|
|
9249
10196
|
* @param element element to check for clobbering attacks
|
|
9250
10197
|
* @return true if clobbered, false if safe
|
|
9251
10198
|
*/
|
|
9252
10199
|
const _isClobbered = function _isClobbered(element) {
|
|
9253
|
-
|
|
10200
|
+
// Realm-independent tag-name probe. If we can't determine the tag
|
|
10201
|
+
// name at all, we can't reason about clobbering — return false
|
|
10202
|
+
// (the caller's other defences still apply).
|
|
10203
|
+
const realTagName = getNodeName ? getNodeName(element) : null;
|
|
10204
|
+
if (typeof realTagName !== 'string') {
|
|
10205
|
+
return false;
|
|
10206
|
+
}
|
|
10207
|
+
if (transformCaseFunc(realTagName) !== 'form') {
|
|
10208
|
+
return false;
|
|
10209
|
+
}
|
|
10210
|
+
return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
|
|
10211
|
+
// Realm-safe NamedNodeMap detection: equality against the cached
|
|
10212
|
+
// prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
|
|
10213
|
+
// makes the direct read diverge from the cached read; a clean form
|
|
10214
|
+
// (same-realm OR foreign-realm) has both reads pointing at the same
|
|
10215
|
+
// canonical NamedNodeMap.
|
|
10216
|
+
element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
|
|
10217
|
+
// NodeType clobbering probe. Cached Node.prototype.nodeType getter
|
|
10218
|
+
// returns the integer 1 for any Element regardless of realm; direct
|
|
10219
|
+
// read on a clobbered form (e.g. <input name="nodeType">) returns
|
|
10220
|
+
// the named child element. Cheap addition — nodeType is read from
|
|
10221
|
+
// an internal slot, no serialization cost — and removes a residual
|
|
10222
|
+
// clobbering surface used by several mXSS / PI / comment branches
|
|
10223
|
+
// in _sanitizeElements that compare currentNode.nodeType directly.
|
|
10224
|
+
element.nodeType !== getNodeType(element) ||
|
|
10225
|
+
// HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
|
|
10226
|
+
// "childNodes" shadows the prototype getter. Direct reads of
|
|
10227
|
+
// form.childNodes from a clobbered form return the named child
|
|
10228
|
+
// instead of the real NodeList, so any walk that reads it directly
|
|
10229
|
+
// skips the form's real children. Compare the direct read to the
|
|
10230
|
+
// cached Node.prototype getter — when the form's named-property
|
|
10231
|
+
// getter intercepts the read, the two values differ and we flag
|
|
10232
|
+
// the form. This catches every clobbering child type (input,
|
|
10233
|
+
// select, etc.) regardless of whether the named child happens to
|
|
10234
|
+
// carry a numeric .length, which a typeof-based probe would miss
|
|
10235
|
+
// (e.g. HTMLSelectElement.length is a defined unsigned-long).
|
|
10236
|
+
element.childNodes !== getChildNodes(element);
|
|
9254
10237
|
};
|
|
9255
10238
|
/**
|
|
9256
|
-
* Checks whether the given
|
|
10239
|
+
* Checks whether the given value is a DocumentFragment from any realm.
|
|
10240
|
+
*
|
|
10241
|
+
* The realm-independent replacement reads `nodeType` through the cached
|
|
10242
|
+
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
|
|
10243
|
+
* constant (11). nodeType is a numeric value resolved from the node's
|
|
10244
|
+
* internal slot, identical across realms for the same kind of node.
|
|
10245
|
+
*
|
|
10246
|
+
* @param value object to check
|
|
10247
|
+
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
10248
|
+
*/
|
|
10249
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
10250
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
10251
|
+
return false;
|
|
10252
|
+
}
|
|
10253
|
+
try {
|
|
10254
|
+
return getNodeType(value) === NODE_TYPE.documentFragment;
|
|
10255
|
+
} catch (_) {
|
|
10256
|
+
return false;
|
|
10257
|
+
}
|
|
10258
|
+
};
|
|
10259
|
+
/**
|
|
10260
|
+
* Checks whether the given object is a DOM node, including nodes that
|
|
10261
|
+
* originate from a different window/realm (e.g. an iframe's
|
|
10262
|
+
* contentDocument). The previous `value instanceof Node` check was
|
|
10263
|
+
* realm-bound: nodes from a different window failed it, causing
|
|
10264
|
+
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
10265
|
+
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
9257
10266
|
*
|
|
9258
10267
|
* @param value object to check whether it's a DOM node
|
|
9259
|
-
* @return true
|
|
10268
|
+
* @return true if value is a DOM node from any realm
|
|
9260
10269
|
*/
|
|
9261
10270
|
const _isNode = function _isNode(value) {
|
|
9262
|
-
|
|
10271
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
10272
|
+
return false;
|
|
10273
|
+
}
|
|
10274
|
+
try {
|
|
10275
|
+
return typeof getNodeType(value) === 'number';
|
|
10276
|
+
} catch (_) {
|
|
10277
|
+
return false;
|
|
10278
|
+
}
|
|
9263
10279
|
};
|
|
9264
10280
|
function _executeHooks(hooks, currentNode, data) {
|
|
10281
|
+
if (hooks.length === 0) {
|
|
10282
|
+
return;
|
|
10283
|
+
}
|
|
9265
10284
|
arrayForEach(hooks, hook => {
|
|
9266
10285
|
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
9267
10286
|
});
|
|
9268
10287
|
}
|
|
10288
|
+
/**
|
|
10289
|
+
* Structural-threat checks that condemn a node regardless of the
|
|
10290
|
+
* allowlists: mXSS via namespace confusion, risky CSS construction,
|
|
10291
|
+
* processing instructions, markup-bearing comments. Pure predicate;
|
|
10292
|
+
* the caller removes. Check order is load-bearing.
|
|
10293
|
+
*
|
|
10294
|
+
* @param currentNode the node to inspect
|
|
10295
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
10296
|
+
* @return true if the node must be removed
|
|
10297
|
+
*/
|
|
10298
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
10299
|
+
/* Detect mXSS attempts abusing namespace confusion */
|
|
10300
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
|
|
10301
|
+
return true;
|
|
10302
|
+
}
|
|
10303
|
+
/* Remove risky CSS construction leading to mXSS */
|
|
10304
|
+
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
10305
|
+
return true;
|
|
10306
|
+
}
|
|
10307
|
+
/* Remove any occurrence of processing instructions */
|
|
10308
|
+
if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
|
|
10309
|
+
return true;
|
|
10310
|
+
}
|
|
10311
|
+
/* Remove any kind of possibly harmful comments */
|
|
10312
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
|
|
10313
|
+
return true;
|
|
10314
|
+
}
|
|
10315
|
+
return false;
|
|
10316
|
+
};
|
|
10317
|
+
/**
|
|
10318
|
+
* Handle a node whose tag is forbidden or not allowlisted: keep
|
|
10319
|
+
* allowed custom elements (false return exits _sanitizeElements
|
|
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).
|
|
10329
|
+
*
|
|
10330
|
+
* @param currentNode the disallowed node
|
|
10331
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
10332
|
+
* @return true if the node was removed, false if kept
|
|
10333
|
+
*/
|
|
10334
|
+
const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
|
|
10335
|
+
/* Check if we have a custom element to handle */
|
|
10336
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
10337
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
10338
|
+
return false;
|
|
10339
|
+
}
|
|
10340
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
10341
|
+
return false;
|
|
10342
|
+
}
|
|
10343
|
+
}
|
|
10344
|
+
/* Keep content except for bad-listed elements.
|
|
10345
|
+
Use the cached prototype getters exclusively — the previous code
|
|
10346
|
+
had `|| currentNode.parentNode` / `|| currentNode.childNodes`
|
|
10347
|
+
fallbacks, but the cached getters always return the canonical
|
|
10348
|
+
value (or null for a real parent-less node), so the fallback
|
|
10349
|
+
path was dead in safe cases and a clobbering surface in unsafe
|
|
10350
|
+
ones. Falsy cached results stay falsy; the `if (childNodes &&
|
|
10351
|
+
parentNode)` check already gates correctly. */
|
|
10352
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
10353
|
+
const parentNode = getParentNode(currentNode);
|
|
10354
|
+
const childNodes = getChildNodes(currentNode);
|
|
10355
|
+
if (childNodes && parentNode) {
|
|
10356
|
+
const childCount = childNodes.length;
|
|
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.
|
|
10372
|
+
`childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
|
|
10373
|
+
valid whether we move (drops the trailing entry) or clone (leaves
|
|
10374
|
+
the list intact). */
|
|
10375
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
10376
|
+
const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
|
|
10377
|
+
parentNode.insertBefore(hoisted, getNextSibling(currentNode));
|
|
10378
|
+
}
|
|
10379
|
+
}
|
|
10380
|
+
}
|
|
10381
|
+
_forceRemove(currentNode);
|
|
10382
|
+
return true;
|
|
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
|
+
};
|
|
9269
10404
|
/**
|
|
9270
10405
|
* _sanitizeElements
|
|
9271
10406
|
*
|
|
@@ -9275,86 +10410,112 @@
|
|
|
9275
10410
|
* @param currentNode to check for permission to exist
|
|
9276
10411
|
* @return true if node was killed, false if left alive
|
|
9277
10412
|
*/
|
|
9278
|
-
|
|
9279
|
-
|
|
10413
|
+
// eslint-disable-next-line complexity
|
|
10414
|
+
const _sanitizeElements = function _sanitizeElements(currentNode, root) {
|
|
9280
10415
|
/* Execute a hook if present */
|
|
9281
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
|
+
}
|
|
9282
10427
|
/* Check if element is clobbered or can clobber */
|
|
9283
10428
|
if (_isClobbered(currentNode)) {
|
|
9284
10429
|
_forceRemove(currentNode);
|
|
9285
10430
|
return true;
|
|
9286
10431
|
}
|
|
9287
10432
|
/* Now let's check the element's type and name */
|
|
9288
|
-
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
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);
|
|
9289
10440
|
/* Execute a hook if present */
|
|
9290
10441
|
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
9291
10442
|
tagName,
|
|
9292
10443
|
allowedTags: ALLOWED_TAGS
|
|
9293
10444
|
});
|
|
9294
|
-
/*
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
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
|
+
}
|
|
9307
10473
|
return true;
|
|
9308
10474
|
}
|
|
9309
|
-
/* Remove
|
|
9310
|
-
if (
|
|
10475
|
+
/* Remove mXSS vectors, processing instructions and risky comments */
|
|
10476
|
+
if (_isUnsafeNode(currentNode, tagName)) {
|
|
9311
10477
|
_forceRemove(currentNode);
|
|
9312
10478
|
return true;
|
|
9313
10479
|
}
|
|
9314
10480
|
/* Remove element if anything forbids its presence */
|
|
9315
10481
|
if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
const childCount = childNodes.length;
|
|
9331
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
|
9332
|
-
const childClone = cloneNode(childNodes[i], true);
|
|
9333
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
9334
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
9335
|
-
}
|
|
9336
|
-
}
|
|
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);
|
|
9337
10496
|
}
|
|
9338
|
-
|
|
9339
|
-
return true;
|
|
10497
|
+
return removed;
|
|
9340
10498
|
}
|
|
9341
|
-
/* Check whether element has a valid namespace
|
|
9342
|
-
|
|
10499
|
+
/* Check whether element has a valid namespace.
|
|
10500
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
|
|
10501
|
+
nodeType getter rather than `instanceof Element`, which is realm-
|
|
10502
|
+
bound and short-circuits to false for any node minted in a different
|
|
10503
|
+
realm — letting a foreign-realm element with a forbidden namespace
|
|
10504
|
+
slip past the namespace check entirely. */
|
|
10505
|
+
const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
|
|
10506
|
+
if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
9343
10507
|
_forceRemove(currentNode);
|
|
9344
10508
|
return true;
|
|
9345
10509
|
}
|
|
9346
10510
|
/* Make sure that older browsers don't get fallback-tag mXSS */
|
|
9347
|
-
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(
|
|
10511
|
+
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
|
|
9348
10512
|
_forceRemove(currentNode);
|
|
9349
10513
|
return true;
|
|
9350
10514
|
}
|
|
9351
10515
|
/* Sanitize element content to be template-safe */
|
|
9352
10516
|
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
9353
10517
|
/* Get the element's text content */
|
|
9354
|
-
content = currentNode.textContent;
|
|
9355
|
-
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
9356
|
-
content = stringReplace(content, expr, ' ');
|
|
9357
|
-
});
|
|
10518
|
+
const content = _stripTemplateExpressions(currentNode.textContent);
|
|
9358
10519
|
if (currentNode.textContent !== content) {
|
|
9359
10520
|
arrayPush(DOMPurify.removed, {
|
|
9360
10521
|
element: currentNode.cloneNode()
|
|
@@ -9380,15 +10541,43 @@
|
|
|
9380
10541
|
if (FORBID_ATTR[lcName]) {
|
|
9381
10542
|
return false;
|
|
9382
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
|
+
}
|
|
9383
10571
|
/* Make sure attribute cannot clobber */
|
|
9384
10572
|
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
9385
10573
|
return false;
|
|
9386
10574
|
}
|
|
10575
|
+
const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
|
|
9387
10576
|
/* Allow valid data-* attributes: At least one character after "-"
|
|
9388
10577
|
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
9389
10578
|
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
9390
10579
|
We don't need to check the value; it's always URI safe. */
|
|
9391
|
-
if (ALLOW_DATA_ATTR &&
|
|
10580
|
+
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
|
|
9392
10581
|
if (
|
|
9393
10582
|
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
9394
10583
|
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
@@ -9400,11 +10589,15 @@
|
|
|
9400
10589
|
return false;
|
|
9401
10590
|
}
|
|
9402
10591
|
/* Check value is safe. First, is attr inert? If so, is safe */
|
|
9403
|
-
} else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
|
|
10592
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if (value) {
|
|
9404
10593
|
return false;
|
|
9405
10594
|
} else ;
|
|
9406
10595
|
return true;
|
|
9407
10596
|
};
|
|
10597
|
+
/* Names the HTML spec reserves from valid-custom-element-name; these must
|
|
10598
|
+
* never be treated as basic custom elements even when a permissive
|
|
10599
|
+
* CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
|
|
10600
|
+
const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ['annotation-xml', 'color-profile', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'missing-glyph']);
|
|
9408
10601
|
/**
|
|
9409
10602
|
* _isBasicCustomElement
|
|
9410
10603
|
* checks if at least one dash is included in tagName, and it's not the first char
|
|
@@ -9414,7 +10607,64 @@
|
|
|
9414
10607
|
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
9415
10608
|
*/
|
|
9416
10609
|
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
9417
|
-
return tagName
|
|
10610
|
+
return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
|
|
10611
|
+
};
|
|
10612
|
+
/**
|
|
10613
|
+
* Wrap an attribute value in the matching Trusted Types object when
|
|
10614
|
+
* the active policy requires it. Namespaced attributes pass through
|
|
10615
|
+
* unchanged (no TT support yet, see
|
|
10616
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
|
|
10617
|
+
*
|
|
10618
|
+
* @param lcTag lowercase tag name of the containing element
|
|
10619
|
+
* @param lcName lowercase attribute name
|
|
10620
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
10621
|
+
* @param value the attribute value to wrap
|
|
10622
|
+
* @return the value, wrapped when Trusted Types demand it
|
|
10623
|
+
*/
|
|
10624
|
+
const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
|
|
10625
|
+
if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
|
|
10626
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
10627
|
+
case 'TrustedHTML':
|
|
10628
|
+
{
|
|
10629
|
+
return _createTrustedHTML(value);
|
|
10630
|
+
}
|
|
10631
|
+
case 'TrustedScriptURL':
|
|
10632
|
+
{
|
|
10633
|
+
return _createTrustedScriptURL(value);
|
|
10634
|
+
}
|
|
10635
|
+
}
|
|
10636
|
+
}
|
|
10637
|
+
return value;
|
|
10638
|
+
};
|
|
10639
|
+
/**
|
|
10640
|
+
* Write a modified attribute value back onto the element. On
|
|
10641
|
+
* success, re-probe for clobbering introduced by the new value and
|
|
10642
|
+
* remove the element when found; otherwise pop the removal entry
|
|
10643
|
+
* recorded by the earlier _removeAttribute (long-standing pairing
|
|
10644
|
+
* with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
|
|
10645
|
+
* failure, remove the attribute instead.
|
|
10646
|
+
*
|
|
10647
|
+
* @param currentNode the element carrying the attribute
|
|
10648
|
+
* @param name the attribute name as present on the element
|
|
10649
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
10650
|
+
* @param value the new attribute value
|
|
10651
|
+
*/
|
|
10652
|
+
const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
|
|
10653
|
+
try {
|
|
10654
|
+
if (namespaceURI) {
|
|
10655
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
10656
|
+
} else {
|
|
10657
|
+
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
10658
|
+
currentNode.setAttribute(name, value);
|
|
10659
|
+
}
|
|
10660
|
+
if (_isClobbered(currentNode)) {
|
|
10661
|
+
_forceRemove(currentNode);
|
|
10662
|
+
} else {
|
|
10663
|
+
arrayPop(DOMPurify.removed);
|
|
10664
|
+
}
|
|
10665
|
+
} catch (_) {
|
|
10666
|
+
_removeAttribute(name, currentNode);
|
|
10667
|
+
}
|
|
9418
10668
|
};
|
|
9419
10669
|
/**
|
|
9420
10670
|
* _sanitizeAttributes
|
|
@@ -9429,13 +10679,14 @@
|
|
|
9429
10679
|
const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
9430
10680
|
/* Execute a hook if present */
|
|
9431
10681
|
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
9432
|
-
const
|
|
9433
|
-
attributes
|
|
9434
|
-
} = currentNode;
|
|
10682
|
+
const attributes = currentNode.attributes;
|
|
9435
10683
|
/* Check if we have attributes; if not we might have a text node */
|
|
9436
10684
|
if (!attributes || _isClobbered(currentNode)) {
|
|
9437
10685
|
return;
|
|
9438
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);
|
|
9439
10690
|
const hookEvent = {
|
|
9440
10691
|
attrName: '',
|
|
9441
10692
|
attrValue: '',
|
|
@@ -9444,14 +10695,13 @@
|
|
|
9444
10695
|
forceKeepAttr: undefined
|
|
9445
10696
|
};
|
|
9446
10697
|
let l = attributes.length;
|
|
10698
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
9447
10699
|
/* Go backwards over all attributes; safely remove bad ones */
|
|
9448
10700
|
while (l--) {
|
|
9449
10701
|
const attr = attributes[l];
|
|
9450
|
-
const
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
value: attrValue
|
|
9454
|
-
} = attr;
|
|
10702
|
+
const name = attr.name,
|
|
10703
|
+
namespaceURI = attr.namespaceURI,
|
|
10704
|
+
attrValue = attr.value;
|
|
9455
10705
|
const lcName = transformCaseFunc(name);
|
|
9456
10706
|
const initValue = attrValue;
|
|
9457
10707
|
let value = name === 'value' ? initValue : stringTrim(initValue);
|
|
@@ -9465,12 +10715,14 @@
|
|
|
9465
10715
|
/* Full DOM Clobbering protection via namespace isolation,
|
|
9466
10716
|
* Prefix id and name attributes with `user-content-`
|
|
9467
10717
|
*/
|
|
9468
|
-
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
|
|
10718
|
+
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
|
|
9469
10719
|
// Remove the attribute with this value
|
|
9470
10720
|
_removeAttribute(name, currentNode);
|
|
9471
10721
|
// Prefix the value and later re-create the attribute with the sanitized value
|
|
9472
10722
|
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
9473
10723
|
}
|
|
10724
|
+
// Else: already prefixed, leave the attribute alone — the prefix is
|
|
10725
|
+
// itself the clobbering protection, and re-applying it is incorrect.
|
|
9474
10726
|
/* Work around a security issue with comments inside attributes */
|
|
9475
10727
|
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
9476
10728
|
_removeAttribute(name, currentNode);
|
|
@@ -9481,7 +10733,7 @@
|
|
|
9481
10733
|
_removeAttribute(name, currentNode);
|
|
9482
10734
|
continue;
|
|
9483
10735
|
}
|
|
9484
|
-
/* Did the hooks
|
|
10736
|
+
/* Did the hooks force-keep the attribute? */
|
|
9485
10737
|
if (hookEvent.forceKeepAttr) {
|
|
9486
10738
|
continue;
|
|
9487
10739
|
}
|
|
@@ -9491,56 +10743,24 @@
|
|
|
9491
10743
|
continue;
|
|
9492
10744
|
}
|
|
9493
10745
|
/* Work around a security issue in jQuery 3.0 */
|
|
9494
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(
|
|
10746
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
|
|
9495
10747
|
_removeAttribute(name, currentNode);
|
|
9496
10748
|
continue;
|
|
9497
10749
|
}
|
|
9498
10750
|
/* Sanitize attribute content to be template-safe */
|
|
9499
10751
|
if (SAFE_FOR_TEMPLATES) {
|
|
9500
|
-
|
|
9501
|
-
value = stringReplace(value, expr, ' ');
|
|
9502
|
-
});
|
|
10752
|
+
value = _stripTemplateExpressions(value);
|
|
9503
10753
|
}
|
|
9504
10754
|
/* Is `value` valid for this attribute? */
|
|
9505
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
9506
10755
|
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
9507
10756
|
_removeAttribute(name, currentNode);
|
|
9508
10757
|
continue;
|
|
9509
10758
|
}
|
|
9510
10759
|
/* Handle attributes that require Trusted Types */
|
|
9511
|
-
|
|
9512
|
-
if (namespaceURI) ; else {
|
|
9513
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
9514
|
-
case 'TrustedHTML':
|
|
9515
|
-
{
|
|
9516
|
-
value = trustedTypesPolicy.createHTML(value);
|
|
9517
|
-
break;
|
|
9518
|
-
}
|
|
9519
|
-
case 'TrustedScriptURL':
|
|
9520
|
-
{
|
|
9521
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
|
9522
|
-
break;
|
|
9523
|
-
}
|
|
9524
|
-
}
|
|
9525
|
-
}
|
|
9526
|
-
}
|
|
10760
|
+
value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
|
|
9527
10761
|
/* Handle invalid data-* attribute set by try-catching it */
|
|
9528
10762
|
if (value !== initValue) {
|
|
9529
|
-
|
|
9530
|
-
if (namespaceURI) {
|
|
9531
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
9532
|
-
} else {
|
|
9533
|
-
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
9534
|
-
currentNode.setAttribute(name, value);
|
|
9535
|
-
}
|
|
9536
|
-
if (_isClobbered(currentNode)) {
|
|
9537
|
-
_forceRemove(currentNode);
|
|
9538
|
-
} else {
|
|
9539
|
-
arrayPop(DOMPurify.removed);
|
|
9540
|
-
}
|
|
9541
|
-
} catch (_) {
|
|
9542
|
-
_removeAttribute(name, currentNode);
|
|
9543
|
-
}
|
|
10763
|
+
_setAttributeValue(currentNode, name, namespaceURI, value);
|
|
9544
10764
|
}
|
|
9545
10765
|
}
|
|
9546
10766
|
/* Execute a hook if present */
|
|
@@ -9560,17 +10780,136 @@
|
|
|
9560
10780
|
/* Execute a hook if present */
|
|
9561
10781
|
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
9562
10782
|
/* Sanitize tags and elements */
|
|
9563
|
-
_sanitizeElements(shadowNode);
|
|
10783
|
+
_sanitizeElements(shadowNode, fragment);
|
|
9564
10784
|
/* Check attributes next */
|
|
9565
10785
|
_sanitizeAttributes(shadowNode);
|
|
9566
|
-
/* Deep shadow DOM detected
|
|
9567
|
-
|
|
10786
|
+
/* Deep shadow DOM detected.
|
|
10787
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
|
|
10788
|
+
DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
|
|
10789
|
+
recurse into <template>.content from foreign realms too. */
|
|
10790
|
+
if (_isDocumentFragment(shadowNode.content)) {
|
|
9568
10791
|
_sanitizeShadowDOM2(shadowNode.content);
|
|
9569
10792
|
}
|
|
10793
|
+
/* An element iterated here may itself host an attached
|
|
10794
|
+
shadow root. The default NodeIterator does not enter shadow
|
|
10795
|
+
trees, so a shadow root nested inside template.content was
|
|
10796
|
+
previously reached by no walk at all (the pre-pass at
|
|
10797
|
+
_sanitizeAttachedShadowRoots descends via childNodes, which
|
|
10798
|
+
doesn't enter template.content; the template-content recursion
|
|
10799
|
+
above iterates the content but never inspected shadowRoot).
|
|
10800
|
+
Walk it explicitly. The nodeType guard avoids reading
|
|
10801
|
+
shadowRoot off text / comment / CDATA / PI nodes that the
|
|
10802
|
+
iterator also surfaces. */
|
|
10803
|
+
const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
|
|
10804
|
+
if (shadowNodeType === NODE_TYPE.element) {
|
|
10805
|
+
const innerSr = getShadowRoot(shadowNode);
|
|
10806
|
+
if (_isDocumentFragment(innerSr)) {
|
|
10807
|
+
_sanitizeAttachedShadowRoots(innerSr);
|
|
10808
|
+
_sanitizeShadowDOM2(innerSr);
|
|
10809
|
+
}
|
|
10810
|
+
}
|
|
9570
10811
|
}
|
|
9571
10812
|
/* Execute a hook if present */
|
|
9572
10813
|
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
9573
10814
|
};
|
|
10815
|
+
/**
|
|
10816
|
+
* _sanitizeAttachedShadowRoots
|
|
10817
|
+
*
|
|
10818
|
+
* Walks `root` and feeds every attached shadow root we encounter into
|
|
10819
|
+
* the existing _sanitizeShadowDOM pipeline. The default node iterator
|
|
10820
|
+
* does not descend into shadow trees, so nodes inside an attached
|
|
10821
|
+
* shadow root would otherwise be skipped entirely.
|
|
10822
|
+
*
|
|
10823
|
+
* Two real input paths put attached shadow roots in front of us:
|
|
10824
|
+
* 1. IN_PLACE on a DOM node that already has shadow roots attached.
|
|
10825
|
+
* 2. DOM-node input where importNode(dirty, true) deep-clones the
|
|
10826
|
+
* shadow root because it was created with `clonable: true`.
|
|
10827
|
+
*
|
|
10828
|
+
* This pass runs once, up front, so the main iteration loop (and the
|
|
10829
|
+
* existing _sanitizeShadowDOM template-content recursion) stay
|
|
10830
|
+
* untouched — string-input paths are not affected.
|
|
10831
|
+
*
|
|
10832
|
+
* @param root the subtree root to walk for attached shadow roots
|
|
10833
|
+
*/
|
|
10834
|
+
const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
|
|
10835
|
+
/* Iterative (explicit stack) rather than per-child recursion. DOM APIs
|
|
10836
|
+
impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
|
|
10837
|
+
built straight into the DOM — the IN_PLACE surface) deeper than the JS
|
|
10838
|
+
call-stack budget would otherwise overflow native recursion here and
|
|
10839
|
+
throw at the IN_PLACE entry pre-pass, before a single node is
|
|
10840
|
+
sanitized, leaving the caller's live tree untouched (fail-open). See
|
|
10841
|
+
campaign-3 F4. A heap stack keeps depth off the call stack.
|
|
10842
|
+
Each work item is either a node to descend into, or a deferred
|
|
10843
|
+
`_sanitizeShadowDOM` for an already-walked shadow root. The deferred
|
|
10844
|
+
form preserves the original post-order discipline: a shadow root's
|
|
10845
|
+
nested shadow roots are discovered before the outer shadow is
|
|
10846
|
+
sanitized (which may remove hosts). Pushes are in reverse of the
|
|
10847
|
+
desired processing order (LIFO): template content, then children, then
|
|
10848
|
+
the shadow-sanitize, then the shadow walk — so the order matches the
|
|
10849
|
+
previous recursion exactly. */
|
|
10850
|
+
const stack = [{
|
|
10851
|
+
node: root,
|
|
10852
|
+
shadow: null
|
|
10853
|
+
}];
|
|
10854
|
+
while (stack.length > 0) {
|
|
10855
|
+
const item = stack.pop();
|
|
10856
|
+
/* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
|
|
10857
|
+
if (item.shadow) {
|
|
10858
|
+
_sanitizeShadowDOM2(item.shadow);
|
|
10859
|
+
continue;
|
|
10860
|
+
}
|
|
10861
|
+
const node = item.node;
|
|
10862
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
10863
|
+
const isElement = nodeType === NODE_TYPE.element;
|
|
10864
|
+
/* (pushed last → processed first) Children, snapshotted in reverse so
|
|
10865
|
+
the first child is processed first. Snapshotting matters because a
|
|
10866
|
+
hook may detach siblings mid-walk. */
|
|
10867
|
+
const childNodes = getChildNodes(node);
|
|
10868
|
+
if (childNodes) {
|
|
10869
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
10870
|
+
stack.push({
|
|
10871
|
+
node: childNodes[i],
|
|
10872
|
+
shadow: null
|
|
10873
|
+
});
|
|
10874
|
+
}
|
|
10875
|
+
}
|
|
10876
|
+
/* (pushed before children → processed after them, matching the old
|
|
10877
|
+
"template content last" order) When the node is a <template>,
|
|
10878
|
+
descend into its content. */
|
|
10879
|
+
if (isElement) {
|
|
10880
|
+
const rootName = getNodeName ? getNodeName(node) : null;
|
|
10881
|
+
if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
|
|
10882
|
+
const content = node.content;
|
|
10883
|
+
if (_isDocumentFragment(content)) {
|
|
10884
|
+
stack.push({
|
|
10885
|
+
node: content,
|
|
10886
|
+
shadow: null
|
|
10887
|
+
});
|
|
10888
|
+
}
|
|
10889
|
+
}
|
|
10890
|
+
}
|
|
10891
|
+
/* Shadow root (processed first): walk its subtree, then sanitise it.
|
|
10892
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
10893
|
+
rather than `instanceof DocumentFragment`, which is realm-bound and
|
|
10894
|
+
silently skipped foreign-realm shadow roots (e.g.
|
|
10895
|
+
iframe.contentDocument attachShadow). */
|
|
10896
|
+
if (isElement) {
|
|
10897
|
+
const sr = getShadowRoot(node);
|
|
10898
|
+
if (_isDocumentFragment(sr)) {
|
|
10899
|
+
/* Push the deferred sanitise first so it pops after the shadow
|
|
10900
|
+
walk we push next, i.e. nested shadow roots are discovered
|
|
10901
|
+
before this one is sanitised. */
|
|
10902
|
+
stack.push({
|
|
10903
|
+
node: null,
|
|
10904
|
+
shadow: sr
|
|
10905
|
+
}, {
|
|
10906
|
+
node: sr,
|
|
10907
|
+
shadow: null
|
|
10908
|
+
});
|
|
10909
|
+
}
|
|
10910
|
+
}
|
|
10911
|
+
}
|
|
10912
|
+
};
|
|
9574
10913
|
// eslint-disable-next-line complexity
|
|
9575
10914
|
DOMPurify.sanitize = function (dirty) {
|
|
9576
10915
|
let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -9587,13 +10926,9 @@
|
|
|
9587
10926
|
}
|
|
9588
10927
|
/* Stringify, in case dirty is an object */
|
|
9589
10928
|
if (typeof dirty !== 'string' && !_isNode(dirty)) {
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
throw typeErrorCreate('dirty is not a string, aborting');
|
|
9594
|
-
}
|
|
9595
|
-
} else {
|
|
9596
|
-
throw typeErrorCreate('toString is not a function');
|
|
10929
|
+
dirty = stringifyValue(dirty);
|
|
10930
|
+
if (typeof dirty !== 'string') {
|
|
10931
|
+
throw typeErrorCreate('dirty is not a string, aborting');
|
|
9597
10932
|
}
|
|
9598
10933
|
}
|
|
9599
10934
|
/* Return dirty HTML if DOMPurify cannot run */
|
|
@@ -9601,24 +10936,90 @@
|
|
|
9601
10936
|
return dirty;
|
|
9602
10937
|
}
|
|
9603
10938
|
/* Assign config vars */
|
|
9604
|
-
if (
|
|
10939
|
+
if (SET_CONFIG) {
|
|
10940
|
+
/* Persistent setConfig() path: _parseConfig is skipped, so the sets are
|
|
10941
|
+
* not re-derived per call. Restore them from the pristine bindings
|
|
10942
|
+
* captured at setConfig() time so a previous call's hook clone (mutated
|
|
10943
|
+
* below) does not carry over. */
|
|
10944
|
+
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
10945
|
+
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
10946
|
+
} else {
|
|
9605
10947
|
_parseConfig(cfg);
|
|
9606
10948
|
}
|
|
10949
|
+
/* Clone the hook-mutable allowlists before the walk whenever an
|
|
10950
|
+
* uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
|
|
10951
|
+
* and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
|
|
10952
|
+
* a hook that widens them would otherwise mutate the shared set
|
|
10953
|
+
* permanently: across later calls and across every element. Cloning per
|
|
10954
|
+
* walk keeps documented in-call widening working while scoping it to the
|
|
10955
|
+
* call. A single guard for both config paths - the per-call path rebinds
|
|
10956
|
+
* the sets in _parseConfig each call, the persistent path restores them
|
|
10957
|
+
* from the captured bindings just above - so the two cannot diverge. */
|
|
10958
|
+
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
|
|
10959
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
10960
|
+
}
|
|
10961
|
+
if (hooks.uponSanitizeAttribute.length > 0) {
|
|
10962
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
10963
|
+
}
|
|
9607
10964
|
/* Clean up removed elements */
|
|
9608
10965
|
DOMPurify.removed = [];
|
|
9609
|
-
/*
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
10966
|
+
/* Resolve IN_PLACE for this call without mutating persistent config.
|
|
10967
|
+
Writing the IN_PLACE closure variable here leaks under setConfig(),
|
|
10968
|
+
where _parseConfig is skipped on later calls: a single string call would
|
|
10969
|
+
disable in-place mode for every subsequent node call, returning a
|
|
10970
|
+
sanitized copy while leaving the caller's node — which in-place callers
|
|
10971
|
+
keep using and whose return value they ignore — unsanitized. REPORT-2. */
|
|
10972
|
+
const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
|
|
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);
|
|
10979
|
+
/* Do some early pre-sanitization to avoid unsafe root nodes.
|
|
10980
|
+
Read nodeName through the cached prototype getter — a clobbering
|
|
10981
|
+
child named "nodeName" on the form root would otherwise shadow
|
|
10982
|
+
the property and let this check skip the root-allowlist
|
|
10983
|
+
validation entirely. */
|
|
10984
|
+
const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
|
|
10985
|
+
if (typeof nn === 'string') {
|
|
10986
|
+
const tagName = transformCaseFunc(nn);
|
|
9617
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);
|
|
9618
10991
|
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
|
|
9619
10992
|
}
|
|
9620
10993
|
}
|
|
9621
|
-
|
|
10994
|
+
/* Pre-flight the root through _isClobbered. The iterator-driven
|
|
10995
|
+
removal path can not detach a parent-less root: _forceRemove
|
|
10996
|
+
falls through to Element.prototype.remove(), which per spec
|
|
10997
|
+
is a no-op on a node with no parent. A clobbered root would
|
|
10998
|
+
then survive the main loop with its attributes uninspected,
|
|
10999
|
+
because _sanitizeAttributes early-returns on _isClobbered. The
|
|
11000
|
+
result would be an attacker-controlled form, complete with any
|
|
11001
|
+
event-handler attributes the caller passed in, handed back to
|
|
11002
|
+
the application unsanitized. Refuse to sanitize such a root
|
|
11003
|
+
the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
|
|
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);
|
|
11009
|
+
throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
|
|
11010
|
+
}
|
|
11011
|
+
/* Sanitize attached shadow roots before the main iterator runs.
|
|
11012
|
+
The iterator does not descend into shadow trees. Same fail-closed
|
|
11013
|
+
barrier as the main walk (campaign-3 F2): a custom-element reaction
|
|
11014
|
+
inside a shadow root could abort this pre-pass before the walk runs,
|
|
11015
|
+
which would otherwise leave the entire live tree unsanitized. */
|
|
11016
|
+
try {
|
|
11017
|
+
_sanitizeAttachedShadowRoots(dirty);
|
|
11018
|
+
} catch (error) {
|
|
11019
|
+
_neutralizeRoot(dirty);
|
|
11020
|
+
throw error;
|
|
11021
|
+
}
|
|
11022
|
+
} else if (_isNode(dirty)) {
|
|
9622
11023
|
/* If dirty is a DOM element, append to an empty document to avoid
|
|
9623
11024
|
elements being stripped by the parser */
|
|
9624
11025
|
body = _initDocument('<!---->');
|
|
@@ -9632,12 +11033,18 @@
|
|
|
9632
11033
|
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
9633
11034
|
body.appendChild(importedNode);
|
|
9634
11035
|
}
|
|
11036
|
+
/* Clonable shadow roots are deep-cloned by importNode(); sanitize
|
|
11037
|
+
them before the main iterator runs, since the iterator does not
|
|
11038
|
+
descend into shadow trees. The walk routes every read through a
|
|
11039
|
+
cached prototype getter so clobbering descendants on a form root
|
|
11040
|
+
cannot hide a shadow host from this pass. */
|
|
11041
|
+
_sanitizeAttachedShadowRoots(importedNode);
|
|
9635
11042
|
} else {
|
|
9636
11043
|
/* Exit directly if we have nothing to do */
|
|
9637
11044
|
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
|
|
9638
11045
|
// eslint-disable-next-line unicorn/prefer-includes
|
|
9639
11046
|
dirty.indexOf('<') === -1) {
|
|
9640
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
11047
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
|
|
9641
11048
|
}
|
|
9642
11049
|
/* Initialize the document to work on */
|
|
9643
11050
|
body = _initDocument(dirty);
|
|
@@ -9651,31 +11058,71 @@
|
|
|
9651
11058
|
_forceRemove(body.firstChild);
|
|
9652
11059
|
}
|
|
9653
11060
|
/* Get node iterator */
|
|
9654
|
-
const
|
|
9655
|
-
/* Now start iterating over the created document
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
11061
|
+
const walkRoot = inPlace ? dirty : body;
|
|
11062
|
+
/* Now start iterating over the created document.
|
|
11063
|
+
The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
|
|
11064
|
+
engine/custom-element mutation can detach a node mid-walk so
|
|
11065
|
+
`_forceRemove`'s parentless guard throws, aborting the loop. Without the
|
|
11066
|
+
barrier the caller's in-place tree would be left half-sanitized with the
|
|
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.) */
|
|
11074
|
+
try {
|
|
11075
|
+
const nodeIterator = _createNodeIterator(walkRoot);
|
|
11076
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
11077
|
+
/* Sanitize tags and elements */
|
|
11078
|
+
_sanitizeElements(currentNode, walkRoot);
|
|
11079
|
+
/* Check attributes next */
|
|
11080
|
+
_sanitizeAttributes(currentNode);
|
|
11081
|
+
/* Shadow DOM detected, sanitize it.
|
|
11082
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
11083
|
+
instead of instanceof, so foreign-realm <template>.content is
|
|
11084
|
+
walked correctly. */
|
|
11085
|
+
if (_isDocumentFragment(currentNode.content)) {
|
|
11086
|
+
_sanitizeShadowDOM2(currentNode.content);
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11089
|
+
} catch (error) {
|
|
11090
|
+
if (inPlace) {
|
|
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
|
+
});
|
|
9664
11100
|
}
|
|
11101
|
+
throw error;
|
|
9665
11102
|
}
|
|
9666
11103
|
/* If we sanitized `dirty` in-place, return it. */
|
|
9667
|
-
if (
|
|
11104
|
+
if (inPlace) {
|
|
11105
|
+
/* Fail-closed completion of the audit-5 F1 fix: every node removed from
|
|
11106
|
+
the caller's live tree is detached but may still hold a queued
|
|
11107
|
+
resource-event handler that fires in page scope after we return. The
|
|
11108
|
+
move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
|
|
11109
|
+
non-allow-listed attributes off every other removed subtree (clobber,
|
|
11110
|
+
mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
|
|
11111
|
+
cancelled before any event can fire. Runs synchronously, pre-return. */
|
|
11112
|
+
arrayForEach(DOMPurify.removed, entry => {
|
|
11113
|
+
if (entry.element) {
|
|
11114
|
+
_neutralizeSubtree(entry.element);
|
|
11115
|
+
}
|
|
11116
|
+
});
|
|
11117
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
11118
|
+
_scrubTemplateExpressions2(dirty);
|
|
11119
|
+
}
|
|
9668
11120
|
return dirty;
|
|
9669
11121
|
}
|
|
9670
11122
|
/* Return sanitized string or DOM */
|
|
9671
11123
|
if (RETURN_DOM) {
|
|
9672
11124
|
if (SAFE_FOR_TEMPLATES) {
|
|
9673
|
-
body
|
|
9674
|
-
let html = body.innerHTML;
|
|
9675
|
-
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
9676
|
-
html = stringReplace(html, expr, ' ');
|
|
9677
|
-
});
|
|
9678
|
-
body.innerHTML = html;
|
|
11125
|
+
_scrubTemplateExpressions2(body);
|
|
9679
11126
|
}
|
|
9680
11127
|
if (RETURN_DOM_FRAGMENT) {
|
|
9681
11128
|
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
@@ -9705,20 +11152,28 @@
|
|
|
9705
11152
|
}
|
|
9706
11153
|
/* Sanitize final string template-safe */
|
|
9707
11154
|
if (SAFE_FOR_TEMPLATES) {
|
|
9708
|
-
|
|
9709
|
-
serializedHTML = stringReplace(serializedHTML, expr, ' ');
|
|
9710
|
-
});
|
|
11155
|
+
serializedHTML = _stripTemplateExpressions(serializedHTML);
|
|
9711
11156
|
}
|
|
9712
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
11157
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
9713
11158
|
};
|
|
9714
11159
|
DOMPurify.setConfig = function () {
|
|
9715
11160
|
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
9716
11161
|
_parseConfig(cfg);
|
|
9717
11162
|
SET_CONFIG = true;
|
|
11163
|
+
SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
|
|
11164
|
+
SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
|
|
9718
11165
|
};
|
|
9719
11166
|
DOMPurify.clearConfig = function () {
|
|
9720
11167
|
CONFIG = null;
|
|
9721
11168
|
SET_CONFIG = false;
|
|
11169
|
+
SET_CONFIG_ALLOWED_TAGS = null;
|
|
11170
|
+
SET_CONFIG_ALLOWED_ATTR = null;
|
|
11171
|
+
// Drop any caller-supplied Trusted Types policy so it cannot poison later
|
|
11172
|
+
// `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
|
|
11173
|
+
// never recreated — Trusted Types throws on duplicate names) is restored by
|
|
11174
|
+
// the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
|
|
11175
|
+
trustedTypesPolicy = defaultTrustedTypesPolicy;
|
|
11176
|
+
emptyHTML = '';
|
|
9722
11177
|
};
|
|
9723
11178
|
DOMPurify.isValidAttribute = function (tag, attr, value) {
|
|
9724
11179
|
/* Initialize shared config vars if necessary. */
|
|
@@ -9733,9 +11188,19 @@
|
|
|
9733
11188
|
if (typeof hookFunction !== 'function') {
|
|
9734
11189
|
return;
|
|
9735
11190
|
}
|
|
11191
|
+
/* Reject unknown entry points. Without this, a non-hook key (e.g.
|
|
11192
|
+
* '__proto__') indexes off the prototype chain rather than a real
|
|
11193
|
+
* hook array, and arrayPush then writes to Object.prototype. Guard
|
|
11194
|
+
* with an own-property check against the known hook names. */
|
|
11195
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
11196
|
+
return;
|
|
11197
|
+
}
|
|
9736
11198
|
arrayPush(hooks[entryPoint], hookFunction);
|
|
9737
11199
|
};
|
|
9738
11200
|
DOMPurify.removeHook = function (entryPoint, hookFunction) {
|
|
11201
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
11202
|
+
return undefined;
|
|
11203
|
+
}
|
|
9739
11204
|
if (hookFunction !== undefined) {
|
|
9740
11205
|
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
9741
11206
|
return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
@@ -9743,6 +11208,9 @@
|
|
|
9743
11208
|
return arrayPop(hooks[entryPoint]);
|
|
9744
11209
|
};
|
|
9745
11210
|
DOMPurify.removeHooks = function (entryPoint) {
|
|
11211
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
11212
|
+
return;
|
|
11213
|
+
}
|
|
9746
11214
|
hooks[entryPoint] = [];
|
|
9747
11215
|
};
|
|
9748
11216
|
DOMPurify.removeAllHooks = function () {
|
|
@@ -10003,10 +11471,26 @@
|
|
|
10003
11471
|
}(Background);
|
|
10004
11472
|
|
|
10005
11473
|
/**
|
|
10006
|
-
* Generate a unique id compatible with HTML element id
|
|
11474
|
+
* Generate a unique id compatible with HTML element id.
|
|
11475
|
+
* Uses the Web Crypto API for cryptographically strong randomness, with a
|
|
11476
|
+
* deterministic fallback only when crypto is unavailable.
|
|
10007
11477
|
*/
|
|
10008
11478
|
function getUniqueId() {
|
|
10009
|
-
|
|
11479
|
+
var letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
11480
|
+
var length = 10;
|
|
11481
|
+
var bytes = new Uint8Array(length);
|
|
11482
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
11483
|
+
crypto.getRandomValues(bytes);
|
|
11484
|
+
} else {
|
|
11485
|
+
for (var i = 0; i < length; i++) {
|
|
11486
|
+
bytes[i] = (i * 31 + 7) % 256;
|
|
11487
|
+
}
|
|
11488
|
+
}
|
|
11489
|
+
var id = '';
|
|
11490
|
+
for (var _i = 0; _i < length; _i++) {
|
|
11491
|
+
id += letters[bytes[_i] % letters.length];
|
|
11492
|
+
}
|
|
11493
|
+
return id;
|
|
10010
11494
|
}
|
|
10011
11495
|
|
|
10012
11496
|
function getFlypayV2Button(widgetId) {
|
|
@@ -14039,6 +15523,54 @@
|
|
|
14039
15523
|
validate_card_types: validateCardNumberInput
|
|
14040
15524
|
});
|
|
14041
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
|
+
}
|
|
14042
15574
|
/**
|
|
14043
15575
|
* Current method can hide prevent the widget from showing the error messages
|
|
14044
15576
|
*
|
|
@@ -19138,6 +20670,90 @@
|
|
|
19138
20670
|
EVENT["ON_SHIPPING_OPTIONS_CHANGE"] = "onShippingOptionsChange";
|
|
19139
20671
|
})(EVENT$1 || (EVENT$1 = {}));
|
|
19140
20672
|
|
|
20673
|
+
/** TTL for a cached service configuration: 1 day, in milliseconds. */
|
|
20674
|
+
var CACHE_TTL_MS = 86400000;
|
|
20675
|
+
/** Builds the `localStorage` key used to cache a service's configuration. */
|
|
20676
|
+
function serviceConfigStorageKey(serviceId) {
|
|
20677
|
+
return "paydock-serviceConfig-".concat(serviceId);
|
|
20678
|
+
}
|
|
20679
|
+
/**
|
|
20680
|
+
* Removes the cached service configuration for the given service ID, forcing the next
|
|
20681
|
+
* fetch to go to the network. Called on error / unavailable flows so a potentially
|
|
20682
|
+
* stale cached config is not reused after something changed server-side. No-throw when
|
|
20683
|
+
* `localStorage` is unavailable.
|
|
20684
|
+
*
|
|
20685
|
+
* @param serviceId - The service ID whose cached configuration should be cleared.
|
|
20686
|
+
*/
|
|
20687
|
+
function clearServiceConfigCache(serviceId) {
|
|
20688
|
+
try {
|
|
20689
|
+
localStorage.removeItem(serviceConfigStorageKey(serviceId));
|
|
20690
|
+
} catch (_error) {
|
|
20691
|
+
// localStorage may be unavailable; nothing to clear
|
|
20692
|
+
}
|
|
20693
|
+
}
|
|
20694
|
+
/**
|
|
20695
|
+
* Fetches the wallet service configuration, backed by a 1-day `localStorage` cache
|
|
20696
|
+
* keyed on the service ID. Falls back gracefully (no caching) when `localStorage`
|
|
20697
|
+
* is unavailable (e.g. private browsing). Shared by the instance `load()` flow and
|
|
20698
|
+
* the static availability checks so both reuse the same cached fetch.
|
|
20699
|
+
*
|
|
20700
|
+
* @param api - The configured API client (env must already be set).
|
|
20701
|
+
* @param serviceId - The service ID to fetch the configuration for.
|
|
20702
|
+
* @returns The service configuration response.
|
|
20703
|
+
*/
|
|
20704
|
+
function getServiceConfigCached(api, serviceId) {
|
|
20705
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
20706
|
+
var storageKey, cachedData, _JSON$parse, data, timestamp, serviceConfigResponse, encodedData;
|
|
20707
|
+
return _regenerator().w(function (_context) {
|
|
20708
|
+
while (1) switch (_context.p = _context.n) {
|
|
20709
|
+
case 0:
|
|
20710
|
+
storageKey = serviceConfigStorageKey(serviceId);
|
|
20711
|
+
_context.p = 1;
|
|
20712
|
+
cachedData = localStorage.getItem(storageKey);
|
|
20713
|
+
if (!cachedData) {
|
|
20714
|
+
_context.n = 5;
|
|
20715
|
+
break;
|
|
20716
|
+
}
|
|
20717
|
+
_context.p = 2;
|
|
20718
|
+
_JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
|
|
20719
|
+
if (!(Date.now() - timestamp < CACHE_TTL_MS)) {
|
|
20720
|
+
_context.n = 3;
|
|
20721
|
+
break;
|
|
20722
|
+
}
|
|
20723
|
+
return _context.a(2, JSON.parse(data));
|
|
20724
|
+
case 3:
|
|
20725
|
+
_context.n = 5;
|
|
20726
|
+
break;
|
|
20727
|
+
case 4:
|
|
20728
|
+
_context.p = 4;
|
|
20729
|
+
_context.v;
|
|
20730
|
+
localStorage.removeItem(storageKey);
|
|
20731
|
+
case 5:
|
|
20732
|
+
_context.n = 7;
|
|
20733
|
+
break;
|
|
20734
|
+
case 6:
|
|
20735
|
+
_context.p = 6;
|
|
20736
|
+
_context.v;
|
|
20737
|
+
case 7:
|
|
20738
|
+
_context.n = 8;
|
|
20739
|
+
return api.service().getConfig(serviceId);
|
|
20740
|
+
case 8:
|
|
20741
|
+
serviceConfigResponse = _context.v;
|
|
20742
|
+
try {
|
|
20743
|
+
encodedData = btoa(JSON.stringify({
|
|
20744
|
+
data: JSON.stringify(serviceConfigResponse),
|
|
20745
|
+
timestamp: Date.now()
|
|
20746
|
+
}));
|
|
20747
|
+
localStorage.setItem(storageKey, encodedData);
|
|
20748
|
+
} catch (_error) {
|
|
20749
|
+
// localStorage may be unavailable; proceed without caching
|
|
20750
|
+
}
|
|
20751
|
+
return _context.a(2, serviceConfigResponse);
|
|
20752
|
+
}
|
|
20753
|
+
}, _callee, null, [[2, 4], [1, 6]]);
|
|
20754
|
+
}));
|
|
20755
|
+
}
|
|
20756
|
+
|
|
19141
20757
|
/**
|
|
19142
20758
|
* @classdesc Abstract base class for Open Wallet buttons. **Do not instantiate directly.**
|
|
19143
20759
|
* Use {@link ApplePayOpenWalletButton} or {@link GooglePayOpenWalletButton} instead.
|
|
@@ -19171,10 +20787,30 @@
|
|
|
19171
20787
|
this.api = new ApiInternal(publicKeyOrAccessToken, this.getApiAuthType(publicKeyOrAccessToken));
|
|
19172
20788
|
this.serviceId = serviceId;
|
|
19173
20789
|
this.meta = meta;
|
|
20790
|
+
this.registerCacheInvalidationOnError();
|
|
19174
20791
|
this.validateBaseMeta();
|
|
19175
20792
|
this.validateWalletMeta();
|
|
19176
20793
|
}
|
|
20794
|
+
/**
|
|
20795
|
+
* Invalidates the cached service configuration whenever an error or unavailable
|
|
20796
|
+
* event fires, so the next `load()` re-fetches a fresh config. The cache is keyed
|
|
20797
|
+
* on the service ID with a 1-day TTL; clearing it on failure means a config that
|
|
20798
|
+
* changed server-side (and caused the failure) is not reused until the TTL expires.
|
|
20799
|
+
* Registered once per button, independently of any merchant-registered handlers.
|
|
20800
|
+
*
|
|
20801
|
+
* @private
|
|
20802
|
+
*/
|
|
19177
20803
|
return _createClass(OpenWalletButtons, [{
|
|
20804
|
+
key: "registerCacheInvalidationOnError",
|
|
20805
|
+
value: function registerCacheInvalidationOnError() {
|
|
20806
|
+
var _this = this;
|
|
20807
|
+
var invalidate = function invalidate() {
|
|
20808
|
+
return clearServiceConfigCache(_this.serviceId);
|
|
20809
|
+
};
|
|
20810
|
+
this.eventEmitter.subscribe(EVENT$1.ERROR, invalidate);
|
|
20811
|
+
this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, invalidate);
|
|
20812
|
+
}
|
|
20813
|
+
}, {
|
|
19178
20814
|
key: "getApiAuthType",
|
|
19179
20815
|
value: function getApiAuthType(publicKeyOrAccessToken) {
|
|
19180
20816
|
if (AccessToken.validateJWT(publicKeyOrAccessToken)) {
|
|
@@ -19208,57 +20844,7 @@
|
|
|
19208
20844
|
}, {
|
|
19209
20845
|
key: "getOpenWalletServiceConfig",
|
|
19210
20846
|
value: function getOpenWalletServiceConfig() {
|
|
19211
|
-
return
|
|
19212
|
-
var storageKey, cachedData, _JSON$parse, data, timestamp, oneDay, serviceConfigResponse, encodedData;
|
|
19213
|
-
return _regenerator().w(function (_context) {
|
|
19214
|
-
while (1) switch (_context.p = _context.n) {
|
|
19215
|
-
case 0:
|
|
19216
|
-
storageKey = "serviceConfig-".concat(this.serviceId);
|
|
19217
|
-
_context.p = 1;
|
|
19218
|
-
cachedData = localStorage.getItem(storageKey);
|
|
19219
|
-
if (!cachedData) {
|
|
19220
|
-
_context.n = 5;
|
|
19221
|
-
break;
|
|
19222
|
-
}
|
|
19223
|
-
_context.p = 2;
|
|
19224
|
-
_JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
|
|
19225
|
-
oneDay = 86400000;
|
|
19226
|
-
if (!(Date.now() - timestamp < oneDay)) {
|
|
19227
|
-
_context.n = 3;
|
|
19228
|
-
break;
|
|
19229
|
-
}
|
|
19230
|
-
return _context.a(2, JSON.parse(data));
|
|
19231
|
-
case 3:
|
|
19232
|
-
_context.n = 5;
|
|
19233
|
-
break;
|
|
19234
|
-
case 4:
|
|
19235
|
-
_context.p = 4;
|
|
19236
|
-
_context.v;
|
|
19237
|
-
localStorage.removeItem(storageKey);
|
|
19238
|
-
case 5:
|
|
19239
|
-
_context.n = 7;
|
|
19240
|
-
break;
|
|
19241
|
-
case 6:
|
|
19242
|
-
_context.p = 6;
|
|
19243
|
-
_context.v;
|
|
19244
|
-
case 7:
|
|
19245
|
-
_context.n = 8;
|
|
19246
|
-
return this.api.service().getConfig(this.serviceId);
|
|
19247
|
-
case 8:
|
|
19248
|
-
serviceConfigResponse = _context.v;
|
|
19249
|
-
try {
|
|
19250
|
-
encodedData = btoa(JSON.stringify({
|
|
19251
|
-
data: JSON.stringify(serviceConfigResponse),
|
|
19252
|
-
timestamp: Date.now()
|
|
19253
|
-
}));
|
|
19254
|
-
localStorage.setItem(storageKey, encodedData);
|
|
19255
|
-
} catch (_error) {
|
|
19256
|
-
// localStorage may be unavailable; proceed without caching
|
|
19257
|
-
}
|
|
19258
|
-
return _context.a(2, serviceConfigResponse);
|
|
19259
|
-
}
|
|
19260
|
-
}, _callee, this, [[2, 4], [1, 6]]);
|
|
19261
|
-
}));
|
|
20847
|
+
return getServiceConfigCached(this.api, this.serviceId);
|
|
19262
20848
|
}
|
|
19263
20849
|
}, {
|
|
19264
20850
|
key: "handleOnError",
|
|
@@ -19293,13 +20879,13 @@
|
|
|
19293
20879
|
}, {
|
|
19294
20880
|
key: "load",
|
|
19295
20881
|
value: function load() {
|
|
19296
|
-
var
|
|
20882
|
+
var _this2 = this;
|
|
19297
20883
|
this.getOpenWalletServiceConfig().then(function (serviceConfig) {
|
|
19298
|
-
|
|
19299
|
-
|
|
19300
|
-
|
|
20884
|
+
_this2.validateServiceType(serviceConfig);
|
|
20885
|
+
_this2.walletService = _this2.createWalletService(serviceConfig);
|
|
20886
|
+
_this2.walletService.load();
|
|
19301
20887
|
})["catch"](function (error) {
|
|
19302
|
-
|
|
20888
|
+
_this2.handleOnError(error instanceof Error ? error : new Error(String(error)), exports.ERROR_OPERATION.CONFIGURATION);
|
|
19303
20889
|
});
|
|
19304
20890
|
}
|
|
19305
20891
|
/**
|
|
@@ -19497,28 +21083,28 @@
|
|
|
19497
21083
|
}, {
|
|
19498
21084
|
key: "onSuccess",
|
|
19499
21085
|
value: function onSuccess(handler) {
|
|
19500
|
-
var
|
|
21086
|
+
var _this3 = this;
|
|
19501
21087
|
if (typeof handler === 'function') {
|
|
19502
21088
|
this.eventEmitter.subscribe(EVENT$1.SUCCESS, function (data) {
|
|
19503
|
-
return __awaiter(
|
|
19504
|
-
var
|
|
19505
|
-
return _regenerator().w(function (
|
|
19506
|
-
while (1) switch (
|
|
21089
|
+
return __awaiter(_this3, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
21090
|
+
var _t;
|
|
21091
|
+
return _regenerator().w(function (_context) {
|
|
21092
|
+
while (1) switch (_context.p = _context.n) {
|
|
19507
21093
|
case 0:
|
|
19508
|
-
|
|
19509
|
-
|
|
21094
|
+
_context.p = 0;
|
|
21095
|
+
_context.n = 1;
|
|
19510
21096
|
return handler(data);
|
|
19511
21097
|
case 1:
|
|
19512
|
-
|
|
21098
|
+
_context.n = 3;
|
|
19513
21099
|
break;
|
|
19514
21100
|
case 2:
|
|
19515
|
-
|
|
19516
|
-
|
|
19517
|
-
console.warn('Merchant onSuccess handler threw (swallowed):',
|
|
21101
|
+
_context.p = 2;
|
|
21102
|
+
_t = _context.v;
|
|
21103
|
+
console.warn('Merchant onSuccess handler threw (swallowed):', _t);
|
|
19518
21104
|
case 3:
|
|
19519
|
-
return
|
|
21105
|
+
return _context.a(2);
|
|
19520
21106
|
}
|
|
19521
|
-
},
|
|
21107
|
+
}, _callee, null, [[0, 2]]);
|
|
19522
21108
|
}));
|
|
19523
21109
|
});
|
|
19524
21110
|
return;
|
|
@@ -19549,28 +21135,28 @@
|
|
|
19549
21135
|
}, {
|
|
19550
21136
|
key: "onUnavailable",
|
|
19551
21137
|
value: function onUnavailable(handler) {
|
|
19552
|
-
var
|
|
21138
|
+
var _this4 = this;
|
|
19553
21139
|
if (typeof handler === 'function') {
|
|
19554
21140
|
this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, function (data) {
|
|
19555
|
-
return __awaiter(
|
|
19556
|
-
var
|
|
19557
|
-
return _regenerator().w(function (
|
|
19558
|
-
while (1) switch (
|
|
21141
|
+
return __awaiter(_this4, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
21142
|
+
var _t2;
|
|
21143
|
+
return _regenerator().w(function (_context2) {
|
|
21144
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
19559
21145
|
case 0:
|
|
19560
|
-
|
|
19561
|
-
|
|
21146
|
+
_context2.p = 0;
|
|
21147
|
+
_context2.n = 1;
|
|
19562
21148
|
return handler(data);
|
|
19563
21149
|
case 1:
|
|
19564
|
-
|
|
21150
|
+
_context2.n = 3;
|
|
19565
21151
|
break;
|
|
19566
21152
|
case 2:
|
|
19567
|
-
|
|
19568
|
-
|
|
19569
|
-
console.warn('Merchant onUnavailable handler threw (swallowed):',
|
|
21153
|
+
_context2.p = 2;
|
|
21154
|
+
_t2 = _context2.v;
|
|
21155
|
+
console.warn('Merchant onUnavailable handler threw (swallowed):', _t2);
|
|
19570
21156
|
case 3:
|
|
19571
|
-
return
|
|
21157
|
+
return _context2.a(2);
|
|
19572
21158
|
}
|
|
19573
|
-
},
|
|
21159
|
+
}, _callee2, null, [[0, 2]]);
|
|
19574
21160
|
}));
|
|
19575
21161
|
});
|
|
19576
21162
|
return;
|
|
@@ -19602,28 +21188,28 @@
|
|
|
19602
21188
|
}, {
|
|
19603
21189
|
key: "onError",
|
|
19604
21190
|
value: function onError(handler) {
|
|
19605
|
-
var
|
|
21191
|
+
var _this5 = this;
|
|
19606
21192
|
if (typeof handler === 'function') {
|
|
19607
21193
|
this.eventEmitter.subscribe(EVENT$1.ERROR, function (data) {
|
|
19608
|
-
return __awaiter(
|
|
19609
|
-
var
|
|
19610
|
-
return _regenerator().w(function (
|
|
19611
|
-
while (1) switch (
|
|
21194
|
+
return __awaiter(_this5, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
21195
|
+
var _t3;
|
|
21196
|
+
return _regenerator().w(function (_context3) {
|
|
21197
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
19612
21198
|
case 0:
|
|
19613
|
-
|
|
19614
|
-
|
|
21199
|
+
_context3.p = 0;
|
|
21200
|
+
_context3.n = 1;
|
|
19615
21201
|
return handler(data);
|
|
19616
21202
|
case 1:
|
|
19617
|
-
|
|
21203
|
+
_context3.n = 3;
|
|
19618
21204
|
break;
|
|
19619
21205
|
case 2:
|
|
19620
|
-
|
|
19621
|
-
|
|
19622
|
-
console.warn('Merchant onError handler threw (swallowed):',
|
|
21206
|
+
_context3.p = 2;
|
|
21207
|
+
_t3 = _context3.v;
|
|
21208
|
+
console.warn('Merchant onError handler threw (swallowed):', _t3);
|
|
19623
21209
|
case 3:
|
|
19624
|
-
return
|
|
21210
|
+
return _context3.a(2);
|
|
19625
21211
|
}
|
|
19626
|
-
},
|
|
21212
|
+
}, _callee3, null, [[0, 2]]);
|
|
19627
21213
|
}));
|
|
19628
21214
|
});
|
|
19629
21215
|
return;
|
|
@@ -19654,28 +21240,28 @@
|
|
|
19654
21240
|
}, {
|
|
19655
21241
|
key: "onCancel",
|
|
19656
21242
|
value: function onCancel(handler) {
|
|
19657
|
-
var
|
|
21243
|
+
var _this6 = this;
|
|
19658
21244
|
if (typeof handler === 'function') {
|
|
19659
21245
|
this.eventEmitter.subscribe(EVENT$1.CHECKOUT_CLOSE, function (data) {
|
|
19660
|
-
return __awaiter(
|
|
19661
|
-
var
|
|
19662
|
-
return _regenerator().w(function (
|
|
19663
|
-
while (1) switch (
|
|
21246
|
+
return __awaiter(_this6, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
21247
|
+
var _t4;
|
|
21248
|
+
return _regenerator().w(function (_context4) {
|
|
21249
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
19664
21250
|
case 0:
|
|
19665
|
-
|
|
19666
|
-
|
|
21251
|
+
_context4.p = 0;
|
|
21252
|
+
_context4.n = 1;
|
|
19667
21253
|
return handler(data);
|
|
19668
21254
|
case 1:
|
|
19669
|
-
|
|
21255
|
+
_context4.n = 3;
|
|
19670
21256
|
break;
|
|
19671
21257
|
case 2:
|
|
19672
|
-
|
|
19673
|
-
|
|
19674
|
-
console.warn('Merchant onCancel handler threw (swallowed):',
|
|
21258
|
+
_context4.p = 2;
|
|
21259
|
+
_t4 = _context4.v;
|
|
21260
|
+
console.warn('Merchant onCancel handler threw (swallowed):', _t4);
|
|
19675
21261
|
case 3:
|
|
19676
|
-
return
|
|
21262
|
+
return _context4.a(2);
|
|
19677
21263
|
}
|
|
19678
|
-
},
|
|
21264
|
+
}, _callee4, null, [[0, 2]]);
|
|
19679
21265
|
}));
|
|
19680
21266
|
});
|
|
19681
21267
|
return;
|
|
@@ -19699,28 +21285,28 @@
|
|
|
19699
21285
|
}, {
|
|
19700
21286
|
key: "onLoaded",
|
|
19701
21287
|
value: function onLoaded(handler) {
|
|
19702
|
-
var
|
|
21288
|
+
var _this7 = this;
|
|
19703
21289
|
if (typeof handler === 'function') {
|
|
19704
21290
|
this.eventEmitter.subscribe(EVENT$1.LOADED, function (data) {
|
|
19705
|
-
return __awaiter(
|
|
19706
|
-
var
|
|
19707
|
-
return _regenerator().w(function (
|
|
19708
|
-
while (1) switch (
|
|
21291
|
+
return __awaiter(_this7, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
21292
|
+
var _t5;
|
|
21293
|
+
return _regenerator().w(function (_context5) {
|
|
21294
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
19709
21295
|
case 0:
|
|
19710
|
-
|
|
19711
|
-
|
|
21296
|
+
_context5.p = 0;
|
|
21297
|
+
_context5.n = 1;
|
|
19712
21298
|
return handler(data);
|
|
19713
21299
|
case 1:
|
|
19714
|
-
|
|
21300
|
+
_context5.n = 3;
|
|
19715
21301
|
break;
|
|
19716
21302
|
case 2:
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
console.warn('Merchant onLoaded handler threw (swallowed):',
|
|
21303
|
+
_context5.p = 2;
|
|
21304
|
+
_t5 = _context5.v;
|
|
21305
|
+
console.warn('Merchant onLoaded handler threw (swallowed):', _t5);
|
|
19720
21306
|
case 3:
|
|
19721
|
-
return
|
|
21307
|
+
return _context5.a(2);
|
|
19722
21308
|
}
|
|
19723
|
-
},
|
|
21309
|
+
}, _callee5, null, [[0, 2]]);
|
|
19724
21310
|
}));
|
|
19725
21311
|
});
|
|
19726
21312
|
return;
|
|
@@ -20068,7 +21654,143 @@
|
|
|
20068
21654
|
WALLET_TYPES["GOOGLE_PAY"] = "google";
|
|
20069
21655
|
})(exports.WALLET_TYPES || (exports.WALLET_TYPES = {}));
|
|
20070
21656
|
|
|
20071
|
-
|
|
21657
|
+
/** CDN location of Apple's web SDK (provides the `<apple-pay-button>` web component). */
|
|
21658
|
+
var APPLE_PAY_SDK_URL = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
21659
|
+
/**
|
|
21660
|
+
* Statuses that count as available when the merchant does not override them.
|
|
21661
|
+
* Includes `paymentCredentialStatusUnknown` so the button is shown in third-party /
|
|
21662
|
+
* cross-device (QR) browsers, per Apple's guidance.
|
|
21663
|
+
*/
|
|
21664
|
+
var DEFAULT_APPLE_PAY_CAPABILITIES$1 = ['paymentCredentialsAvailable', 'paymentCredentialStatusUnknown'];
|
|
21665
|
+
/**
|
|
21666
|
+
* Maps the SDK's friendly capability tokens to Apple's `PaymentCredentialStatus` values.
|
|
21667
|
+
* Unknown tokens are passed through unchanged.
|
|
21668
|
+
*/
|
|
21669
|
+
function formatCapabilities(capabilities) {
|
|
21670
|
+
var fieldMap = {
|
|
21671
|
+
credentials_available: 'paymentCredentialsAvailable',
|
|
21672
|
+
credentials_status_unknown: 'paymentCredentialStatusUnknown',
|
|
21673
|
+
credentials_unavailable: 'paymentCredentialsUnavailable'
|
|
21674
|
+
};
|
|
21675
|
+
return capabilities.map(function (capability) {
|
|
21676
|
+
return fieldMap[capability] || capability;
|
|
21677
|
+
});
|
|
21678
|
+
}
|
|
21679
|
+
/**
|
|
21680
|
+
* Synchronous, network-free check for a **native, same-device** Apple Pay session
|
|
21681
|
+
* (`window.ApplePaySession` exists and `canMakePayments()` is `true`). Safe to call in
|
|
21682
|
+
* any environment (never throws).
|
|
21683
|
+
*
|
|
21684
|
+
* Note: this is a legacy/Safari-oriented signal. It is **not** authoritative for
|
|
21685
|
+
* cross-browser / cross-device (QR) availability — in Chrome/Edge/Firefox
|
|
21686
|
+
* `window.ApplePaySession` is supplied by the CDN SDK and may be absent until it loads,
|
|
21687
|
+
* and the cross-device flow is reflected by `applePayCapabilities()`, not this call.
|
|
21688
|
+
* Use {@link evaluateApplePayAvailability} for the authoritative, cross-browser answer.
|
|
21689
|
+
*/
|
|
21690
|
+
function hasNativeApplePaySession() {
|
|
21691
|
+
try {
|
|
21692
|
+
return typeof window !== 'undefined' && !!window.ApplePaySession && typeof ApplePaySession !== 'undefined' && ApplePaySession.canMakePayments();
|
|
21693
|
+
} catch (_a) {
|
|
21694
|
+
return false;
|
|
21695
|
+
}
|
|
21696
|
+
}
|
|
21697
|
+
var sdkLoadPromise = null;
|
|
21698
|
+
/**
|
|
21699
|
+
* Idempotently loads Apple's web SDK from the CDN.
|
|
21700
|
+
* Resolves immediately if the `<apple-pay-button>` custom element is already
|
|
21701
|
+
* registered, and de-duplicates concurrent loads. Rejects if the script fails to load.
|
|
21702
|
+
*/
|
|
21703
|
+
function loadApplePaySdk() {
|
|
21704
|
+
if (typeof customElements !== 'undefined' && customElements.get('apple-pay-button')) {
|
|
21705
|
+
return Promise.resolve();
|
|
21706
|
+
}
|
|
21707
|
+
if (sdkLoadPromise) {
|
|
21708
|
+
return sdkLoadPromise;
|
|
21709
|
+
}
|
|
21710
|
+
sdkLoadPromise = new Promise(function (resolve, reject) {
|
|
21711
|
+
var script = document.createElement('script');
|
|
21712
|
+
script.src = APPLE_PAY_SDK_URL;
|
|
21713
|
+
script.type = 'text/javascript';
|
|
21714
|
+
script.crossOrigin = 'anonymous';
|
|
21715
|
+
script.onload = function () {
|
|
21716
|
+
return resolve();
|
|
21717
|
+
};
|
|
21718
|
+
script.onerror = function () {
|
|
21719
|
+
// Allow a future retry after a transient failure.
|
|
21720
|
+
sdkLoadPromise = null;
|
|
21721
|
+
reject(new Error('Failed to load Apple Pay script'));
|
|
21722
|
+
};
|
|
21723
|
+
document.head.appendChild(script);
|
|
21724
|
+
});
|
|
21725
|
+
return sdkLoadPromise;
|
|
21726
|
+
}
|
|
21727
|
+
/**
|
|
21728
|
+
* Core Apple Pay availability evaluation, shared by the instance flow
|
|
21729
|
+
* (`ApplePayOpenWalletService`) and the static `ApplePayOpenWalletButton.checkAvailability`.
|
|
21730
|
+
*
|
|
21731
|
+
* Assumes the Apple Pay SDK is already loaded (call {@link loadApplePaySdk} first).
|
|
21732
|
+
*/
|
|
21733
|
+
function evaluateApplePayAvailability(params) {
|
|
21734
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
21735
|
+
var _a, hasNativeSession, allowed, capabilities, paymentCredentialStatus, available;
|
|
21736
|
+
return _regenerator().w(function (_context) {
|
|
21737
|
+
while (1) switch (_context.p = _context.n) {
|
|
21738
|
+
case 0:
|
|
21739
|
+
if (!(typeof window === 'undefined' || !window.ApplePaySession)) {
|
|
21740
|
+
_context.n = 1;
|
|
21741
|
+
break;
|
|
21742
|
+
}
|
|
21743
|
+
return _context.a(2, {
|
|
21744
|
+
available: false,
|
|
21745
|
+
supported: false,
|
|
21746
|
+
has_native_session: false,
|
|
21747
|
+
reason: 'unsupported_browser'
|
|
21748
|
+
});
|
|
21749
|
+
case 1:
|
|
21750
|
+
hasNativeSession = hasNativeApplePaySession();
|
|
21751
|
+
allowed = ((_a = params.apple_pay_capabilities) === null || _a === void 0 ? void 0 : _a.length) ? formatCapabilities(params.apple_pay_capabilities) : DEFAULT_APPLE_PAY_CAPABILITIES$1;
|
|
21752
|
+
_context.p = 2;
|
|
21753
|
+
_context.n = 3;
|
|
21754
|
+
return ApplePaySession.applePayCapabilities(params.merchantId);
|
|
21755
|
+
case 3:
|
|
21756
|
+
capabilities = _context.v;
|
|
21757
|
+
paymentCredentialStatus = capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus; // `applePayCapabilities` is authoritative: trust an explicit `applePayUnsupported`
|
|
21758
|
+
// (e.g. an unregistered/misconfigured merchant) rather than overriding it with the
|
|
21759
|
+
// coarse `canMakePayments()` signal.
|
|
21760
|
+
if (!(paymentCredentialStatus === 'applePayUnsupported')) {
|
|
21761
|
+
_context.n = 4;
|
|
21762
|
+
break;
|
|
21763
|
+
}
|
|
21764
|
+
return _context.a(2, {
|
|
21765
|
+
available: false,
|
|
21766
|
+
supported: false,
|
|
21767
|
+
has_native_session: hasNativeSession,
|
|
21768
|
+
payment_credential_status: paymentCredentialStatus,
|
|
21769
|
+
reason: 'unsupported_browser'
|
|
21770
|
+
});
|
|
21771
|
+
case 4:
|
|
21772
|
+
available = allowed.includes(paymentCredentialStatus);
|
|
21773
|
+
return _context.a(2, {
|
|
21774
|
+
available: available,
|
|
21775
|
+
supported: true,
|
|
21776
|
+
has_native_session: hasNativeSession,
|
|
21777
|
+
payment_credential_status: paymentCredentialStatus,
|
|
21778
|
+
reason: available ? undefined : 'no_credentials'
|
|
21779
|
+
});
|
|
21780
|
+
case 5:
|
|
21781
|
+
_context.p = 5;
|
|
21782
|
+
_context.v;
|
|
21783
|
+
return _context.a(2, {
|
|
21784
|
+
available: false,
|
|
21785
|
+
supported: hasNativeSession,
|
|
21786
|
+
has_native_session: hasNativeSession,
|
|
21787
|
+
reason: 'query_failed'
|
|
21788
|
+
});
|
|
21789
|
+
}
|
|
21790
|
+
}, _callee, null, [[2, 5]]);
|
|
21791
|
+
}));
|
|
21792
|
+
}
|
|
21793
|
+
|
|
20072
21794
|
/**
|
|
20073
21795
|
* Apple Pay implementation of the OpenWallet service.
|
|
20074
21796
|
*
|
|
@@ -20344,7 +22066,6 @@
|
|
|
20344
22066
|
value: function load() {
|
|
20345
22067
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
20346
22068
|
var _this4 = this;
|
|
20347
|
-
var applePayScript;
|
|
20348
22069
|
return _regenerator().w(function (_context3) {
|
|
20349
22070
|
while (1) switch (_context3.n) {
|
|
20350
22071
|
case 0:
|
|
@@ -20355,26 +22076,12 @@
|
|
|
20355
22076
|
this.handleOnUnavailable('Promises not supported');
|
|
20356
22077
|
return _context3.a(2);
|
|
20357
22078
|
case 1:
|
|
20358
|
-
|
|
20359
|
-
_context3.n = 2;
|
|
20360
|
-
break;
|
|
20361
|
-
}
|
|
20362
|
-
this.onScriptLoaded();
|
|
20363
|
-
return _context3.a(2);
|
|
20364
|
-
case 2:
|
|
20365
|
-
applePayScript = document.createElement('script');
|
|
20366
|
-
applePayScript.src = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
20367
|
-
applePayScript.type = 'text/javascript';
|
|
20368
|
-
applePayScript.crossOrigin = 'anonymous';
|
|
20369
|
-
applePayScript.onload = function () {
|
|
22079
|
+
loadApplePaySdk().then(function () {
|
|
20370
22080
|
_this4.onScriptLoaded();
|
|
20371
|
-
}
|
|
20372
|
-
applePayScript.onerror = function () {
|
|
22081
|
+
})["catch"](function () {
|
|
20373
22082
|
_this4.handleOnUnavailable('Failed to load Apple Pay script');
|
|
20374
|
-
|
|
20375
|
-
|
|
20376
|
-
document.head.appendChild(applePayScript);
|
|
20377
|
-
case 3:
|
|
22083
|
+
});
|
|
22084
|
+
case 2:
|
|
20378
22085
|
return _context3.a(2);
|
|
20379
22086
|
}
|
|
20380
22087
|
}, _callee3, this);
|
|
@@ -20402,26 +22109,22 @@
|
|
|
20402
22109
|
}, {
|
|
20403
22110
|
key: "checkAvailability",
|
|
20404
22111
|
value: function checkAvailability() {
|
|
20405
|
-
|
|
20406
|
-
|
|
20407
|
-
|
|
20408
|
-
|
|
20409
|
-
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
|
|
20415
|
-
|
|
20416
|
-
|
|
20417
|
-
|
|
22112
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
22113
|
+
var result;
|
|
22114
|
+
return _regenerator().w(function (_context4) {
|
|
22115
|
+
while (1) switch (_context4.n) {
|
|
22116
|
+
case 0:
|
|
22117
|
+
_context4.n = 1;
|
|
22118
|
+
return evaluateApplePayAvailability({
|
|
22119
|
+
merchantId: this.getMerchantId(),
|
|
22120
|
+
apple_pay_capabilities: this.meta.apple_pay_capabilities
|
|
22121
|
+
});
|
|
22122
|
+
case 1:
|
|
22123
|
+
result = _context4.v;
|
|
22124
|
+
return _context4.a(2, result.available);
|
|
20418
22125
|
}
|
|
20419
|
-
|
|
20420
|
-
|
|
20421
|
-
})["catch"](function () {
|
|
20422
|
-
resolve(false);
|
|
20423
|
-
});
|
|
20424
|
-
});
|
|
22126
|
+
}, _callee4, this);
|
|
22127
|
+
}));
|
|
20425
22128
|
}
|
|
20426
22129
|
}, {
|
|
20427
22130
|
key: "mount",
|
|
@@ -20447,7 +22150,7 @@
|
|
|
20447
22150
|
}, {
|
|
20448
22151
|
key: "onApplePayButtonClicked",
|
|
20449
22152
|
value: function onApplePayButtonClicked() {
|
|
20450
|
-
var
|
|
22153
|
+
var _this6 = this;
|
|
20451
22154
|
if (this.isButtonDisabled()) {
|
|
20452
22155
|
return;
|
|
20453
22156
|
}
|
|
@@ -20466,26 +22169,27 @@
|
|
|
20466
22169
|
// As part of PAYCA-2065 we detect that the paymentSession.onvalidatemerchant is not
|
|
20467
22170
|
// executed if the browser is not safari. In that case, we handle it outside the
|
|
20468
22171
|
// actual merchant validation function.
|
|
20469
|
-
var
|
|
20470
|
-
var
|
|
22172
|
+
var userAgent = navigator.userAgent || '';
|
|
22173
|
+
var isIOS = userAgent.includes('iPhone') || userAgent.includes('iPad') || userAgent.includes('iPod');
|
|
22174
|
+
var isDesktopRequestIOS = navigator.maxTouchPoints > 1 && userAgent.includes('Macintosh');
|
|
20471
22175
|
if (!window.safari && !isIOS && !isDesktopRequestIOS) {
|
|
20472
22176
|
this.handleMerchantOnButtonClickEvent()["catch"](function (err) {
|
|
20473
22177
|
console.error('Error while processing merchant callback', err);
|
|
20474
|
-
|
|
22178
|
+
_this6.paymentSession.abort();
|
|
20475
22179
|
});
|
|
20476
22180
|
}
|
|
20477
22181
|
}
|
|
20478
22182
|
}, {
|
|
20479
22183
|
key: "getMerchantSession",
|
|
20480
22184
|
value: function getMerchantSession() {
|
|
20481
|
-
var
|
|
22185
|
+
var _this7 = this;
|
|
20482
22186
|
return new Promise(function (resolve, reject) {
|
|
20483
|
-
return
|
|
20484
|
-
service_id:
|
|
22187
|
+
return _this7.api.paymentSource().createSession(_extends({
|
|
22188
|
+
service_id: _this7.serviceId,
|
|
20485
22189
|
session_id: window.location.hostname,
|
|
20486
|
-
store_name:
|
|
20487
|
-
},
|
|
20488
|
-
request_shipping:
|
|
22190
|
+
store_name: _this7.meta.store_name
|
|
22191
|
+
}, _this7.isShippingRequired() && {
|
|
22192
|
+
request_shipping: _this7.meta.request_shipping
|
|
20489
22193
|
})).then(function (res) {
|
|
20490
22194
|
resolve(res);
|
|
20491
22195
|
})["catch"](function (err) {
|
|
@@ -20496,42 +22200,30 @@
|
|
|
20496
22200
|
}, {
|
|
20497
22201
|
key: "handleMerchantOnButtonClickEvent",
|
|
20498
22202
|
value: function handleMerchantOnButtonClickEvent() {
|
|
20499
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function
|
|
22203
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
20500
22204
|
var results;
|
|
20501
|
-
return _regenerator().w(function (
|
|
20502
|
-
while (1) switch (
|
|
22205
|
+
return _regenerator().w(function (_context5) {
|
|
22206
|
+
while (1) switch (_context5.n) {
|
|
20503
22207
|
case 0:
|
|
20504
|
-
|
|
22208
|
+
_context5.n = 1;
|
|
20505
22209
|
return this.eventEmitter.emitWithResult(EVENT$1.ON_CLICK, {
|
|
20506
22210
|
event: EVENT$1.ON_CLICK
|
|
20507
22211
|
});
|
|
20508
22212
|
case 1:
|
|
20509
|
-
results =
|
|
22213
|
+
results = _context5.v;
|
|
20510
22214
|
if (!results.some(function (r) {
|
|
20511
22215
|
return r === false;
|
|
20512
22216
|
})) {
|
|
20513
|
-
|
|
22217
|
+
_context5.n = 2;
|
|
20514
22218
|
break;
|
|
20515
22219
|
}
|
|
20516
22220
|
throw new Error('onClick handler aborted the payment flow');
|
|
20517
22221
|
case 2:
|
|
20518
|
-
return
|
|
22222
|
+
return _context5.a(2);
|
|
20519
22223
|
}
|
|
20520
|
-
},
|
|
22224
|
+
}, _callee5, this);
|
|
20521
22225
|
}));
|
|
20522
22226
|
}
|
|
20523
|
-
}, {
|
|
20524
|
-
key: "formatCapabilities",
|
|
20525
|
-
value: function formatCapabilities(capabilities) {
|
|
20526
|
-
var fieldMap = {
|
|
20527
|
-
credentials_available: 'paymentCredentialsAvailable',
|
|
20528
|
-
credentials_status_unknown: 'paymentCredentialStatusUnknown',
|
|
20529
|
-
credentials_unavailable: 'paymentCredentialsUnavailable'
|
|
20530
|
-
};
|
|
20531
|
-
return capabilities.map(function (capability) {
|
|
20532
|
-
return fieldMap[capability] || capability;
|
|
20533
|
-
});
|
|
20534
|
-
}
|
|
20535
22227
|
}, {
|
|
20536
22228
|
key: "formatErrorFields",
|
|
20537
22229
|
value: function formatErrorFields(error) {
|
|
@@ -20698,11 +22390,6 @@
|
|
|
20698
22390
|
applePayLaterAvailability: this.meta.apple_pay_later_availability
|
|
20699
22391
|
});
|
|
20700
22392
|
}
|
|
20701
|
-
}, {
|
|
20702
|
-
key: "isUnsuportedBrowser",
|
|
20703
|
-
value: function isUnsuportedBrowser(capabilities) {
|
|
20704
|
-
return (capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus) === 'applePayUnsupported';
|
|
20705
|
-
}
|
|
20706
22393
|
}]);
|
|
20707
22394
|
}(OpenWalletService);
|
|
20708
22395
|
|
|
@@ -20751,17 +22438,57 @@
|
|
|
20751
22438
|
return _this;
|
|
20752
22439
|
}
|
|
20753
22440
|
/**
|
|
20754
|
-
*
|
|
20755
|
-
*
|
|
22441
|
+
* Checks Apple Pay availability **without instantiating the button** — the single,
|
|
22442
|
+
* authoritative, cross-browser-aware availability entry point.
|
|
20756
22443
|
*
|
|
20757
|
-
*
|
|
20758
|
-
*
|
|
20759
|
-
*
|
|
22444
|
+
* Resolves the merchant identifier (either supplied directly or fetched from the
|
|
22445
|
+
* service configuration), loads Apple's web SDK if needed, then queries
|
|
22446
|
+
* `ApplePaySession.applePayCapabilities()`. Returns a convenience `available` verdict
|
|
22447
|
+
* (computed against `apple_pay_capabilities`), the raw device-reported
|
|
22448
|
+
* `payment_credential_status`, and `has_native_session` so callers can infer the transport:
|
|
22449
|
+
* `available && has_native_session` ⇒ native sheet likely; `available && !has_native_session`
|
|
22450
|
+
* ⇒ cross-device / QR handoff likely.
|
|
22451
|
+
*
|
|
22452
|
+
* Pass `{ sync: true }` for a cheap, network-free native same-device pre-check that
|
|
22453
|
+
* resolves immediately (see {@link ApplePayAvailabilityOptions.sync}).
|
|
22454
|
+
*
|
|
22455
|
+
* @param {ApplePayAvailabilityOptions} [options] - Merchant context, allowed capabilities, and mode.
|
|
22456
|
+
* @returns {Promise<ApplePayAvailabilityResult>} The availability result.
|
|
22457
|
+
*
|
|
22458
|
+
* @example
|
|
22459
|
+
* // Lightest path — no network, when you already know the merchant identifier:
|
|
22460
|
+
* const result = await ApplePayOpenWalletButton.checkAvailability({ merchant_id });
|
|
22461
|
+
*
|
|
22462
|
+
* @example
|
|
22463
|
+
* // Resolve the merchant identifier from the service configuration:
|
|
22464
|
+
* const result = await ApplePayOpenWalletButton.checkAvailability({
|
|
22465
|
+
* public_key_or_access_token,
|
|
22466
|
+
* service_id,
|
|
22467
|
+
* env: 'sandbox',
|
|
22468
|
+
* });
|
|
22469
|
+
* if (result.available) {
|
|
22470
|
+
* // Render the Apple Pay button (native sheet or cross-device QR, per has_native_session).
|
|
22471
|
+
* } else {
|
|
22472
|
+
* console.log('Unavailable:', result.reason, result.payment_credential_status);
|
|
22473
|
+
* }
|
|
22474
|
+
*
|
|
22475
|
+
* @example
|
|
22476
|
+
* // Synchronous native-only fast check (no network / SDK load):
|
|
22477
|
+
* const { has_native_session } = await ApplePayOpenWalletButton.checkAvailability({ sync: true });
|
|
20760
22478
|
*/
|
|
20761
22479
|
_inherits(ApplePayOpenWalletButton, _OpenWalletButtons);
|
|
20762
22480
|
return _createClass(ApplePayOpenWalletButton, [{
|
|
20763
22481
|
key: "validateWalletMeta",
|
|
20764
|
-
value:
|
|
22482
|
+
value:
|
|
22483
|
+
/**
|
|
22484
|
+
* Validates Apple Pay-specific required metadata fields.
|
|
22485
|
+
* Apple Pay requires `amount_label` and `store_name` to be present and strings.
|
|
22486
|
+
*
|
|
22487
|
+
* @private
|
|
22488
|
+
* @throws {Error} If `amount_label` is missing or not a string.
|
|
22489
|
+
* @throws {Error} If `store_name` is missing or not a string.
|
|
22490
|
+
*/
|
|
22491
|
+
function validateWalletMeta() {
|
|
20765
22492
|
if (typeof this.meta.amount_label !== 'string' || this.meta.amount_label.trim() === '') {
|
|
20766
22493
|
throw new Error("meta.amount_label is required for Apple Pay and must be a non-empty string (e.g. 'TOTAL').");
|
|
20767
22494
|
}
|
|
@@ -20795,6 +22522,114 @@
|
|
|
20795
22522
|
value: function createWalletService(serviceConfig) {
|
|
20796
22523
|
return new ApplePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
|
|
20797
22524
|
}
|
|
22525
|
+
}], [{
|
|
22526
|
+
key: "checkAvailability",
|
|
22527
|
+
value: function checkAvailability() {
|
|
22528
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
22529
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22530
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
22531
|
+
var hasNativeSession, merchantId, authType, api, serviceConfig;
|
|
22532
|
+
return _regenerator().w(function (_context) {
|
|
22533
|
+
while (1) switch (_context.p = _context.n) {
|
|
22534
|
+
case 0:
|
|
22535
|
+
hasNativeSession = hasNativeApplePaySession();
|
|
22536
|
+
if (!options.sync) {
|
|
22537
|
+
_context.n = 1;
|
|
22538
|
+
break;
|
|
22539
|
+
}
|
|
22540
|
+
return _context.a(2, {
|
|
22541
|
+
available: hasNativeSession,
|
|
22542
|
+
supported: hasNativeSession,
|
|
22543
|
+
has_native_session: hasNativeSession,
|
|
22544
|
+
reason: hasNativeSession ? undefined : 'no_native_session'
|
|
22545
|
+
});
|
|
22546
|
+
case 1:
|
|
22547
|
+
merchantId = options.merchant_id;
|
|
22548
|
+
if (merchantId) {
|
|
22549
|
+
_context.n = 6;
|
|
22550
|
+
break;
|
|
22551
|
+
}
|
|
22552
|
+
if (!(!options.public_key_or_access_token || !options.service_id)) {
|
|
22553
|
+
_context.n = 2;
|
|
22554
|
+
break;
|
|
22555
|
+
}
|
|
22556
|
+
return _context.a(2, {
|
|
22557
|
+
available: false,
|
|
22558
|
+
supported: hasNativeSession,
|
|
22559
|
+
has_native_session: hasNativeSession,
|
|
22560
|
+
reason: 'missing_merchant_id'
|
|
22561
|
+
});
|
|
22562
|
+
case 2:
|
|
22563
|
+
_context.p = 2;
|
|
22564
|
+
authType = AccessToken.validateJWT(options.public_key_or_access_token) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
|
|
22565
|
+
api = new ApiInternal(options.public_key_or_access_token, authType);
|
|
22566
|
+
if (options.env) {
|
|
22567
|
+
api.setEnv(options.env);
|
|
22568
|
+
}
|
|
22569
|
+
_context.n = 3;
|
|
22570
|
+
return getServiceConfigCached(api, options.service_id);
|
|
22571
|
+
case 3:
|
|
22572
|
+
serviceConfig = _context.v;
|
|
22573
|
+
if (!(serviceConfig.type !== SERVICE_TYPES.APPLE_PAY)) {
|
|
22574
|
+
_context.n = 4;
|
|
22575
|
+
break;
|
|
22576
|
+
}
|
|
22577
|
+
return _context.a(2, {
|
|
22578
|
+
available: false,
|
|
22579
|
+
supported: hasNativeSession,
|
|
22580
|
+
has_native_session: hasNativeSession,
|
|
22581
|
+
reason: 'service_type_mismatch'
|
|
22582
|
+
});
|
|
22583
|
+
case 4:
|
|
22584
|
+
merchantId = serviceConfig.merchant;
|
|
22585
|
+
_context.n = 6;
|
|
22586
|
+
break;
|
|
22587
|
+
case 5:
|
|
22588
|
+
_context.p = 5;
|
|
22589
|
+
_context.v;
|
|
22590
|
+
return _context.a(2, {
|
|
22591
|
+
available: false,
|
|
22592
|
+
supported: hasNativeSession,
|
|
22593
|
+
has_native_session: hasNativeSession,
|
|
22594
|
+
reason: 'config_fetch_failed'
|
|
22595
|
+
});
|
|
22596
|
+
case 6:
|
|
22597
|
+
if (merchantId) {
|
|
22598
|
+
_context.n = 7;
|
|
22599
|
+
break;
|
|
22600
|
+
}
|
|
22601
|
+
return _context.a(2, {
|
|
22602
|
+
available: false,
|
|
22603
|
+
supported: hasNativeSession,
|
|
22604
|
+
has_native_session: hasNativeSession,
|
|
22605
|
+
reason: 'missing_merchant_id'
|
|
22606
|
+
});
|
|
22607
|
+
case 7:
|
|
22608
|
+
_context.p = 7;
|
|
22609
|
+
_context.n = 8;
|
|
22610
|
+
return loadApplePaySdk();
|
|
22611
|
+
case 8:
|
|
22612
|
+
_context.n = 10;
|
|
22613
|
+
break;
|
|
22614
|
+
case 9:
|
|
22615
|
+
_context.p = 9;
|
|
22616
|
+
_context.v;
|
|
22617
|
+
return _context.a(2, {
|
|
22618
|
+
available: false,
|
|
22619
|
+
supported: hasNativeSession,
|
|
22620
|
+
has_native_session: hasNativeSession,
|
|
22621
|
+
reason: 'sdk_load_failed'
|
|
22622
|
+
});
|
|
22623
|
+
case 10:
|
|
22624
|
+
return _context.a(2, evaluateApplePayAvailability({
|
|
22625
|
+
merchantId: merchantId,
|
|
22626
|
+
apple_pay_capabilities: options.apple_pay_capabilities
|
|
22627
|
+
}));
|
|
22628
|
+
}
|
|
22629
|
+
}, _callee, null, [[7, 9], [2, 5]]);
|
|
22630
|
+
})();
|
|
22631
|
+
});
|
|
22632
|
+
}
|
|
20798
22633
|
}]);
|
|
20799
22634
|
}(OpenWalletButtons);
|
|
20800
22635
|
|
|
@@ -20831,6 +22666,137 @@
|
|
|
20831
22666
|
SHIPPING_OPTION: EVENT$1.ON_SHIPPING_OPTIONS_CHANGE
|
|
20832
22667
|
});
|
|
20833
22668
|
|
|
22669
|
+
/**
|
|
22670
|
+
* Synchronous, network-free check for whether the Google Pay JS API is already present
|
|
22671
|
+
* in the page (`window.google.payments.api.PaymentsClient`). Safe to call in any
|
|
22672
|
+
* environment (never throws).
|
|
22673
|
+
*
|
|
22674
|
+
* Note: Google Pay has no synchronous device/card capability API — this only reports
|
|
22675
|
+
* whether the SDK script has loaded. The authoritative readiness signal comes from
|
|
22676
|
+
* {@link evaluateGooglePayAvailability} (which runs `isReadyToPay`).
|
|
22677
|
+
*/
|
|
22678
|
+
function isGooglePayApiPresent() {
|
|
22679
|
+
var _a, _b, _c;
|
|
22680
|
+
try {
|
|
22681
|
+
return typeof window !== 'undefined' && !!((_c = (_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.payments) === null || _b === void 0 ? void 0 : _b.api) === null || _c === void 0 ? void 0 : _c.PaymentsClient);
|
|
22682
|
+
} catch (_d) {
|
|
22683
|
+
return false;
|
|
22684
|
+
}
|
|
22685
|
+
}
|
|
22686
|
+
var scriptLoadPromise = null;
|
|
22687
|
+
/**
|
|
22688
|
+
* Idempotently loads the Google Pay JS SDK from the CDN.
|
|
22689
|
+
* Resolves immediately if the API is already present, de-duplicates concurrent loads,
|
|
22690
|
+
* and rejects if the script fails to load.
|
|
22691
|
+
*/
|
|
22692
|
+
function loadGooglePayScript() {
|
|
22693
|
+
if (isGooglePayApiPresent()) {
|
|
22694
|
+
return Promise.resolve();
|
|
22695
|
+
}
|
|
22696
|
+
if (scriptLoadPromise) {
|
|
22697
|
+
return scriptLoadPromise;
|
|
22698
|
+
}
|
|
22699
|
+
scriptLoadPromise = new Promise(function (resolve, reject) {
|
|
22700
|
+
var script = document.createElement('script');
|
|
22701
|
+
script.type = 'text/javascript';
|
|
22702
|
+
script.src = GOOGLE_PAY_SCRIPT_URL;
|
|
22703
|
+
script.async = true;
|
|
22704
|
+
script.onload = function () {
|
|
22705
|
+
if (!isGooglePayApiPresent()) {
|
|
22706
|
+
scriptLoadPromise = null;
|
|
22707
|
+
reject(new Error('Google Pay not available'));
|
|
22708
|
+
return;
|
|
22709
|
+
}
|
|
22710
|
+
resolve();
|
|
22711
|
+
};
|
|
22712
|
+
script.onerror = function () {
|
|
22713
|
+
// Allow a future retry after a transient failure.
|
|
22714
|
+
scriptLoadPromise = null;
|
|
22715
|
+
reject(new Error('Failed to load Google Pay script'));
|
|
22716
|
+
};
|
|
22717
|
+
document.head.appendChild(script);
|
|
22718
|
+
});
|
|
22719
|
+
return scriptLoadPromise;
|
|
22720
|
+
}
|
|
22721
|
+
/**
|
|
22722
|
+
* Builds the base `isReadyToPay` request using the default card configuration
|
|
22723
|
+
* (standard auth methods + card networks). Mirrors the instance service's request:
|
|
22724
|
+
* `existingPaymentMethodRequired` is `false` on Safari (where Google Pay surfaces a
|
|
22725
|
+
* different flow) and `true` elsewhere.
|
|
22726
|
+
*/
|
|
22727
|
+
function buildIsReadyToPayRequest() {
|
|
22728
|
+
var isSafariBrowser = Browser.getBrowserName() === 'Apple Safari';
|
|
22729
|
+
return _extends(_extends({}, GOOGLE_PAY_API_CONFIG), {
|
|
22730
|
+
allowedPaymentMethods: [{
|
|
22731
|
+
type: 'CARD',
|
|
22732
|
+
parameters: {
|
|
22733
|
+
allowedAuthMethods: GOOGLE_PAY_AUTH_METHODS,
|
|
22734
|
+
allowedCardNetworks: GOOGLE_PAY_CARD_NETWORKS
|
|
22735
|
+
}
|
|
22736
|
+
}],
|
|
22737
|
+
existingPaymentMethodRequired: !isSafariBrowser
|
|
22738
|
+
});
|
|
22739
|
+
}
|
|
22740
|
+
/**
|
|
22741
|
+
* Core Google Pay availability evaluation, shared by the instance flow
|
|
22742
|
+
* (`GooglePayOpenWalletService`) and the static `GooglePayOpenWalletButton.checkAvailability`.
|
|
22743
|
+
*
|
|
22744
|
+
* The static check passes no `request`, so it uses the **default** card configuration
|
|
22745
|
+
* (a button instance with a custom `card_config` may produce a different result). The
|
|
22746
|
+
* instance flow passes its own `paymentsClient` and `request` so the readiness check
|
|
22747
|
+
* honours the merchant's `card_config` and runs against the same client it pays with.
|
|
22748
|
+
*
|
|
22749
|
+
* Assumes the Google Pay SDK is already loaded (call {@link loadGooglePayScript} first).
|
|
22750
|
+
*/
|
|
22751
|
+
function evaluateGooglePayAvailability() {
|
|
22752
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
22753
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22754
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
22755
|
+
var _a, _b, paymentsClient, response, available;
|
|
22756
|
+
return _regenerator().w(function (_context) {
|
|
22757
|
+
while (1) switch (_context.p = _context.n) {
|
|
22758
|
+
case 0:
|
|
22759
|
+
if (isGooglePayApiPresent()) {
|
|
22760
|
+
_context.n = 1;
|
|
22761
|
+
break;
|
|
22762
|
+
}
|
|
22763
|
+
return _context.a(2, {
|
|
22764
|
+
available: false,
|
|
22765
|
+
supported: false,
|
|
22766
|
+
reason: 'unsupported_browser'
|
|
22767
|
+
});
|
|
22768
|
+
case 1:
|
|
22769
|
+
_context.p = 1;
|
|
22770
|
+
paymentsClient = (_a = params.paymentsClient) !== null && _a !== void 0 ? _a : new google.payments.api.PaymentsClient({
|
|
22771
|
+
merchantInfo: {
|
|
22772
|
+
merchantId: params.merchantId || ''
|
|
22773
|
+
}
|
|
22774
|
+
});
|
|
22775
|
+
_context.n = 2;
|
|
22776
|
+
return paymentsClient.isReadyToPay((_b = params.request) !== null && _b !== void 0 ? _b : buildIsReadyToPayRequest());
|
|
22777
|
+
case 2:
|
|
22778
|
+
response = _context.v;
|
|
22779
|
+
available = !!response.result;
|
|
22780
|
+
return _context.a(2, {
|
|
22781
|
+
available: available,
|
|
22782
|
+
supported: true,
|
|
22783
|
+
payment_method_present: response.paymentMethodPresent,
|
|
22784
|
+
reason: available ? undefined : 'no_payment_method'
|
|
22785
|
+
});
|
|
22786
|
+
case 3:
|
|
22787
|
+
_context.p = 3;
|
|
22788
|
+
_context.v;
|
|
22789
|
+
return _context.a(2, {
|
|
22790
|
+
available: false,
|
|
22791
|
+
supported: isGooglePayApiPresent(),
|
|
22792
|
+
reason: 'query_failed'
|
|
22793
|
+
});
|
|
22794
|
+
}
|
|
22795
|
+
}, _callee, null, [[1, 3]]);
|
|
22796
|
+
})();
|
|
22797
|
+
});
|
|
22798
|
+
}
|
|
22799
|
+
|
|
20834
22800
|
/**
|
|
20835
22801
|
* Parses intermediate payment data from Google Pay into a normalized format
|
|
20836
22802
|
* for use in shipping address/option change events.
|
|
@@ -21166,14 +23132,18 @@
|
|
|
21166
23132
|
key: "checkAvailability",
|
|
21167
23133
|
value: function checkAvailability() {
|
|
21168
23134
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
23135
|
+
var result;
|
|
21169
23136
|
return _regenerator().w(function (_context2) {
|
|
21170
23137
|
while (1) switch (_context2.n) {
|
|
21171
23138
|
case 0:
|
|
21172
|
-
|
|
21173
|
-
|
|
21174
|
-
|
|
21175
|
-
|
|
21176
|
-
})
|
|
23139
|
+
_context2.n = 1;
|
|
23140
|
+
return evaluateGooglePayAvailability({
|
|
23141
|
+
paymentsClient: this.paymentsClient,
|
|
23142
|
+
request: this.createRequest()
|
|
23143
|
+
});
|
|
23144
|
+
case 1:
|
|
23145
|
+
result = _context2.v;
|
|
23146
|
+
return _context2.a(2, result.available);
|
|
21177
23147
|
}
|
|
21178
23148
|
}, _callee2, this);
|
|
21179
23149
|
}));
|
|
@@ -21631,14 +23601,46 @@
|
|
|
21631
23601
|
return _this;
|
|
21632
23602
|
}
|
|
21633
23603
|
/**
|
|
21634
|
-
*
|
|
21635
|
-
*
|
|
21636
|
-
*
|
|
23604
|
+
* Checks Google Pay availability **without instantiating the button** — the static
|
|
23605
|
+
* availability entry point.
|
|
23606
|
+
*
|
|
23607
|
+
* Loads the Google Pay JS SDK if needed, then runs `PaymentsClient.isReadyToPay()` using
|
|
23608
|
+
* the **default** card configuration (a button instance with a custom `card_config` may
|
|
23609
|
+
* produce a different result). All options are optional — unlike Apple Pay, Google Pay's
|
|
23610
|
+
* readiness check does not require a merchant identifier; supplying `service_id` +
|
|
23611
|
+
* `public_key_or_access_token` additionally validates that the service is a Google Pay service.
|
|
23612
|
+
*
|
|
23613
|
+
* Pass `{ sync: true }` for a cheap, network-free check that only reports whether the
|
|
23614
|
+
* Google Pay JS API is already present (see {@link GooglePayAvailabilityOptions.sync}).
|
|
23615
|
+
*
|
|
23616
|
+
* @param {GooglePayAvailabilityOptions} [options] - Optional merchant context and mode.
|
|
23617
|
+
* @returns {Promise<GooglePayAvailabilityResult>} The availability result.
|
|
23618
|
+
*
|
|
23619
|
+
* @example
|
|
23620
|
+
* // Simplest form — no merchant context needed:
|
|
23621
|
+
* const result = await GooglePayOpenWalletButton.checkAvailability();
|
|
23622
|
+
* if (result.available) {
|
|
23623
|
+
* // Render the Google Pay button.
|
|
23624
|
+
* }
|
|
23625
|
+
*
|
|
23626
|
+
* @example
|
|
23627
|
+
* // Validate the service is a Google Pay service while checking:
|
|
23628
|
+
* const result = await GooglePayOpenWalletButton.checkAvailability({
|
|
23629
|
+
* public_key_or_access_token,
|
|
23630
|
+
* service_id,
|
|
23631
|
+
* env: 'sandbox',
|
|
23632
|
+
* });
|
|
21637
23633
|
*/
|
|
21638
23634
|
_inherits(GooglePayOpenWalletButton, _OpenWalletButtons);
|
|
21639
23635
|
return _createClass(GooglePayOpenWalletButton, [{
|
|
21640
23636
|
key: "validateWalletMeta",
|
|
21641
|
-
value:
|
|
23637
|
+
value:
|
|
23638
|
+
/**
|
|
23639
|
+
* Validates Google Pay-specific required metadata fields.
|
|
23640
|
+
* Google Pay has no additional required fields beyond the base (amount, currency, country).
|
|
23641
|
+
* @private
|
|
23642
|
+
*/
|
|
23643
|
+
function validateWalletMeta() {
|
|
21642
23644
|
// Google Pay has no additional required meta fields beyond the base.
|
|
21643
23645
|
// Optional fields (merchant_name, card_config, etc.) are validated
|
|
21644
23646
|
// at runtime by the Google Pay SDK.
|
|
@@ -21669,6 +23671,87 @@
|
|
|
21669
23671
|
value: function createWalletService(serviceConfig) {
|
|
21670
23672
|
return new GooglePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
|
|
21671
23673
|
}
|
|
23674
|
+
}], [{
|
|
23675
|
+
key: "checkAvailability",
|
|
23676
|
+
value: function checkAvailability() {
|
|
23677
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
23678
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23679
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
23680
|
+
var present, merchantId, authType, api, serviceConfig;
|
|
23681
|
+
return _regenerator().w(function (_context) {
|
|
23682
|
+
while (1) switch (_context.p = _context.n) {
|
|
23683
|
+
case 0:
|
|
23684
|
+
if (!options.sync) {
|
|
23685
|
+
_context.n = 1;
|
|
23686
|
+
break;
|
|
23687
|
+
}
|
|
23688
|
+
present = isGooglePayApiPresent();
|
|
23689
|
+
return _context.a(2, {
|
|
23690
|
+
available: present,
|
|
23691
|
+
supported: present,
|
|
23692
|
+
reason: present ? undefined : 'api_not_loaded'
|
|
23693
|
+
});
|
|
23694
|
+
case 1:
|
|
23695
|
+
merchantId = options.merchant_id;
|
|
23696
|
+
if (!(!merchantId && options.public_key_or_access_token && options.service_id)) {
|
|
23697
|
+
_context.n = 6;
|
|
23698
|
+
break;
|
|
23699
|
+
}
|
|
23700
|
+
_context.p = 2;
|
|
23701
|
+
authType = AccessToken.validateJWT(options.public_key_or_access_token) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
|
|
23702
|
+
api = new ApiInternal(options.public_key_or_access_token, authType);
|
|
23703
|
+
if (options.env) {
|
|
23704
|
+
api.setEnv(options.env);
|
|
23705
|
+
}
|
|
23706
|
+
_context.n = 3;
|
|
23707
|
+
return getServiceConfigCached(api, options.service_id);
|
|
23708
|
+
case 3:
|
|
23709
|
+
serviceConfig = _context.v;
|
|
23710
|
+
if (!(serviceConfig.type !== SERVICE_TYPES.GOOGLE_PAY)) {
|
|
23711
|
+
_context.n = 4;
|
|
23712
|
+
break;
|
|
23713
|
+
}
|
|
23714
|
+
return _context.a(2, {
|
|
23715
|
+
available: false,
|
|
23716
|
+
supported: isGooglePayApiPresent(),
|
|
23717
|
+
reason: 'service_type_mismatch'
|
|
23718
|
+
});
|
|
23719
|
+
case 4:
|
|
23720
|
+
merchantId = serviceConfig.merchant;
|
|
23721
|
+
_context.n = 6;
|
|
23722
|
+
break;
|
|
23723
|
+
case 5:
|
|
23724
|
+
_context.p = 5;
|
|
23725
|
+
_context.v;
|
|
23726
|
+
return _context.a(2, {
|
|
23727
|
+
available: false,
|
|
23728
|
+
supported: isGooglePayApiPresent(),
|
|
23729
|
+
reason: 'config_fetch_failed'
|
|
23730
|
+
});
|
|
23731
|
+
case 6:
|
|
23732
|
+
_context.p = 6;
|
|
23733
|
+
_context.n = 7;
|
|
23734
|
+
return loadGooglePayScript();
|
|
23735
|
+
case 7:
|
|
23736
|
+
_context.n = 9;
|
|
23737
|
+
break;
|
|
23738
|
+
case 8:
|
|
23739
|
+
_context.p = 8;
|
|
23740
|
+
_context.v;
|
|
23741
|
+
return _context.a(2, {
|
|
23742
|
+
available: false,
|
|
23743
|
+
supported: isGooglePayApiPresent(),
|
|
23744
|
+
reason: 'sdk_load_failed'
|
|
23745
|
+
});
|
|
23746
|
+
case 9:
|
|
23747
|
+
return _context.a(2, evaluateGooglePayAvailability({
|
|
23748
|
+
merchantId: merchantId
|
|
23749
|
+
}));
|
|
23750
|
+
}
|
|
23751
|
+
}, _callee, null, [[6, 8], [2, 5]]);
|
|
23752
|
+
})();
|
|
23753
|
+
});
|
|
23754
|
+
}
|
|
21672
23755
|
}]);
|
|
21673
23756
|
}(OpenWalletButtons);
|
|
21674
23757
|
|
|
@@ -44739,6 +46822,7 @@
|
|
|
44739
46822
|
exports.ApplePayOpenWalletButton = ApplePayOpenWalletButton;
|
|
44740
46823
|
exports.ApplePayWalletButtonExpress = ApplePayWalletButtonExpress;
|
|
44741
46824
|
exports.CANVAS_3DS_EVENT = CANVAS_3DS_EVENT;
|
|
46825
|
+
exports.CARD_SCHEME = CARD_SCHEME;
|
|
44742
46826
|
exports.CHECKOUT_BUTTON_EVENT = CHECKOUT_BUTTON_EVENT;
|
|
44743
46827
|
exports.CHECKOUT_EVENT = EVENT$2;
|
|
44744
46828
|
exports.Canvas3ds = Canvas3ds;
|