@paydock/client-sdk 1.144.1-beta → 1.145.0-beta
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 +422 -31
- package/bundles/index.cjs +1972 -532
- package/bundles/index.cjs.d.ts +192 -8
- package/bundles/index.mjs +1972 -532
- package/bundles/index.mjs.d.ts +192 -8
- 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/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/widget.umd.js +1972 -532
- package/bundles/widget.umd.js.d.ts +192 -8
- package/bundles/widget.umd.js.min.d.ts +192 -8
- package/bundles/widget.umd.min.js +1 -1
- package/docs/open-wallet-buttons-examples.md +170 -2
- package/docs/open-wallet-buttons.md +252 -29
- package/package.json +10 -7
- package/slate.md +170 -2
package/bundles/index.cjs
CHANGED
|
@@ -830,16 +830,28 @@ var Browser = /*#__PURE__*/function () {
|
|
|
830
830
|
value: function getBrowserName() {
|
|
831
831
|
var sUsrAg = navigator.userAgent;
|
|
832
832
|
// "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
|
|
833
|
-
if (sUsrAg.indexOf('Firefox') > -1)
|
|
834
|
-
|
|
833
|
+
if (sUsrAg.indexOf('Firefox') > -1) {
|
|
834
|
+
return 'Mozilla Firefox';
|
|
835
|
+
}
|
|
836
|
+
if (sUsrAg.indexOf('Opera') > -1) {
|
|
837
|
+
return 'Opera';
|
|
838
|
+
}
|
|
835
839
|
// "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"
|
|
836
|
-
if (sUsrAg.indexOf('Trident') > -1)
|
|
840
|
+
if (sUsrAg.indexOf('Trident') > -1) {
|
|
841
|
+
return 'Microsoft Internet Explorer';
|
|
842
|
+
}
|
|
837
843
|
// "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"
|
|
838
|
-
if (sUsrAg.indexOf('Edge') > -1)
|
|
844
|
+
if (sUsrAg.indexOf('Edge') > -1) {
|
|
845
|
+
return 'Microsoft Edge';
|
|
846
|
+
}
|
|
839
847
|
// "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"
|
|
840
|
-
if (sUsrAg.indexOf('Chrome') > -1)
|
|
848
|
+
if (sUsrAg.indexOf('Chrome') > -1) {
|
|
849
|
+
return 'Google Chrome or Chromium';
|
|
850
|
+
}
|
|
841
851
|
// "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"
|
|
842
|
-
if (sUsrAg.indexOf('Safari') > -1)
|
|
852
|
+
if (sUsrAg.indexOf('Safari') > -1) {
|
|
853
|
+
return 'Apple Safari';
|
|
854
|
+
}
|
|
843
855
|
return 'unknown';
|
|
844
856
|
}
|
|
845
857
|
}, {
|
|
@@ -870,11 +882,13 @@ var Browser = /*#__PURE__*/function () {
|
|
|
870
882
|
}, {
|
|
871
883
|
key: "getBrowserInfo",
|
|
872
884
|
value: function getBrowserInfo() {
|
|
873
|
-
|
|
885
|
+
// Bound the user-agent length before running any regex to avoid
|
|
886
|
+
// pathological backtracking (ReDoS) on maliciously long inputs.
|
|
887
|
+
var ua = (navigator.userAgent || '').slice(0, 256);
|
|
874
888
|
var M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
875
|
-
var tem;
|
|
876
|
-
if (/trident/i.test(M[1])) {
|
|
877
|
-
tem = /\brv[ :](\d+)
|
|
889
|
+
var tem = null;
|
|
890
|
+
if (/trident/i.test(M[1] || '')) {
|
|
891
|
+
tem = ua.match(/\brv[ :](\d+)/) || [];
|
|
878
892
|
return {
|
|
879
893
|
name: 'IE',
|
|
880
894
|
version: tem[1] || ''
|
|
@@ -890,8 +904,8 @@ var Browser = /*#__PURE__*/function () {
|
|
|
890
904
|
}
|
|
891
905
|
}
|
|
892
906
|
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
|
893
|
-
|
|
894
|
-
if (
|
|
907
|
+
tem = ua.match(/version\/(\d+)/i);
|
|
908
|
+
if (tem != null) {
|
|
895
909
|
M.splice(1, 1, tem[1]);
|
|
896
910
|
}
|
|
897
911
|
return {
|
|
@@ -1851,7 +1865,7 @@ SDK.headerKeys = Object.freeze({
|
|
|
1851
1865
|
version: 'x-sdk-version',
|
|
1852
1866
|
type: 'x-sdk-type'
|
|
1853
1867
|
});
|
|
1854
|
-
SDK._version = 'v1.
|
|
1868
|
+
SDK._version = 'v1.145.0-beta';
|
|
1855
1869
|
|
|
1856
1870
|
var ACCESS_HEADER_NAME = {
|
|
1857
1871
|
accessToken: 'x-access-token',
|
|
@@ -5650,12 +5664,12 @@ var Uuid = /*#__PURE__*/function () {
|
|
|
5650
5664
|
return _createClass(Uuid, null, [{
|
|
5651
5665
|
key: "generate",
|
|
5652
5666
|
value: function generate() {
|
|
5653
|
-
if (typeof window !==
|
|
5667
|
+
if (typeof window !== 'undefined' && typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues !== 'undefined') {
|
|
5654
5668
|
var buf = new Uint16Array(8);
|
|
5655
5669
|
window.crypto.getRandomValues(buf);
|
|
5656
|
-
return
|
|
5670
|
+
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]);
|
|
5657
5671
|
} else {
|
|
5658
|
-
return
|
|
5672
|
+
return Uuid.random() + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + Uuid.random() + Uuid.random();
|
|
5659
5673
|
}
|
|
5660
5674
|
}
|
|
5661
5675
|
}, {
|
|
@@ -5663,14 +5677,22 @@ var Uuid = /*#__PURE__*/function () {
|
|
|
5663
5677
|
value: function hash(number) {
|
|
5664
5678
|
var hash = number.toString(16);
|
|
5665
5679
|
while (hash.length < 4) {
|
|
5666
|
-
hash =
|
|
5680
|
+
hash = '0' + hash;
|
|
5667
5681
|
}
|
|
5668
5682
|
return hash;
|
|
5669
5683
|
}
|
|
5670
5684
|
}, {
|
|
5671
5685
|
key: "random",
|
|
5672
5686
|
value: function random() {
|
|
5673
|
-
|
|
5687
|
+
var value;
|
|
5688
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
5689
|
+
var buf = new Uint16Array(1);
|
|
5690
|
+
crypto.getRandomValues(buf);
|
|
5691
|
+
value = buf[0] / 0x10000;
|
|
5692
|
+
} else {
|
|
5693
|
+
value = Math.random();
|
|
5694
|
+
}
|
|
5695
|
+
return Math.floor((1 + value) * 0x10000).toString(16).substring(1);
|
|
5674
5696
|
}
|
|
5675
5697
|
}]);
|
|
5676
5698
|
}();
|
|
@@ -8345,7 +8367,7 @@ var AfterPayWalletService = /*#__PURE__*/function (_WalletService) {
|
|
|
8345
8367
|
}]);
|
|
8346
8368
|
}(WalletService);
|
|
8347
8369
|
|
|
8348
|
-
/*! @license DOMPurify 3.4.
|
|
8370
|
+
/*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */
|
|
8349
8371
|
|
|
8350
8372
|
var purify_cjs;
|
|
8351
8373
|
var hasRequiredPurify_cjs;
|
|
@@ -8354,22 +8376,63 @@ function requirePurify_cjs () {
|
|
|
8354
8376
|
if (hasRequiredPurify_cjs) return purify_cjs;
|
|
8355
8377
|
hasRequiredPurify_cjs = 1;
|
|
8356
8378
|
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8379
|
+
function _arrayLikeToArray(r, a) {
|
|
8380
|
+
(null == a || a > r.length) && (a = r.length);
|
|
8381
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8382
|
+
return n;
|
|
8383
|
+
}
|
|
8384
|
+
function _arrayWithHoles(r) {
|
|
8385
|
+
if (Array.isArray(r)) return r;
|
|
8386
|
+
}
|
|
8387
|
+
function _iterableToArrayLimit(r, l) {
|
|
8388
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
8389
|
+
if (null != t) {
|
|
8390
|
+
var e,
|
|
8391
|
+
n,
|
|
8392
|
+
i,
|
|
8393
|
+
u,
|
|
8394
|
+
a = [],
|
|
8395
|
+
f = true,
|
|
8396
|
+
o = false;
|
|
8397
|
+
try {
|
|
8398
|
+
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);
|
|
8399
|
+
} catch (r) {
|
|
8400
|
+
o = true, n = r;
|
|
8401
|
+
} finally {
|
|
8402
|
+
try {
|
|
8403
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
8404
|
+
} finally {
|
|
8405
|
+
if (o) throw n;
|
|
8406
|
+
}
|
|
8407
|
+
}
|
|
8408
|
+
return a;
|
|
8409
|
+
}
|
|
8410
|
+
}
|
|
8411
|
+
function _nonIterableRest() {
|
|
8412
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
8413
|
+
}
|
|
8414
|
+
function _slicedToArray(r, e) {
|
|
8415
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
8416
|
+
}
|
|
8417
|
+
function _unsupportedIterableToArray(r, a) {
|
|
8418
|
+
if (r) {
|
|
8419
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
8420
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
8421
|
+
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;
|
|
8422
|
+
}
|
|
8423
|
+
}
|
|
8424
|
+
|
|
8425
|
+
const entries = Object.entries,
|
|
8426
|
+
setPrototypeOf = Object.setPrototypeOf,
|
|
8427
|
+
isFrozen = Object.isFrozen,
|
|
8428
|
+
getPrototypeOf = Object.getPrototypeOf,
|
|
8429
|
+
getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
8430
|
+
let freeze = Object.freeze,
|
|
8431
|
+
seal = Object.seal,
|
|
8432
|
+
create = Object.create; // eslint-disable-line import/no-mutable-exports
|
|
8433
|
+
let _ref = typeof Reflect !== 'undefined' && Reflect,
|
|
8434
|
+
apply = _ref.apply,
|
|
8435
|
+
construct = _ref.construct;
|
|
8373
8436
|
if (!freeze) {
|
|
8374
8437
|
freeze = function freeze(x) {
|
|
8375
8438
|
return x;
|
|
@@ -8401,13 +8464,19 @@ function requirePurify_cjs () {
|
|
|
8401
8464
|
const arrayPop = unapply(Array.prototype.pop);
|
|
8402
8465
|
const arrayPush = unapply(Array.prototype.push);
|
|
8403
8466
|
const arraySplice = unapply(Array.prototype.splice);
|
|
8467
|
+
const arrayIsArray = Array.isArray;
|
|
8404
8468
|
const stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
8405
8469
|
const stringToString = unapply(String.prototype.toString);
|
|
8406
8470
|
const stringMatch = unapply(String.prototype.match);
|
|
8407
8471
|
const stringReplace = unapply(String.prototype.replace);
|
|
8408
8472
|
const stringIndexOf = unapply(String.prototype.indexOf);
|
|
8409
8473
|
const stringTrim = unapply(String.prototype.trim);
|
|
8474
|
+
const numberToString = unapply(Number.prototype.toString);
|
|
8475
|
+
const booleanToString = unapply(Boolean.prototype.toString);
|
|
8476
|
+
const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
|
|
8477
|
+
const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
|
|
8410
8478
|
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
8479
|
+
const objectToString = unapply(Object.prototype.toString);
|
|
8411
8480
|
const regExpTest = unapply(RegExp.prototype.test);
|
|
8412
8481
|
const typeErrorCreate = unconstruct(TypeError);
|
|
8413
8482
|
/**
|
|
@@ -8457,6 +8526,9 @@ function requirePurify_cjs () {
|
|
|
8457
8526
|
// Prevent prototype setters from intercepting set as a this value.
|
|
8458
8527
|
setPrototypeOf(set, null);
|
|
8459
8528
|
}
|
|
8529
|
+
if (!arrayIsArray(array)) {
|
|
8530
|
+
return set;
|
|
8531
|
+
}
|
|
8460
8532
|
let l = array.length;
|
|
8461
8533
|
while (l--) {
|
|
8462
8534
|
let element = array[l];
|
|
@@ -8497,10 +8569,13 @@ function requirePurify_cjs () {
|
|
|
8497
8569
|
*/
|
|
8498
8570
|
function clone(object) {
|
|
8499
8571
|
const newObject = create(null);
|
|
8500
|
-
for (const
|
|
8572
|
+
for (const _ref2 of entries(object)) {
|
|
8573
|
+
var _ref3 = _slicedToArray(_ref2, 2);
|
|
8574
|
+
const property = _ref3[0];
|
|
8575
|
+
const value = _ref3[1];
|
|
8501
8576
|
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
8502
8577
|
if (isPropertyExist) {
|
|
8503
|
-
if (
|
|
8578
|
+
if (arrayIsArray(value)) {
|
|
8504
8579
|
newObject[property] = cleanArray(value);
|
|
8505
8580
|
} else if (value && typeof value === 'object' && value.constructor === Object) {
|
|
8506
8581
|
newObject[property] = clone(value);
|
|
@@ -8511,6 +8586,58 @@ function requirePurify_cjs () {
|
|
|
8511
8586
|
}
|
|
8512
8587
|
return newObject;
|
|
8513
8588
|
}
|
|
8589
|
+
/**
|
|
8590
|
+
* Convert non-node values into strings without depending on direct property access.
|
|
8591
|
+
*
|
|
8592
|
+
* @param value - The value to stringify.
|
|
8593
|
+
* @returns A string representation of the provided value.
|
|
8594
|
+
*/
|
|
8595
|
+
function stringifyValue(value) {
|
|
8596
|
+
switch (typeof value) {
|
|
8597
|
+
case 'string':
|
|
8598
|
+
{
|
|
8599
|
+
return value;
|
|
8600
|
+
}
|
|
8601
|
+
case 'number':
|
|
8602
|
+
{
|
|
8603
|
+
return numberToString(value);
|
|
8604
|
+
}
|
|
8605
|
+
case 'boolean':
|
|
8606
|
+
{
|
|
8607
|
+
return booleanToString(value);
|
|
8608
|
+
}
|
|
8609
|
+
case 'bigint':
|
|
8610
|
+
{
|
|
8611
|
+
return bigintToString ? bigintToString(value) : '0';
|
|
8612
|
+
}
|
|
8613
|
+
case 'symbol':
|
|
8614
|
+
{
|
|
8615
|
+
return symbolToString ? symbolToString(value) : 'Symbol()';
|
|
8616
|
+
}
|
|
8617
|
+
case 'undefined':
|
|
8618
|
+
{
|
|
8619
|
+
return objectToString(value);
|
|
8620
|
+
}
|
|
8621
|
+
case 'function':
|
|
8622
|
+
case 'object':
|
|
8623
|
+
{
|
|
8624
|
+
if (value === null) {
|
|
8625
|
+
return objectToString(value);
|
|
8626
|
+
}
|
|
8627
|
+
const valueAsRecord = value;
|
|
8628
|
+
const valueToString = lookupGetter(valueAsRecord, 'toString');
|
|
8629
|
+
if (typeof valueToString === 'function') {
|
|
8630
|
+
const stringified = valueToString(valueAsRecord);
|
|
8631
|
+
return typeof stringified === 'string' ? stringified : objectToString(stringified);
|
|
8632
|
+
}
|
|
8633
|
+
return objectToString(value);
|
|
8634
|
+
}
|
|
8635
|
+
default:
|
|
8636
|
+
{
|
|
8637
|
+
return objectToString(value);
|
|
8638
|
+
}
|
|
8639
|
+
}
|
|
8640
|
+
}
|
|
8514
8641
|
/**
|
|
8515
8642
|
* This method automatically checks if the prop is function or getter and behaves accordingly.
|
|
8516
8643
|
*
|
|
@@ -8536,6 +8663,14 @@ function requirePurify_cjs () {
|
|
|
8536
8663
|
}
|
|
8537
8664
|
return fallbackValue;
|
|
8538
8665
|
}
|
|
8666
|
+
function isRegex(value) {
|
|
8667
|
+
try {
|
|
8668
|
+
regExpTest(value, '');
|
|
8669
|
+
return true;
|
|
8670
|
+
} catch (_unused) {
|
|
8671
|
+
return false;
|
|
8672
|
+
}
|
|
8673
|
+
}
|
|
8539
8674
|
|
|
8540
8675
|
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']);
|
|
8541
8676
|
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']);
|
|
@@ -8551,15 +8686,14 @@ function requirePurify_cjs () {
|
|
|
8551
8686
|
const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
|
|
8552
8687
|
const text = freeze(['#text']);
|
|
8553
8688
|
|
|
8554
|
-
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'
|
|
8689
|
+
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']);
|
|
8555
8690
|
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']);
|
|
8556
8691
|
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']);
|
|
8557
8692
|
const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
|
|
8558
8693
|
|
|
8559
|
-
|
|
8560
|
-
const
|
|
8561
|
-
const
|
|
8562
|
-
const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
|
|
8694
|
+
const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
|
|
8695
|
+
const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
|
|
8696
|
+
const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
|
|
8563
8697
|
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
|
|
8564
8698
|
const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
|
|
8565
8699
|
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
|
|
@@ -8569,30 +8703,31 @@ function requirePurify_cjs () {
|
|
|
8569
8703
|
);
|
|
8570
8704
|
const DOCTYPE_NAME = seal(/^html$/i);
|
|
8571
8705
|
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
8706
|
+
// Markup-significant character probes used by _sanitizeElements.
|
|
8707
|
+
// Shared module-level instances are safe despite the sticky /g flags:
|
|
8708
|
+
// unapply() resets lastIndex for RegExp receivers before every call.
|
|
8709
|
+
const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
|
|
8710
|
+
const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
8711
|
+
const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
8712
|
+
const SELF_CLOSING_TAG = seal(/\/>/i);
|
|
8572
8713
|
|
|
8573
|
-
var EXPRESSIONS = /*#__PURE__*/Object.freeze({
|
|
8574
|
-
__proto__: null,
|
|
8575
|
-
ARIA_ATTR: ARIA_ATTR,
|
|
8576
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE,
|
|
8577
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT,
|
|
8578
|
-
DATA_ATTR: DATA_ATTR,
|
|
8579
|
-
DOCTYPE_NAME: DOCTYPE_NAME,
|
|
8580
|
-
ERB_EXPR: ERB_EXPR,
|
|
8581
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI,
|
|
8582
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
|
|
8583
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR,
|
|
8584
|
-
TMPLIT_EXPR: TMPLIT_EXPR
|
|
8585
|
-
});
|
|
8586
|
-
|
|
8587
|
-
/* eslint-disable @typescript-eslint/indent */
|
|
8588
8714
|
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
|
|
8589
8715
|
const NODE_TYPE = {
|
|
8590
8716
|
element: 1,
|
|
8717
|
+
attribute: 2,
|
|
8591
8718
|
text: 3,
|
|
8719
|
+
cdataSection: 4,
|
|
8720
|
+
entityReference: 5,
|
|
8592
8721
|
// Deprecated
|
|
8593
|
-
|
|
8722
|
+
entityNode: 6,
|
|
8723
|
+
// Deprecated
|
|
8724
|
+
processingInstruction: 7,
|
|
8594
8725
|
comment: 8,
|
|
8595
|
-
document: 9
|
|
8726
|
+
document: 9,
|
|
8727
|
+
documentType: 10,
|
|
8728
|
+
documentFragment: 11,
|
|
8729
|
+
notation: 12 // Deprecated
|
|
8730
|
+
};
|
|
8596
8731
|
const getGlobal = function getGlobal() {
|
|
8597
8732
|
return typeof window === 'undefined' ? null : window;
|
|
8598
8733
|
};
|
|
@@ -8647,10 +8782,25 @@ function requirePurify_cjs () {
|
|
|
8647
8782
|
uponSanitizeShadowNode: []
|
|
8648
8783
|
};
|
|
8649
8784
|
};
|
|
8785
|
+
/**
|
|
8786
|
+
* Resolve a set-valued configuration option: a fresh set built from
|
|
8787
|
+
* cfg[key] when it is an own array property (seeded with a clone of
|
|
8788
|
+
* options.base when given, case-normalized via options.transform),
|
|
8789
|
+
* the fallback set otherwise.
|
|
8790
|
+
*
|
|
8791
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
8792
|
+
* @param key the configuration property to read
|
|
8793
|
+
* @param fallback the set to use when the option is absent or not an array
|
|
8794
|
+
* @param options transform and optional base set to merge into
|
|
8795
|
+
* @returns the resolved set
|
|
8796
|
+
*/
|
|
8797
|
+
const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
8798
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
8799
|
+
};
|
|
8650
8800
|
function createDOMPurify() {
|
|
8651
8801
|
let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
|
8652
8802
|
const DOMPurify = root => createDOMPurify(root);
|
|
8653
|
-
DOMPurify.version = '3.4.
|
|
8803
|
+
DOMPurify.version = '3.4.11';
|
|
8654
8804
|
DOMPurify.removed = [];
|
|
8655
8805
|
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
8656
8806
|
// Not running in a browser, provide a factory function
|
|
@@ -8658,28 +8808,29 @@ function requirePurify_cjs () {
|
|
|
8658
8808
|
DOMPurify.isSupported = false;
|
|
8659
8809
|
return DOMPurify;
|
|
8660
8810
|
}
|
|
8661
|
-
let
|
|
8662
|
-
document
|
|
8663
|
-
} = window;
|
|
8811
|
+
let document = window.document;
|
|
8664
8812
|
const originalDocument = document;
|
|
8665
8813
|
const currentScript = originalDocument.currentScript;
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
NamedNodeMap
|
|
8673
|
-
HTMLFormElement
|
|
8674
|
-
DOMParser,
|
|
8675
|
-
trustedTypes
|
|
8676
|
-
} = window;
|
|
8814
|
+
window.DocumentFragment;
|
|
8815
|
+
const HTMLTemplateElement = window.HTMLTemplateElement,
|
|
8816
|
+
Node = window.Node,
|
|
8817
|
+
Element = window.Element,
|
|
8818
|
+
NodeFilter = window.NodeFilter,
|
|
8819
|
+
_window$NamedNodeMap = window.NamedNodeMap;
|
|
8820
|
+
_window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
|
|
8821
|
+
window.HTMLFormElement;
|
|
8822
|
+
const DOMParser = window.DOMParser,
|
|
8823
|
+
trustedTypes = window.trustedTypes;
|
|
8677
8824
|
const ElementPrototype = Element.prototype;
|
|
8678
8825
|
const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
|
|
8679
8826
|
const remove = lookupGetter(ElementPrototype, 'remove');
|
|
8680
8827
|
const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
|
|
8681
8828
|
const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
|
|
8682
8829
|
const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
|
|
8830
|
+
const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
|
|
8831
|
+
const getAttributes = lookupGetter(ElementPrototype, 'attributes');
|
|
8832
|
+
const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
|
|
8833
|
+
const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
|
|
8683
8834
|
// As per issue #47, the web-components registry is inherited by a
|
|
8684
8835
|
// new document created via createHTMLDocument. As per the spec
|
|
8685
8836
|
// (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
|
|
@@ -8694,33 +8845,74 @@ function requirePurify_cjs () {
|
|
|
8694
8845
|
}
|
|
8695
8846
|
let trustedTypesPolicy;
|
|
8696
8847
|
let emptyHTML = '';
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8848
|
+
// The instance's own internal Trusted Types policy. Unlike a caller-supplied
|
|
8849
|
+
// `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
|
|
8850
|
+
// on duplicate policy names — and is the only policy allowed to persist
|
|
8851
|
+
// across configurations and survive `clearConfig()`.
|
|
8852
|
+
let defaultTrustedTypesPolicy;
|
|
8853
|
+
let defaultTrustedTypesPolicyResolved = false;
|
|
8854
|
+
// Tracks whether we are already inside a call to the configured Trusted Types
|
|
8855
|
+
// policy (`createHTML` or `createScriptURL`). If a supplied policy callback
|
|
8856
|
+
// itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
|
|
8857
|
+
// re-enter the policy and recurse until the stack overflows. We detect that
|
|
8858
|
+
// re-entry and throw a clear, actionable error instead. The guard is shared
|
|
8859
|
+
// across both callbacks, because either one re-entering `sanitize` triggers
|
|
8860
|
+
// the same unbounded recursion.
|
|
8861
|
+
let IN_TRUSTED_TYPES_POLICY = 0;
|
|
8862
|
+
const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
|
|
8863
|
+
if (IN_TRUSTED_TYPES_POLICY > 0) {
|
|
8864
|
+
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.');
|
|
8865
|
+
}
|
|
8866
|
+
};
|
|
8867
|
+
const _createTrustedHTML = function _createTrustedHTML(html) {
|
|
8868
|
+
_assertNotInTrustedTypesPolicy();
|
|
8869
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
8870
|
+
try {
|
|
8871
|
+
return trustedTypesPolicy.createHTML(html);
|
|
8872
|
+
} finally {
|
|
8873
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
8874
|
+
}
|
|
8875
|
+
};
|
|
8876
|
+
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
8877
|
+
_assertNotInTrustedTypesPolicy();
|
|
8878
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
8879
|
+
try {
|
|
8880
|
+
return trustedTypesPolicy.createScriptURL(scriptUrl);
|
|
8881
|
+
} finally {
|
|
8882
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
8883
|
+
}
|
|
8884
|
+
};
|
|
8885
|
+
// Lazily resolve (and cache) the instance's internal default policy.
|
|
8886
|
+
// Resolution is attempted at most once: a successful `createPolicy` cannot be
|
|
8887
|
+
// repeated (Trusted Types throws on duplicate names), and a failed or
|
|
8888
|
+
// unsupported attempt must not be retried on every parse.
|
|
8889
|
+
const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
|
|
8890
|
+
if (!defaultTrustedTypesPolicyResolved) {
|
|
8891
|
+
defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
8892
|
+
defaultTrustedTypesPolicyResolved = true;
|
|
8893
|
+
}
|
|
8894
|
+
return defaultTrustedTypesPolicy;
|
|
8895
|
+
};
|
|
8896
|
+
const _document = document,
|
|
8897
|
+
implementation = _document.implementation,
|
|
8898
|
+
createNodeIterator = _document.createNodeIterator,
|
|
8899
|
+
createDocumentFragment = _document.createDocumentFragment,
|
|
8900
|
+
getElementsByTagName = _document.getElementsByTagName;
|
|
8901
|
+
const importNode = originalDocument.importNode;
|
|
8706
8902
|
let hooks = _createHooksMap();
|
|
8707
8903
|
/**
|
|
8708
8904
|
* Expose whether this browser supports running the full DOMPurify.
|
|
8709
8905
|
*/
|
|
8710
8906
|
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
|
|
8711
|
-
const
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
} = EXPRESSIONS;
|
|
8721
|
-
let {
|
|
8722
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
8723
|
-
} = EXPRESSIONS;
|
|
8907
|
+
const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
|
|
8908
|
+
ERB_EXPR$1 = ERB_EXPR,
|
|
8909
|
+
TMPLIT_EXPR$1 = TMPLIT_EXPR,
|
|
8910
|
+
DATA_ATTR$1 = DATA_ATTR,
|
|
8911
|
+
ARIA_ATTR$1 = ARIA_ATTR,
|
|
8912
|
+
IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
|
|
8913
|
+
ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
|
|
8914
|
+
CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
|
|
8915
|
+
let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
|
|
8724
8916
|
/**
|
|
8725
8917
|
* We consider the elements and attributes below to be safe. Ideally
|
|
8726
8918
|
* don't add any new ones but feel free to remove unwanted ones.
|
|
@@ -8797,6 +8989,13 @@ function requirePurify_cjs () {
|
|
|
8797
8989
|
let WHOLE_DOCUMENT = false;
|
|
8798
8990
|
/* Track whether config is already set on this instance of DOMPurify. */
|
|
8799
8991
|
let SET_CONFIG = false;
|
|
8992
|
+
/* Pristine allowlist bindings captured at setConfig() time. On the
|
|
8993
|
+
* persistent-config path sanitize() restores the sets from these before
|
|
8994
|
+
* the per-walk hook clone-guard, so a hook's in-call widening cannot
|
|
8995
|
+
* carry across calls. Null until setConfig() is called; reset by
|
|
8996
|
+
* clearConfig(). */
|
|
8997
|
+
let SET_CONFIG_ALLOWED_TAGS = null;
|
|
8998
|
+
let SET_CONFIG_ALLOWED_ATTR = null;
|
|
8800
8999
|
/* Decide if all elements (e.g. style, script) must be children of
|
|
8801
9000
|
* document.body. By default, browsers might move them to document.head */
|
|
8802
9001
|
let FORCE_BODY = false;
|
|
@@ -8839,7 +9038,17 @@ function requirePurify_cjs () {
|
|
|
8839
9038
|
let USE_PROFILES = {};
|
|
8840
9039
|
/* Tags to ignore content of when KEEP_CONTENT is true */
|
|
8841
9040
|
let FORBID_CONTENTS = null;
|
|
8842
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
9041
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
9042
|
+
// <selectedcontent> mirrors the selected <option>'s subtree, cloned by
|
|
9043
|
+
// the UA (customizable <select>) — including any on* handlers — and the
|
|
9044
|
+
// engine re-mirrors synchronously whenever a removal changes which
|
|
9045
|
+
// option/selectedcontent is current, even inside DOMPurify's inert
|
|
9046
|
+
// DOMParser document. Hoisting its children on removal re-inserts a fresh
|
|
9047
|
+
// mirror target ahead of the walk, which the engine refills, looping
|
|
9048
|
+
// forever (DoS) and amplifying output. Dropping its content on removal
|
|
9049
|
+
// (rather than hoisting) breaks that cascade; the content is a duplicate
|
|
9050
|
+
// of the option, which is sanitized on its own. See campaign-3 F1/F6.
|
|
9051
|
+
'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
|
|
8843
9052
|
/* Tags that are safe for data: URIs */
|
|
8844
9053
|
let DATA_URI_TAGS = null;
|
|
8845
9054
|
const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
|
|
@@ -8855,8 +9064,10 @@ function requirePurify_cjs () {
|
|
|
8855
9064
|
/* Allowed XHTML+XML namespaces */
|
|
8856
9065
|
let ALLOWED_NAMESPACES = null;
|
|
8857
9066
|
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
8858
|
-
|
|
8859
|
-
let
|
|
9067
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
|
|
9068
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
9069
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
|
|
9070
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
|
|
8860
9071
|
// Certain elements are allowed in both SVG and HTML
|
|
8861
9072
|
// namespace. We need to specify them explicitly
|
|
8862
9073
|
// so that they don't get erroneously deleted from
|
|
@@ -8898,15 +9109,33 @@ function requirePurify_cjs () {
|
|
|
8898
9109
|
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
|
|
8899
9110
|
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
|
|
8900
9111
|
/* Set configuration parameters */
|
|
8901
|
-
ALLOWED_TAGS =
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
9112
|
+
ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
|
|
9113
|
+
transform: transformCaseFunc
|
|
9114
|
+
});
|
|
9115
|
+
ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
|
|
9116
|
+
transform: transformCaseFunc
|
|
9117
|
+
});
|
|
9118
|
+
ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
|
|
9119
|
+
transform: stringToString
|
|
9120
|
+
});
|
|
9121
|
+
URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
|
|
9122
|
+
transform: transformCaseFunc,
|
|
9123
|
+
base: DEFAULT_URI_SAFE_ATTRIBUTES
|
|
9124
|
+
});
|
|
9125
|
+
DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
|
|
9126
|
+
transform: transformCaseFunc,
|
|
9127
|
+
base: DEFAULT_DATA_URI_TAGS
|
|
9128
|
+
});
|
|
9129
|
+
FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
|
|
9130
|
+
transform: transformCaseFunc
|
|
9131
|
+
});
|
|
9132
|
+
FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
|
|
9133
|
+
transform: transformCaseFunc
|
|
9134
|
+
});
|
|
9135
|
+
FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
|
|
9136
|
+
transform: transformCaseFunc
|
|
9137
|
+
});
|
|
9138
|
+
USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
8910
9139
|
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
|
|
8911
9140
|
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
|
|
8912
9141
|
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
@@ -8922,20 +9151,22 @@ function requirePurify_cjs () {
|
|
|
8922
9151
|
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
|
|
8923
9152
|
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
|
|
8924
9153
|
IN_PLACE = cfg.IN_PLACE || false; // Default false
|
|
8925
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP
|
|
8926
|
-
NAMESPACE = cfg.NAMESPACE
|
|
8927
|
-
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS
|
|
8928
|
-
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
9154
|
+
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
|
|
9155
|
+
NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
|
|
9156
|
+
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
|
|
9157
|
+
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
|
|
9158
|
+
const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
|
|
9159
|
+
CUSTOM_ELEMENT_HANDLING = create(null);
|
|
9160
|
+
if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
|
|
9161
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
|
|
8932
9162
|
}
|
|
8933
|
-
if (
|
|
8934
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck =
|
|
9163
|
+
if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
|
|
9164
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
|
|
8935
9165
|
}
|
|
8936
|
-
if (
|
|
8937
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements =
|
|
9166
|
+
if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
|
|
9167
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
|
|
8938
9168
|
}
|
|
9169
|
+
seal(CUSTOM_ELEMENT_HANDLING);
|
|
8939
9170
|
if (SAFE_FOR_TEMPLATES) {
|
|
8940
9171
|
ALLOW_DATA_ATTR = false;
|
|
8941
9172
|
}
|
|
@@ -8971,36 +9202,36 @@ function requirePurify_cjs () {
|
|
|
8971
9202
|
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
8972
9203
|
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
8973
9204
|
/* Merge configuration parameters */
|
|
8974
|
-
if (cfg
|
|
9205
|
+
if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
|
|
8975
9206
|
if (typeof cfg.ADD_TAGS === 'function') {
|
|
8976
9207
|
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
8977
|
-
} else {
|
|
9208
|
+
} else if (arrayIsArray(cfg.ADD_TAGS)) {
|
|
8978
9209
|
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
8979
9210
|
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
8980
9211
|
}
|
|
8981
9212
|
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
8982
9213
|
}
|
|
8983
9214
|
}
|
|
8984
|
-
if (cfg
|
|
9215
|
+
if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
|
|
8985
9216
|
if (typeof cfg.ADD_ATTR === 'function') {
|
|
8986
9217
|
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
8987
|
-
} else {
|
|
9218
|
+
} else if (arrayIsArray(cfg.ADD_ATTR)) {
|
|
8988
9219
|
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
8989
9220
|
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
8990
9221
|
}
|
|
8991
9222
|
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
8992
9223
|
}
|
|
8993
9224
|
}
|
|
8994
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
9225
|
+
if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
|
|
8995
9226
|
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
8996
9227
|
}
|
|
8997
|
-
if (cfg.FORBID_CONTENTS) {
|
|
9228
|
+
if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
|
|
8998
9229
|
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
8999
9230
|
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
9000
9231
|
}
|
|
9001
9232
|
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
9002
9233
|
}
|
|
9003
|
-
if (cfg.ADD_FORBID_CONTENTS) {
|
|
9234
|
+
if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
|
|
9004
9235
|
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
9005
9236
|
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
9006
9237
|
}
|
|
@@ -9019,6 +9250,13 @@ function requirePurify_cjs () {
|
|
|
9019
9250
|
addToSet(ALLOWED_TAGS, ['tbody']);
|
|
9020
9251
|
delete FORBID_TAGS.tbody;
|
|
9021
9252
|
}
|
|
9253
|
+
// Re-derive the active Trusted Types policy from this configuration on
|
|
9254
|
+
// every parse. The active policy must never be sticky closure state that
|
|
9255
|
+
// outlives the config that set it: a caller-supplied policy left in place
|
|
9256
|
+
// after `clearConfig()` — or after a later call that supplied none, or
|
|
9257
|
+
// `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
|
|
9258
|
+
// `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
|
|
9259
|
+
// See GHSA-vxr8-fq34-vvx9.
|
|
9022
9260
|
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
9023
9261
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
|
|
9024
9262
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
@@ -9026,18 +9264,45 @@ function requirePurify_cjs () {
|
|
|
9026
9264
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
|
|
9027
9265
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
9028
9266
|
}
|
|
9029
|
-
//
|
|
9267
|
+
// A caller-supplied policy applies to this configuration only.
|
|
9268
|
+
const previousTrustedTypesPolicy = trustedTypesPolicy;
|
|
9030
9269
|
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
9031
|
-
// Sign local variables required by `sanitize`.
|
|
9032
|
-
|
|
9270
|
+
// Sign local variables required by `sanitize`. If the supplied policy's
|
|
9271
|
+
// `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
|
|
9272
|
+
// throws via the re-entrancy guard. Restore the previous policy first so
|
|
9273
|
+
// the instance is not left in a poisoned state. See #1422.
|
|
9274
|
+
try {
|
|
9275
|
+
emptyHTML = _createTrustedHTML('');
|
|
9276
|
+
} catch (error) {
|
|
9277
|
+
trustedTypesPolicy = previousTrustedTypesPolicy;
|
|
9278
|
+
throw error;
|
|
9279
|
+
}
|
|
9280
|
+
} else if (cfg.TRUSTED_TYPES_POLICY === null) {
|
|
9281
|
+
// Explicit opt-out for this call: perform no Trusted Types signing and
|
|
9282
|
+
// create nothing (so a strict `trusted-types` CSP that disallows a
|
|
9283
|
+
// `dompurify` policy can still call `sanitize` from inside its own
|
|
9284
|
+
// policy — see #1422). Resetting to `undefined` rather than a sticky
|
|
9285
|
+
// `null` also drops any previously retained caller policy, so it cannot
|
|
9286
|
+
// resurface on a later call, while still allowing the next config-less
|
|
9287
|
+
// call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
|
|
9288
|
+
trustedTypesPolicy = undefined;
|
|
9289
|
+
emptyHTML = '';
|
|
9033
9290
|
} else {
|
|
9034
|
-
//
|
|
9291
|
+
// No policy supplied: keep the currently active policy if one is set — a
|
|
9292
|
+
// previously supplied policy is intentionally sticky across config-less
|
|
9293
|
+
// calls — otherwise fall back to the instance's own internal policy,
|
|
9294
|
+
// created at most once. (A policy supplied for a *single* call still
|
|
9295
|
+
// lingers by design; what must not linger is a policy whose configuration
|
|
9296
|
+
// has been torn down via `clearConfig()`, which restores the default.)
|
|
9035
9297
|
if (trustedTypesPolicy === undefined) {
|
|
9036
|
-
trustedTypesPolicy =
|
|
9298
|
+
trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
9037
9299
|
}
|
|
9038
|
-
//
|
|
9039
|
-
|
|
9040
|
-
|
|
9300
|
+
// Sign internal variables only when a policy is active. A falsy policy
|
|
9301
|
+
// (Trusted Types unsupported, creation failed, or an explicit opt-out)
|
|
9302
|
+
// leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
|
|
9303
|
+
// a non-policy and throw. See #1422.
|
|
9304
|
+
if (trustedTypesPolicy && typeof emptyHTML === 'string') {
|
|
9305
|
+
emptyHTML = _createTrustedHTML('');
|
|
9041
9306
|
}
|
|
9042
9307
|
}
|
|
9043
9308
|
// Prevent further manipulation of configuration.
|
|
@@ -9052,6 +9317,77 @@ function requirePurify_cjs () {
|
|
|
9052
9317
|
* correctly. */
|
|
9053
9318
|
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
9054
9319
|
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
9320
|
+
/**
|
|
9321
|
+
* Namespace rules for an element in the SVG namespace.
|
|
9322
|
+
*
|
|
9323
|
+
* @param tagName the element's lowercase tag name
|
|
9324
|
+
* @param parent the (possibly simulated) parent node
|
|
9325
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9326
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9327
|
+
*/
|
|
9328
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
|
|
9329
|
+
// The only way to switch from HTML namespace to SVG
|
|
9330
|
+
// is via <svg>. If it happens via any other tag, then
|
|
9331
|
+
// it should be killed.
|
|
9332
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9333
|
+
return tagName === 'svg';
|
|
9334
|
+
}
|
|
9335
|
+
// The only way to switch from MathML to SVG is via <svg>
|
|
9336
|
+
// if the parent is either <annotation-xml> or a MathML
|
|
9337
|
+
// text integration point.
|
|
9338
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
9339
|
+
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
9340
|
+
}
|
|
9341
|
+
// We only allow elements that are defined in SVG
|
|
9342
|
+
// spec. All others are disallowed in SVG namespace.
|
|
9343
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
9344
|
+
};
|
|
9345
|
+
/**
|
|
9346
|
+
* Namespace rules for an element in the MathML namespace.
|
|
9347
|
+
*
|
|
9348
|
+
* @param tagName the element's lowercase tag name
|
|
9349
|
+
* @param parent the (possibly simulated) parent node
|
|
9350
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9351
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9352
|
+
*/
|
|
9353
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
|
|
9354
|
+
// The only way to switch from HTML namespace to MathML
|
|
9355
|
+
// is via <math>. If it happens via any other tag, then
|
|
9356
|
+
// it should be killed.
|
|
9357
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9358
|
+
return tagName === 'math';
|
|
9359
|
+
}
|
|
9360
|
+
// The only way to switch from SVG to MathML is via
|
|
9361
|
+
// <math> and HTML integration points
|
|
9362
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
9363
|
+
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
9364
|
+
}
|
|
9365
|
+
// We only allow elements that are defined in MathML
|
|
9366
|
+
// spec. All others are disallowed in MathML namespace.
|
|
9367
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
9368
|
+
};
|
|
9369
|
+
/**
|
|
9370
|
+
* Namespace rules for an element in the HTML namespace.
|
|
9371
|
+
*
|
|
9372
|
+
* @param tagName the element's lowercase tag name
|
|
9373
|
+
* @param parent the (possibly simulated) parent node
|
|
9374
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9375
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9376
|
+
*/
|
|
9377
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
|
|
9378
|
+
// The only way to switch from SVG to HTML is via
|
|
9379
|
+
// HTML integration points, and from MathML to HTML
|
|
9380
|
+
// is via MathML text integration points
|
|
9381
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
9382
|
+
return false;
|
|
9383
|
+
}
|
|
9384
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
9385
|
+
return false;
|
|
9386
|
+
}
|
|
9387
|
+
// We disallow tags that are specific for MathML
|
|
9388
|
+
// or SVG and should never appear in HTML namespace
|
|
9389
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
9390
|
+
};
|
|
9055
9391
|
/**
|
|
9056
9392
|
* @param element a DOM element whose namespace is being checked
|
|
9057
9393
|
* @returns Return false if the element has a
|
|
@@ -9074,51 +9410,13 @@ function requirePurify_cjs () {
|
|
|
9074
9410
|
return false;
|
|
9075
9411
|
}
|
|
9076
9412
|
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
9077
|
-
|
|
9078
|
-
// is via <svg>. If it happens via any other tag, then
|
|
9079
|
-
// it should be killed.
|
|
9080
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9081
|
-
return tagName === 'svg';
|
|
9082
|
-
}
|
|
9083
|
-
// The only way to switch from MathML to SVG is via`
|
|
9084
|
-
// svg if parent is either <annotation-xml> or MathML
|
|
9085
|
-
// text integration points.
|
|
9086
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
9087
|
-
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
9088
|
-
}
|
|
9089
|
-
// We only allow elements that are defined in SVG
|
|
9090
|
-
// spec. All others are disallowed in SVG namespace.
|
|
9091
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
9413
|
+
return _checkSvgNamespace(tagName, parent, parentTagName);
|
|
9092
9414
|
}
|
|
9093
9415
|
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
9094
|
-
|
|
9095
|
-
// is via <math>. If it happens via any other tag, then
|
|
9096
|
-
// it should be killed.
|
|
9097
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9098
|
-
return tagName === 'math';
|
|
9099
|
-
}
|
|
9100
|
-
// The only way to switch from SVG to MathML is via
|
|
9101
|
-
// <math> and HTML integration points
|
|
9102
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
9103
|
-
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
9104
|
-
}
|
|
9105
|
-
// We only allow elements that are defined in MathML
|
|
9106
|
-
// spec. All others are disallowed in MathML namespace.
|
|
9107
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
9416
|
+
return _checkMathMlNamespace(tagName, parent, parentTagName);
|
|
9108
9417
|
}
|
|
9109
9418
|
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
9110
|
-
|
|
9111
|
-
// HTML integration points, and from MathML to HTML
|
|
9112
|
-
// is via MathML text integration points
|
|
9113
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
9114
|
-
return false;
|
|
9115
|
-
}
|
|
9116
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
9117
|
-
return false;
|
|
9118
|
-
}
|
|
9119
|
-
// We disallow tags that are specific for MathML
|
|
9120
|
-
// or SVG and should never appear in HTML namespace
|
|
9121
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
9419
|
+
return _checkHtmlNamespace(tagName, parent, parentTagName);
|
|
9122
9420
|
}
|
|
9123
9421
|
// For XHTML and XML documents that support custom namespaces
|
|
9124
9422
|
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
@@ -9143,7 +9441,74 @@ function requirePurify_cjs () {
|
|
|
9143
9441
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
9144
9442
|
getParentNode(node).removeChild(node);
|
|
9145
9443
|
} catch (_) {
|
|
9444
|
+
/* The normal detach failed — this is reached for a parentless node
|
|
9445
|
+
(getParentNode() is null, so .removeChild throws). Element.prototype
|
|
9446
|
+
.remove() is itself a spec no-op on a parentless node, so a recorded
|
|
9447
|
+
"removal" would otherwise hand the caller back an intact,
|
|
9448
|
+
payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
|
|
9449
|
+
the style-with-element-child rule decided to kill). Fail closed by
|
|
9450
|
+
throwing — exactly as a clobbered root does at the IN_PLACE entry —
|
|
9451
|
+
rather than trying to "neutralize" the node via its own methods.
|
|
9452
|
+
Neutralizing would mean calling getAttributeNames()/removeAttribute()
|
|
9453
|
+
on the node, both of which a <form> root can clobber via a named child
|
|
9454
|
+
(and _isClobbered does not even probe getAttributeNames), so the
|
|
9455
|
+
neutralize step could itself be silently defeated, leaving the payload
|
|
9456
|
+
intact. A throw touches only the cached, clobber-safe remove() and
|
|
9457
|
+
getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
|
|
9458
|
+
to every root-kill reason. REPORT-3.
|
|
9459
|
+
This lives inside the catch, so it never fires for a normally-removed
|
|
9460
|
+
in-tree node: those have a parent, removeChild() succeeds, and the
|
|
9461
|
+
catch is not entered. Only a kept (parentless) root reaches here. */
|
|
9146
9462
|
remove(node);
|
|
9463
|
+
if (!getParentNode(node)) {
|
|
9464
|
+
throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
|
|
9465
|
+
}
|
|
9466
|
+
}
|
|
9467
|
+
};
|
|
9468
|
+
/**
|
|
9469
|
+
* _neutralizeRoot
|
|
9470
|
+
*
|
|
9471
|
+
* Fail-closed teardown of an in-place root after the sanitize walk aborts
|
|
9472
|
+
* (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
|
|
9473
|
+
* custom element's reaction detaches a node so `_forceRemove`'s deliberate
|
|
9474
|
+
* parentless guard throws, or any other re-entrant engine mutation — would
|
|
9475
|
+
* otherwise leave the caller's *live* tree half-sanitized, with everything
|
|
9476
|
+
* after the abort point still carrying its handlers. There is no safe way
|
|
9477
|
+
* to resume the walk (the tree mutated under us), so we strip the root bare:
|
|
9478
|
+
* remove every child and every attribute, then let the caller's catch see
|
|
9479
|
+
* the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
|
|
9480
|
+
* getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
|
|
9481
|
+
*
|
|
9482
|
+
* @param root the in-place root to empty
|
|
9483
|
+
*/
|
|
9484
|
+
const _neutralizeRoot = function _neutralizeRoot(root) {
|
|
9485
|
+
const childNodes = getChildNodes(root);
|
|
9486
|
+
if (childNodes) {
|
|
9487
|
+
const snapshot = [];
|
|
9488
|
+
arrayForEach(childNodes, child => {
|
|
9489
|
+
arrayPush(snapshot, child);
|
|
9490
|
+
});
|
|
9491
|
+
arrayForEach(snapshot, child => {
|
|
9492
|
+
try {
|
|
9493
|
+
remove(child);
|
|
9494
|
+
} catch (_) {
|
|
9495
|
+
/* Best-effort teardown; a still-attached child is handled below */
|
|
9496
|
+
}
|
|
9497
|
+
});
|
|
9498
|
+
}
|
|
9499
|
+
const attributes = getAttributes(root);
|
|
9500
|
+
if (attributes) {
|
|
9501
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
9502
|
+
const attribute = attributes[i];
|
|
9503
|
+
const name = attribute && attribute.name;
|
|
9504
|
+
if (typeof name === 'string') {
|
|
9505
|
+
try {
|
|
9506
|
+
root.removeAttribute(name);
|
|
9507
|
+
} catch (_) {
|
|
9508
|
+
/* Clobbered removeAttribute — ignore (fail-closed best effort) */
|
|
9509
|
+
}
|
|
9510
|
+
}
|
|
9511
|
+
}
|
|
9147
9512
|
}
|
|
9148
9513
|
};
|
|
9149
9514
|
/**
|
|
@@ -9178,6 +9543,72 @@ function requirePurify_cjs () {
|
|
|
9178
9543
|
}
|
|
9179
9544
|
}
|
|
9180
9545
|
};
|
|
9546
|
+
/**
|
|
9547
|
+
* _stripDisallowedAttributes
|
|
9548
|
+
*
|
|
9549
|
+
* Removes every attribute the active configuration does not allow from a
|
|
9550
|
+
* single element, using the same allowlist as the main attribute pass (so
|
|
9551
|
+
* `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
|
|
9552
|
+
* neutralise nodes that are being discarded from an in-place tree.
|
|
9553
|
+
*
|
|
9554
|
+
* @param element the element to strip
|
|
9555
|
+
*/
|
|
9556
|
+
const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
|
|
9557
|
+
const attributes = getAttributes(element);
|
|
9558
|
+
if (!attributes) {
|
|
9559
|
+
return;
|
|
9560
|
+
}
|
|
9561
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
9562
|
+
const attribute = attributes[i];
|
|
9563
|
+
const name = attribute && attribute.name;
|
|
9564
|
+
if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
|
|
9565
|
+
continue;
|
|
9566
|
+
}
|
|
9567
|
+
try {
|
|
9568
|
+
element.removeAttribute(name);
|
|
9569
|
+
} catch (_) {
|
|
9570
|
+
/* Clobbered removeAttribute on a doomed node — ignore */
|
|
9571
|
+
}
|
|
9572
|
+
}
|
|
9573
|
+
};
|
|
9574
|
+
/**
|
|
9575
|
+
* _neutralizeSubtree
|
|
9576
|
+
*
|
|
9577
|
+
* Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
|
|
9578
|
+
* move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
|
|
9579
|
+
* namespace, comment, processing-instruction and KEEP_CONTENT:false removals
|
|
9580
|
+
* all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
|
|
9581
|
+
* those dropped nodes are detached from the caller's LIVE tree but a
|
|
9582
|
+
* handler-bearing original among them (an `<img onerror>`/`<video>` that was
|
|
9583
|
+
* loading) keeps its queued resource event, which fires in page scope after
|
|
9584
|
+
* sanitize returns. This walks a removed subtree and strips every attribute
|
|
9585
|
+
* the active configuration does not allow — so `on*` handlers are cancelled
|
|
9586
|
+
* through the SAME allowlist that governs kept nodes, not a separate `/^on/`
|
|
9587
|
+
* blocklist. Run synchronously before sanitize returns, i.e. before any
|
|
9588
|
+
* queued event can fire. Hook-free by design: these nodes leave the output,
|
|
9589
|
+
* so firing attribute hooks for them would be surprising. Clobber-safe reads;
|
|
9590
|
+
* a doomed clobbered node may shadow `removeAttribute` (its own attributes are
|
|
9591
|
+
* irrelevant — it is discarded — while its non-clobbered descendants, e.g.
|
|
9592
|
+
* the `<img>`, are reached and scrubbed).
|
|
9593
|
+
*
|
|
9594
|
+
* @param root the root of a removed subtree to neutralise
|
|
9595
|
+
*/
|
|
9596
|
+
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
9597
|
+
const stack = [root];
|
|
9598
|
+
while (stack.length > 0) {
|
|
9599
|
+
const node = stack.pop();
|
|
9600
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
9601
|
+
if (nodeType === NODE_TYPE.element) {
|
|
9602
|
+
_stripDisallowedAttributes(node);
|
|
9603
|
+
}
|
|
9604
|
+
const childNodes = getChildNodes(node);
|
|
9605
|
+
if (childNodes) {
|
|
9606
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
9607
|
+
stack.push(childNodes[i]);
|
|
9608
|
+
}
|
|
9609
|
+
}
|
|
9610
|
+
}
|
|
9611
|
+
};
|
|
9181
9612
|
/**
|
|
9182
9613
|
* _initDocument
|
|
9183
9614
|
*
|
|
@@ -9199,7 +9630,7 @@ function requirePurify_cjs () {
|
|
|
9199
9630
|
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
|
|
9200
9631
|
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
|
|
9201
9632
|
}
|
|
9202
|
-
const dirtyPayload = trustedTypesPolicy ?
|
|
9633
|
+
const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
|
|
9203
9634
|
/*
|
|
9204
9635
|
* Use the DOMParser API by default, fallback later if needs be
|
|
9205
9636
|
* DOMParser not work for svg when has multiple root element.
|
|
@@ -9239,29 +9670,254 @@ function requirePurify_cjs () {
|
|
|
9239
9670
|
// eslint-disable-next-line no-bitwise
|
|
9240
9671
|
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
9241
9672
|
};
|
|
9673
|
+
/**
|
|
9674
|
+
* Replace template expression syntax (mustache, ERB, template
|
|
9675
|
+
* literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
|
|
9676
|
+
* sites. Order matters: mustache, then ERB, then template literal.
|
|
9677
|
+
*
|
|
9678
|
+
* @param value the string to scrub
|
|
9679
|
+
* @returns the scrubbed string
|
|
9680
|
+
*/
|
|
9681
|
+
const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
|
|
9682
|
+
value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
|
|
9683
|
+
value = stringReplace(value, ERB_EXPR$1, ' ');
|
|
9684
|
+
value = stringReplace(value, TMPLIT_EXPR$1, ' ');
|
|
9685
|
+
return value;
|
|
9686
|
+
};
|
|
9687
|
+
/**
|
|
9688
|
+
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
|
|
9689
|
+
* character data of an element subtree. Used as the final safety net for
|
|
9690
|
+
* SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
|
|
9691
|
+
* which only form after text-node normalization (e.g. fragments split across
|
|
9692
|
+
* stripped elements) cannot survive into a template-evaluating framework.
|
|
9693
|
+
*
|
|
9694
|
+
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
|
|
9695
|
+
* in place rather than round-tripping through innerHTML. This preserves
|
|
9696
|
+
* descendant node references (important for IN_PLACE callers), avoids a
|
|
9697
|
+
* serialize/reparse cycle, and reads literal character data — which means
|
|
9698
|
+
* `<%...%>` in text content matches the ERB regex against its real bytes
|
|
9699
|
+
* instead of the HTML-entity-escaped form innerHTML would produce.
|
|
9700
|
+
*
|
|
9701
|
+
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
|
|
9702
|
+
* attributes is performed during the per-node `_sanitizeAttributes` pass.
|
|
9703
|
+
*
|
|
9704
|
+
* @param node The root element whose character data should be scrubbed.
|
|
9705
|
+
*/
|
|
9706
|
+
const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
|
|
9707
|
+
var _node$querySelectorAl;
|
|
9708
|
+
node.normalize();
|
|
9709
|
+
const walker = createNodeIterator.call(node.ownerDocument || node, node,
|
|
9710
|
+
// eslint-disable-next-line no-bitwise
|
|
9711
|
+
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
9712
|
+
let currentNode = walker.nextNode();
|
|
9713
|
+
while (currentNode) {
|
|
9714
|
+
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
9715
|
+
currentNode = walker.nextNode();
|
|
9716
|
+
}
|
|
9717
|
+
// NodeIterator does not descend into <template>.content per the DOM spec,
|
|
9718
|
+
// so we must explicitly recurse into each template's content fragment,
|
|
9719
|
+
// mirroring the approach used by _sanitizeShadowDOM.
|
|
9720
|
+
const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
|
|
9721
|
+
if (templates) {
|
|
9722
|
+
arrayForEach(templates, tmpl => {
|
|
9723
|
+
if (_isDocumentFragment(tmpl.content)) {
|
|
9724
|
+
_scrubTemplateExpressions2(tmpl.content);
|
|
9725
|
+
}
|
|
9726
|
+
});
|
|
9727
|
+
}
|
|
9728
|
+
};
|
|
9242
9729
|
/**
|
|
9243
9730
|
* _isClobbered
|
|
9244
9731
|
*
|
|
9732
|
+
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
|
|
9733
|
+
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
9734
|
+
* `name` attribute matching a prototype property shadows that property
|
|
9735
|
+
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
9736
|
+
* during attribute sanitization to refuse clobbered forms.
|
|
9737
|
+
*
|
|
9245
9738
|
* @param element element to check for clobbering attacks
|
|
9246
9739
|
* @return true if clobbered, false if safe
|
|
9247
9740
|
*/
|
|
9248
9741
|
const _isClobbered = function _isClobbered(element) {
|
|
9249
|
-
|
|
9742
|
+
// Realm-independent tag-name probe. If we can't determine the tag
|
|
9743
|
+
// name at all, we can't reason about clobbering — return false
|
|
9744
|
+
// (the caller's other defences still apply).
|
|
9745
|
+
const realTagName = getNodeName ? getNodeName(element) : null;
|
|
9746
|
+
if (typeof realTagName !== 'string') {
|
|
9747
|
+
return false;
|
|
9748
|
+
}
|
|
9749
|
+
if (transformCaseFunc(realTagName) !== 'form') {
|
|
9750
|
+
return false;
|
|
9751
|
+
}
|
|
9752
|
+
return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
|
|
9753
|
+
// Realm-safe NamedNodeMap detection: equality against the cached
|
|
9754
|
+
// prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
|
|
9755
|
+
// makes the direct read diverge from the cached read; a clean form
|
|
9756
|
+
// (same-realm OR foreign-realm) has both reads pointing at the same
|
|
9757
|
+
// canonical NamedNodeMap.
|
|
9758
|
+
element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
|
|
9759
|
+
// NodeType clobbering probe. Cached Node.prototype.nodeType getter
|
|
9760
|
+
// returns the integer 1 for any Element regardless of realm; direct
|
|
9761
|
+
// read on a clobbered form (e.g. <input name="nodeType">) returns
|
|
9762
|
+
// the named child element. Cheap addition — nodeType is read from
|
|
9763
|
+
// an internal slot, no serialization cost — and removes a residual
|
|
9764
|
+
// clobbering surface used by several mXSS / PI / comment branches
|
|
9765
|
+
// in _sanitizeElements that compare currentNode.nodeType directly.
|
|
9766
|
+
element.nodeType !== getNodeType(element) ||
|
|
9767
|
+
// HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
|
|
9768
|
+
// "childNodes" shadows the prototype getter. Direct reads of
|
|
9769
|
+
// form.childNodes from a clobbered form return the named child
|
|
9770
|
+
// instead of the real NodeList, so any walk that reads it directly
|
|
9771
|
+
// skips the form's real children. Compare the direct read to the
|
|
9772
|
+
// cached Node.prototype getter — when the form's named-property
|
|
9773
|
+
// getter intercepts the read, the two values differ and we flag
|
|
9774
|
+
// the form. This catches every clobbering child type (input,
|
|
9775
|
+
// select, etc.) regardless of whether the named child happens to
|
|
9776
|
+
// carry a numeric .length, which a typeof-based probe would miss
|
|
9777
|
+
// (e.g. HTMLSelectElement.length is a defined unsigned-long).
|
|
9778
|
+
element.childNodes !== getChildNodes(element);
|
|
9779
|
+
};
|
|
9780
|
+
/**
|
|
9781
|
+
* Checks whether the given value is a DocumentFragment from any realm.
|
|
9782
|
+
*
|
|
9783
|
+
* The realm-independent replacement reads `nodeType` through the cached
|
|
9784
|
+
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
|
|
9785
|
+
* constant (11). nodeType is a numeric value resolved from the node's
|
|
9786
|
+
* internal slot, identical across realms for the same kind of node.
|
|
9787
|
+
*
|
|
9788
|
+
* @param value object to check
|
|
9789
|
+
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
9790
|
+
*/
|
|
9791
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
9792
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
9793
|
+
return false;
|
|
9794
|
+
}
|
|
9795
|
+
try {
|
|
9796
|
+
return getNodeType(value) === NODE_TYPE.documentFragment;
|
|
9797
|
+
} catch (_) {
|
|
9798
|
+
return false;
|
|
9799
|
+
}
|
|
9250
9800
|
};
|
|
9251
9801
|
/**
|
|
9252
|
-
* Checks whether the given object is a DOM node
|
|
9802
|
+
* Checks whether the given object is a DOM node, including nodes that
|
|
9803
|
+
* originate from a different window/realm (e.g. an iframe's
|
|
9804
|
+
* contentDocument). The previous `value instanceof Node` check was
|
|
9805
|
+
* realm-bound: nodes from a different window failed it, causing
|
|
9806
|
+
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
9807
|
+
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
9253
9808
|
*
|
|
9254
9809
|
* @param value object to check whether it's a DOM node
|
|
9255
|
-
* @return true
|
|
9810
|
+
* @return true if value is a DOM node from any realm
|
|
9256
9811
|
*/
|
|
9257
9812
|
const _isNode = function _isNode(value) {
|
|
9258
|
-
|
|
9813
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
9814
|
+
return false;
|
|
9815
|
+
}
|
|
9816
|
+
try {
|
|
9817
|
+
return typeof getNodeType(value) === 'number';
|
|
9818
|
+
} catch (_) {
|
|
9819
|
+
return false;
|
|
9820
|
+
}
|
|
9259
9821
|
};
|
|
9260
9822
|
function _executeHooks(hooks, currentNode, data) {
|
|
9823
|
+
if (hooks.length === 0) {
|
|
9824
|
+
return;
|
|
9825
|
+
}
|
|
9261
9826
|
arrayForEach(hooks, hook => {
|
|
9262
9827
|
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
9263
9828
|
});
|
|
9264
9829
|
}
|
|
9830
|
+
/**
|
|
9831
|
+
* Structural-threat checks that condemn a node regardless of the
|
|
9832
|
+
* allowlists: mXSS via namespace confusion, risky CSS construction,
|
|
9833
|
+
* processing instructions, markup-bearing comments. Pure predicate;
|
|
9834
|
+
* the caller removes. Check order is load-bearing.
|
|
9835
|
+
*
|
|
9836
|
+
* @param currentNode the node to inspect
|
|
9837
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
9838
|
+
* @return true if the node must be removed
|
|
9839
|
+
*/
|
|
9840
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
9841
|
+
/* Detect mXSS attempts abusing namespace confusion */
|
|
9842
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
|
|
9843
|
+
return true;
|
|
9844
|
+
}
|
|
9845
|
+
/* Remove risky CSS construction leading to mXSS */
|
|
9846
|
+
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
9847
|
+
return true;
|
|
9848
|
+
}
|
|
9849
|
+
/* Remove any occurrence of processing instructions */
|
|
9850
|
+
if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
|
|
9851
|
+
return true;
|
|
9852
|
+
}
|
|
9853
|
+
/* Remove any kind of possibly harmful comments */
|
|
9854
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
|
|
9855
|
+
return true;
|
|
9856
|
+
}
|
|
9857
|
+
return false;
|
|
9858
|
+
};
|
|
9859
|
+
/**
|
|
9860
|
+
* Handle a node whose tag is forbidden or not allowlisted: keep
|
|
9861
|
+
* allowed custom elements (false return exits _sanitizeElements
|
|
9862
|
+
* early - namespace/fallback checks and the afterSanitizeElements
|
|
9863
|
+
* hook are intentionally skipped for kept custom elements), else
|
|
9864
|
+
* hoist content per KEEP_CONTENT and remove.
|
|
9865
|
+
*
|
|
9866
|
+
* @param currentNode the disallowed node
|
|
9867
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
9868
|
+
* @return true if the node was removed, false if kept
|
|
9869
|
+
*/
|
|
9870
|
+
const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
|
|
9871
|
+
/* Check if we have a custom element to handle */
|
|
9872
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
9873
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
9874
|
+
return false;
|
|
9875
|
+
}
|
|
9876
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
9877
|
+
return false;
|
|
9878
|
+
}
|
|
9879
|
+
}
|
|
9880
|
+
/* Keep content except for bad-listed elements.
|
|
9881
|
+
Use the cached prototype getters exclusively — the previous code
|
|
9882
|
+
had `|| currentNode.parentNode` / `|| currentNode.childNodes`
|
|
9883
|
+
fallbacks, but the cached getters always return the canonical
|
|
9884
|
+
value (or null for a real parent-less node), so the fallback
|
|
9885
|
+
path was dead in safe cases and a clobbering surface in unsafe
|
|
9886
|
+
ones. Falsy cached results stay falsy; the `if (childNodes &&
|
|
9887
|
+
parentNode)` check already gates correctly. */
|
|
9888
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
9889
|
+
const parentNode = getParentNode(currentNode);
|
|
9890
|
+
const childNodes = getChildNodes(currentNode);
|
|
9891
|
+
if (childNodes && parentNode) {
|
|
9892
|
+
const childCount = childNodes.length;
|
|
9893
|
+
/* In-place: hoist the *original* children so the iterator visits
|
|
9894
|
+
and sanitises them through the same allowlist pass as every other
|
|
9895
|
+
node. The caller built the tree in the live document, so the
|
|
9896
|
+
originals carry already-queued resource events (`<img onerror>`,
|
|
9897
|
+
`<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
|
|
9898
|
+
those originals detached but still armed, firing in page scope
|
|
9899
|
+
while the returned tree looked clean. Moving is safe in-place: the
|
|
9900
|
+
root is pre-validated as an allowed tag and so is never the node
|
|
9901
|
+
being removed, which keeps `parentNode` inside the iterator root
|
|
9902
|
+
and the relocated child inside the serialised tree.
|
|
9903
|
+
Otherwise (string / DOM-copy paths): clone. The iterator is rooted
|
|
9904
|
+
at — and the result serialised from — `body`, so a restrictive
|
|
9905
|
+
ALLOWED_TAGS that removes `body` itself must leave its content in
|
|
9906
|
+
place, which only cloning does; and those paths parse into an
|
|
9907
|
+
inert document, so their discarded originals never had a queued
|
|
9908
|
+
event to neutralise.
|
|
9909
|
+
`childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
|
|
9910
|
+
valid whether we move (drops the trailing entry) or clone (leaves
|
|
9911
|
+
the list intact). */
|
|
9912
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
9913
|
+
const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
|
|
9914
|
+
parentNode.insertBefore(hoisted, getNextSibling(currentNode));
|
|
9915
|
+
}
|
|
9916
|
+
}
|
|
9917
|
+
}
|
|
9918
|
+
_forceRemove(currentNode);
|
|
9919
|
+
return true;
|
|
9920
|
+
};
|
|
9265
9921
|
/**
|
|
9266
9922
|
* _sanitizeElements
|
|
9267
9923
|
*
|
|
@@ -9272,7 +9928,6 @@ function requirePurify_cjs () {
|
|
|
9272
9928
|
* @return true if node was killed, false if left alive
|
|
9273
9929
|
*/
|
|
9274
9930
|
const _sanitizeElements = function _sanitizeElements(currentNode) {
|
|
9275
|
-
let content = null;
|
|
9276
9931
|
/* Execute a hook if present */
|
|
9277
9932
|
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
9278
9933
|
/* Check if element is clobbered or can clobber */
|
|
@@ -9281,76 +9936,41 @@ function requirePurify_cjs () {
|
|
|
9281
9936
|
return true;
|
|
9282
9937
|
}
|
|
9283
9938
|
/* Now let's check the element's type and name */
|
|
9284
|
-
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
9939
|
+
const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
|
|
9285
9940
|
/* Execute a hook if present */
|
|
9286
9941
|
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
9287
9942
|
tagName,
|
|
9288
9943
|
allowedTags: ALLOWED_TAGS
|
|
9289
9944
|
});
|
|
9290
|
-
/*
|
|
9291
|
-
if (
|
|
9292
|
-
_forceRemove(currentNode);
|
|
9293
|
-
return true;
|
|
9294
|
-
}
|
|
9295
|
-
/* Remove risky CSS construction leading to mXSS */
|
|
9296
|
-
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
9297
|
-
_forceRemove(currentNode);
|
|
9298
|
-
return true;
|
|
9299
|
-
}
|
|
9300
|
-
/* Remove any occurrence of processing instructions */
|
|
9301
|
-
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
9302
|
-
_forceRemove(currentNode);
|
|
9303
|
-
return true;
|
|
9304
|
-
}
|
|
9305
|
-
/* Remove any kind of possibly harmful comments */
|
|
9306
|
-
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
9945
|
+
/* Remove mXSS vectors, processing instructions and risky comments */
|
|
9946
|
+
if (_isUnsafeNode(currentNode, tagName)) {
|
|
9307
9947
|
_forceRemove(currentNode);
|
|
9308
9948
|
return true;
|
|
9309
9949
|
}
|
|
9310
9950
|
/* Remove element if anything forbids its presence */
|
|
9311
9951
|
if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
|
|
9312
|
-
|
|
9313
|
-
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
9314
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
9315
|
-
return false;
|
|
9316
|
-
}
|
|
9317
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
9318
|
-
return false;
|
|
9319
|
-
}
|
|
9320
|
-
}
|
|
9321
|
-
/* Keep content except for bad-listed elements */
|
|
9322
|
-
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
9323
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
9324
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
9325
|
-
if (childNodes && parentNode) {
|
|
9326
|
-
const childCount = childNodes.length;
|
|
9327
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
|
9328
|
-
const childClone = cloneNode(childNodes[i], true);
|
|
9329
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
9330
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
9331
|
-
}
|
|
9332
|
-
}
|
|
9333
|
-
}
|
|
9334
|
-
_forceRemove(currentNode);
|
|
9335
|
-
return true;
|
|
9952
|
+
return _sanitizeDisallowedNode(currentNode, tagName);
|
|
9336
9953
|
}
|
|
9337
|
-
/* Check whether element has a valid namespace
|
|
9338
|
-
|
|
9954
|
+
/* Check whether element has a valid namespace.
|
|
9955
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
|
|
9956
|
+
nodeType getter rather than `instanceof Element`, which is realm-
|
|
9957
|
+
bound and short-circuits to false for any node minted in a different
|
|
9958
|
+
realm — letting a foreign-realm element with a forbidden namespace
|
|
9959
|
+
slip past the namespace check entirely. */
|
|
9960
|
+
const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
|
|
9961
|
+
if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
9339
9962
|
_forceRemove(currentNode);
|
|
9340
9963
|
return true;
|
|
9341
9964
|
}
|
|
9342
9965
|
/* Make sure that older browsers don't get fallback-tag mXSS */
|
|
9343
|
-
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(
|
|
9966
|
+
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
|
|
9344
9967
|
_forceRemove(currentNode);
|
|
9345
9968
|
return true;
|
|
9346
9969
|
}
|
|
9347
9970
|
/* Sanitize element content to be template-safe */
|
|
9348
9971
|
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
9349
9972
|
/* Get the element's text content */
|
|
9350
|
-
content = currentNode.textContent;
|
|
9351
|
-
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
9352
|
-
content = stringReplace(content, expr, ' ');
|
|
9353
|
-
});
|
|
9973
|
+
const content = _stripTemplateExpressions(currentNode.textContent);
|
|
9354
9974
|
if (currentNode.textContent !== content) {
|
|
9355
9975
|
arrayPush(DOMPurify.removed, {
|
|
9356
9976
|
element: currentNode.cloneNode()
|
|
@@ -9380,11 +10000,12 @@ function requirePurify_cjs () {
|
|
|
9380
10000
|
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
9381
10001
|
return false;
|
|
9382
10002
|
}
|
|
10003
|
+
const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
|
|
9383
10004
|
/* Allow valid data-* attributes: At least one character after "-"
|
|
9384
10005
|
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
9385
10006
|
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
9386
10007
|
We don't need to check the value; it's always URI safe. */
|
|
9387
|
-
if (ALLOW_DATA_ATTR &&
|
|
10008
|
+
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
|
|
9388
10009
|
if (
|
|
9389
10010
|
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
9390
10011
|
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
@@ -9396,11 +10017,15 @@ function requirePurify_cjs () {
|
|
|
9396
10017
|
return false;
|
|
9397
10018
|
}
|
|
9398
10019
|
/* Check value is safe. First, is attr inert? If so, is safe */
|
|
9399
|
-
} 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) {
|
|
10020
|
+
} 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) {
|
|
9400
10021
|
return false;
|
|
9401
10022
|
} else ;
|
|
9402
10023
|
return true;
|
|
9403
10024
|
};
|
|
10025
|
+
/* Names the HTML spec reserves from valid-custom-element-name; these must
|
|
10026
|
+
* never be treated as basic custom elements even when a permissive
|
|
10027
|
+
* CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
|
|
10028
|
+
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']);
|
|
9404
10029
|
/**
|
|
9405
10030
|
* _isBasicCustomElement
|
|
9406
10031
|
* checks if at least one dash is included in tagName, and it's not the first char
|
|
@@ -9410,7 +10035,64 @@ function requirePurify_cjs () {
|
|
|
9410
10035
|
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
9411
10036
|
*/
|
|
9412
10037
|
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
9413
|
-
return tagName
|
|
10038
|
+
return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
|
|
10039
|
+
};
|
|
10040
|
+
/**
|
|
10041
|
+
* Wrap an attribute value in the matching Trusted Types object when
|
|
10042
|
+
* the active policy requires it. Namespaced attributes pass through
|
|
10043
|
+
* unchanged (no TT support yet, see
|
|
10044
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
|
|
10045
|
+
*
|
|
10046
|
+
* @param lcTag lowercase tag name of the containing element
|
|
10047
|
+
* @param lcName lowercase attribute name
|
|
10048
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
10049
|
+
* @param value the attribute value to wrap
|
|
10050
|
+
* @return the value, wrapped when Trusted Types demand it
|
|
10051
|
+
*/
|
|
10052
|
+
const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
|
|
10053
|
+
if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
|
|
10054
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
10055
|
+
case 'TrustedHTML':
|
|
10056
|
+
{
|
|
10057
|
+
return _createTrustedHTML(value);
|
|
10058
|
+
}
|
|
10059
|
+
case 'TrustedScriptURL':
|
|
10060
|
+
{
|
|
10061
|
+
return _createTrustedScriptURL(value);
|
|
10062
|
+
}
|
|
10063
|
+
}
|
|
10064
|
+
}
|
|
10065
|
+
return value;
|
|
10066
|
+
};
|
|
10067
|
+
/**
|
|
10068
|
+
* Write a modified attribute value back onto the element. On
|
|
10069
|
+
* success, re-probe for clobbering introduced by the new value and
|
|
10070
|
+
* remove the element when found; otherwise pop the removal entry
|
|
10071
|
+
* recorded by the earlier _removeAttribute (long-standing pairing
|
|
10072
|
+
* with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
|
|
10073
|
+
* failure, remove the attribute instead.
|
|
10074
|
+
*
|
|
10075
|
+
* @param currentNode the element carrying the attribute
|
|
10076
|
+
* @param name the attribute name as present on the element
|
|
10077
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
10078
|
+
* @param value the new attribute value
|
|
10079
|
+
*/
|
|
10080
|
+
const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
|
|
10081
|
+
try {
|
|
10082
|
+
if (namespaceURI) {
|
|
10083
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
10084
|
+
} else {
|
|
10085
|
+
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
10086
|
+
currentNode.setAttribute(name, value);
|
|
10087
|
+
}
|
|
10088
|
+
if (_isClobbered(currentNode)) {
|
|
10089
|
+
_forceRemove(currentNode);
|
|
10090
|
+
} else {
|
|
10091
|
+
arrayPop(DOMPurify.removed);
|
|
10092
|
+
}
|
|
10093
|
+
} catch (_) {
|
|
10094
|
+
_removeAttribute(name, currentNode);
|
|
10095
|
+
}
|
|
9414
10096
|
};
|
|
9415
10097
|
/**
|
|
9416
10098
|
* _sanitizeAttributes
|
|
@@ -9425,9 +10107,7 @@ function requirePurify_cjs () {
|
|
|
9425
10107
|
const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
9426
10108
|
/* Execute a hook if present */
|
|
9427
10109
|
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
9428
|
-
const
|
|
9429
|
-
attributes
|
|
9430
|
-
} = currentNode;
|
|
10110
|
+
const attributes = currentNode.attributes;
|
|
9431
10111
|
/* Check if we have attributes; if not we might have a text node */
|
|
9432
10112
|
if (!attributes || _isClobbered(currentNode)) {
|
|
9433
10113
|
return;
|
|
@@ -9440,14 +10120,13 @@ function requirePurify_cjs () {
|
|
|
9440
10120
|
forceKeepAttr: undefined
|
|
9441
10121
|
};
|
|
9442
10122
|
let l = attributes.length;
|
|
10123
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
9443
10124
|
/* Go backwards over all attributes; safely remove bad ones */
|
|
9444
10125
|
while (l--) {
|
|
9445
10126
|
const attr = attributes[l];
|
|
9446
|
-
const
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
value: attrValue
|
|
9450
|
-
} = attr;
|
|
10127
|
+
const name = attr.name,
|
|
10128
|
+
namespaceURI = attr.namespaceURI,
|
|
10129
|
+
attrValue = attr.value;
|
|
9451
10130
|
const lcName = transformCaseFunc(name);
|
|
9452
10131
|
const initValue = attrValue;
|
|
9453
10132
|
let value = name === 'value' ? initValue : stringTrim(initValue);
|
|
@@ -9461,12 +10140,14 @@ function requirePurify_cjs () {
|
|
|
9461
10140
|
/* Full DOM Clobbering protection via namespace isolation,
|
|
9462
10141
|
* Prefix id and name attributes with `user-content-`
|
|
9463
10142
|
*/
|
|
9464
|
-
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
|
|
10143
|
+
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
|
|
9465
10144
|
// Remove the attribute with this value
|
|
9466
10145
|
_removeAttribute(name, currentNode);
|
|
9467
10146
|
// Prefix the value and later re-create the attribute with the sanitized value
|
|
9468
10147
|
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
9469
10148
|
}
|
|
10149
|
+
// Else: already prefixed, leave the attribute alone — the prefix is
|
|
10150
|
+
// itself the clobbering protection, and re-applying it is incorrect.
|
|
9470
10151
|
/* Work around a security issue with comments inside attributes */
|
|
9471
10152
|
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
9472
10153
|
_removeAttribute(name, currentNode);
|
|
@@ -9477,7 +10158,7 @@ function requirePurify_cjs () {
|
|
|
9477
10158
|
_removeAttribute(name, currentNode);
|
|
9478
10159
|
continue;
|
|
9479
10160
|
}
|
|
9480
|
-
/* Did the hooks
|
|
10161
|
+
/* Did the hooks force-keep the attribute? */
|
|
9481
10162
|
if (hookEvent.forceKeepAttr) {
|
|
9482
10163
|
continue;
|
|
9483
10164
|
}
|
|
@@ -9487,56 +10168,24 @@ function requirePurify_cjs () {
|
|
|
9487
10168
|
continue;
|
|
9488
10169
|
}
|
|
9489
10170
|
/* Work around a security issue in jQuery 3.0 */
|
|
9490
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(
|
|
10171
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
|
|
9491
10172
|
_removeAttribute(name, currentNode);
|
|
9492
10173
|
continue;
|
|
9493
10174
|
}
|
|
9494
10175
|
/* Sanitize attribute content to be template-safe */
|
|
9495
10176
|
if (SAFE_FOR_TEMPLATES) {
|
|
9496
|
-
|
|
9497
|
-
value = stringReplace(value, expr, ' ');
|
|
9498
|
-
});
|
|
10177
|
+
value = _stripTemplateExpressions(value);
|
|
9499
10178
|
}
|
|
9500
10179
|
/* Is `value` valid for this attribute? */
|
|
9501
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
9502
10180
|
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
9503
10181
|
_removeAttribute(name, currentNode);
|
|
9504
10182
|
continue;
|
|
9505
10183
|
}
|
|
9506
10184
|
/* Handle attributes that require Trusted Types */
|
|
9507
|
-
|
|
9508
|
-
if (namespaceURI) ; else {
|
|
9509
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
9510
|
-
case 'TrustedHTML':
|
|
9511
|
-
{
|
|
9512
|
-
value = trustedTypesPolicy.createHTML(value);
|
|
9513
|
-
break;
|
|
9514
|
-
}
|
|
9515
|
-
case 'TrustedScriptURL':
|
|
9516
|
-
{
|
|
9517
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
|
9518
|
-
break;
|
|
9519
|
-
}
|
|
9520
|
-
}
|
|
9521
|
-
}
|
|
9522
|
-
}
|
|
10185
|
+
value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
|
|
9523
10186
|
/* Handle invalid data-* attribute set by try-catching it */
|
|
9524
10187
|
if (value !== initValue) {
|
|
9525
|
-
|
|
9526
|
-
if (namespaceURI) {
|
|
9527
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
9528
|
-
} else {
|
|
9529
|
-
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
9530
|
-
currentNode.setAttribute(name, value);
|
|
9531
|
-
}
|
|
9532
|
-
if (_isClobbered(currentNode)) {
|
|
9533
|
-
_forceRemove(currentNode);
|
|
9534
|
-
} else {
|
|
9535
|
-
arrayPop(DOMPurify.removed);
|
|
9536
|
-
}
|
|
9537
|
-
} catch (_) {
|
|
9538
|
-
_removeAttribute(name, currentNode);
|
|
9539
|
-
}
|
|
10188
|
+
_setAttributeValue(currentNode, name, namespaceURI, value);
|
|
9540
10189
|
}
|
|
9541
10190
|
}
|
|
9542
10191
|
/* Execute a hook if present */
|
|
@@ -9559,14 +10208,133 @@ function requirePurify_cjs () {
|
|
|
9559
10208
|
_sanitizeElements(shadowNode);
|
|
9560
10209
|
/* Check attributes next */
|
|
9561
10210
|
_sanitizeAttributes(shadowNode);
|
|
9562
|
-
/* Deep shadow DOM detected
|
|
9563
|
-
|
|
10211
|
+
/* Deep shadow DOM detected.
|
|
10212
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
|
|
10213
|
+
DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
|
|
10214
|
+
recurse into <template>.content from foreign realms too. */
|
|
10215
|
+
if (_isDocumentFragment(shadowNode.content)) {
|
|
9564
10216
|
_sanitizeShadowDOM2(shadowNode.content);
|
|
9565
10217
|
}
|
|
10218
|
+
/* An element iterated here may itself host an attached
|
|
10219
|
+
shadow root. The default NodeIterator does not enter shadow
|
|
10220
|
+
trees, so a shadow root nested inside template.content was
|
|
10221
|
+
previously reached by no walk at all (the pre-pass at
|
|
10222
|
+
_sanitizeAttachedShadowRoots descends via childNodes, which
|
|
10223
|
+
doesn't enter template.content; the template-content recursion
|
|
10224
|
+
above iterates the content but never inspected shadowRoot).
|
|
10225
|
+
Walk it explicitly. The nodeType guard avoids reading
|
|
10226
|
+
shadowRoot off text / comment / CDATA / PI nodes that the
|
|
10227
|
+
iterator also surfaces. */
|
|
10228
|
+
const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
|
|
10229
|
+
if (shadowNodeType === NODE_TYPE.element) {
|
|
10230
|
+
const innerSr = getShadowRoot(shadowNode);
|
|
10231
|
+
if (_isDocumentFragment(innerSr)) {
|
|
10232
|
+
_sanitizeAttachedShadowRoots(innerSr);
|
|
10233
|
+
_sanitizeShadowDOM2(innerSr);
|
|
10234
|
+
}
|
|
10235
|
+
}
|
|
9566
10236
|
}
|
|
9567
10237
|
/* Execute a hook if present */
|
|
9568
10238
|
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
9569
10239
|
};
|
|
10240
|
+
/**
|
|
10241
|
+
* _sanitizeAttachedShadowRoots
|
|
10242
|
+
*
|
|
10243
|
+
* Walks `root` and feeds every attached shadow root we encounter into
|
|
10244
|
+
* the existing _sanitizeShadowDOM pipeline. The default node iterator
|
|
10245
|
+
* does not descend into shadow trees, so nodes inside an attached
|
|
10246
|
+
* shadow root would otherwise be skipped entirely.
|
|
10247
|
+
*
|
|
10248
|
+
* Two real input paths put attached shadow roots in front of us:
|
|
10249
|
+
* 1. IN_PLACE on a DOM node that already has shadow roots attached.
|
|
10250
|
+
* 2. DOM-node input where importNode(dirty, true) deep-clones the
|
|
10251
|
+
* shadow root because it was created with `clonable: true`.
|
|
10252
|
+
*
|
|
10253
|
+
* This pass runs once, up front, so the main iteration loop (and the
|
|
10254
|
+
* existing _sanitizeShadowDOM template-content recursion) stay
|
|
10255
|
+
* untouched — string-input paths are not affected.
|
|
10256
|
+
*
|
|
10257
|
+
* @param root the subtree root to walk for attached shadow roots
|
|
10258
|
+
*/
|
|
10259
|
+
const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
|
|
10260
|
+
/* Iterative (explicit stack) rather than per-child recursion. DOM APIs
|
|
10261
|
+
impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
|
|
10262
|
+
built straight into the DOM — the IN_PLACE surface) deeper than the JS
|
|
10263
|
+
call-stack budget would otherwise overflow native recursion here and
|
|
10264
|
+
throw at the IN_PLACE entry pre-pass, before a single node is
|
|
10265
|
+
sanitized, leaving the caller's live tree untouched (fail-open). See
|
|
10266
|
+
campaign-3 F4. A heap stack keeps depth off the call stack.
|
|
10267
|
+
Each work item is either a node to descend into, or a deferred
|
|
10268
|
+
`_sanitizeShadowDOM` for an already-walked shadow root. The deferred
|
|
10269
|
+
form preserves the original post-order discipline: a shadow root's
|
|
10270
|
+
nested shadow roots are discovered before the outer shadow is
|
|
10271
|
+
sanitized (which may remove hosts). Pushes are in reverse of the
|
|
10272
|
+
desired processing order (LIFO): template content, then children, then
|
|
10273
|
+
the shadow-sanitize, then the shadow walk — so the order matches the
|
|
10274
|
+
previous recursion exactly. */
|
|
10275
|
+
const stack = [{
|
|
10276
|
+
node: root,
|
|
10277
|
+
shadow: null
|
|
10278
|
+
}];
|
|
10279
|
+
while (stack.length > 0) {
|
|
10280
|
+
const item = stack.pop();
|
|
10281
|
+
/* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
|
|
10282
|
+
if (item.shadow) {
|
|
10283
|
+
_sanitizeShadowDOM2(item.shadow);
|
|
10284
|
+
continue;
|
|
10285
|
+
}
|
|
10286
|
+
const node = item.node;
|
|
10287
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
10288
|
+
const isElement = nodeType === NODE_TYPE.element;
|
|
10289
|
+
/* (pushed last → processed first) Children, snapshotted in reverse so
|
|
10290
|
+
the first child is processed first. Snapshotting matters because a
|
|
10291
|
+
hook may detach siblings mid-walk. */
|
|
10292
|
+
const childNodes = getChildNodes(node);
|
|
10293
|
+
if (childNodes) {
|
|
10294
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
10295
|
+
stack.push({
|
|
10296
|
+
node: childNodes[i],
|
|
10297
|
+
shadow: null
|
|
10298
|
+
});
|
|
10299
|
+
}
|
|
10300
|
+
}
|
|
10301
|
+
/* (pushed before children → processed after them, matching the old
|
|
10302
|
+
"template content last" order) When the node is a <template>,
|
|
10303
|
+
descend into its content. */
|
|
10304
|
+
if (isElement) {
|
|
10305
|
+
const rootName = getNodeName ? getNodeName(node) : null;
|
|
10306
|
+
if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
|
|
10307
|
+
const content = node.content;
|
|
10308
|
+
if (_isDocumentFragment(content)) {
|
|
10309
|
+
stack.push({
|
|
10310
|
+
node: content,
|
|
10311
|
+
shadow: null
|
|
10312
|
+
});
|
|
10313
|
+
}
|
|
10314
|
+
}
|
|
10315
|
+
}
|
|
10316
|
+
/* Shadow root (processed first): walk its subtree, then sanitise it.
|
|
10317
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
10318
|
+
rather than `instanceof DocumentFragment`, which is realm-bound and
|
|
10319
|
+
silently skipped foreign-realm shadow roots (e.g.
|
|
10320
|
+
iframe.contentDocument attachShadow). */
|
|
10321
|
+
if (isElement) {
|
|
10322
|
+
const sr = getShadowRoot(node);
|
|
10323
|
+
if (_isDocumentFragment(sr)) {
|
|
10324
|
+
/* Push the deferred sanitise first so it pops after the shadow
|
|
10325
|
+
walk we push next, i.e. nested shadow roots are discovered
|
|
10326
|
+
before this one is sanitised. */
|
|
10327
|
+
stack.push({
|
|
10328
|
+
node: null,
|
|
10329
|
+
shadow: sr
|
|
10330
|
+
}, {
|
|
10331
|
+
node: sr,
|
|
10332
|
+
shadow: null
|
|
10333
|
+
});
|
|
10334
|
+
}
|
|
10335
|
+
}
|
|
10336
|
+
}
|
|
10337
|
+
};
|
|
9570
10338
|
// eslint-disable-next-line complexity
|
|
9571
10339
|
DOMPurify.sanitize = function (dirty) {
|
|
9572
10340
|
let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -9583,13 +10351,9 @@ function requirePurify_cjs () {
|
|
|
9583
10351
|
}
|
|
9584
10352
|
/* Stringify, in case dirty is an object */
|
|
9585
10353
|
if (typeof dirty !== 'string' && !_isNode(dirty)) {
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
throw typeErrorCreate('dirty is not a string, aborting');
|
|
9590
|
-
}
|
|
9591
|
-
} else {
|
|
9592
|
-
throw typeErrorCreate('toString is not a function');
|
|
10354
|
+
dirty = stringifyValue(dirty);
|
|
10355
|
+
if (typeof dirty !== 'string') {
|
|
10356
|
+
throw typeErrorCreate('dirty is not a string, aborting');
|
|
9593
10357
|
}
|
|
9594
10358
|
}
|
|
9595
10359
|
/* Return dirty HTML if DOMPurify cannot run */
|
|
@@ -9597,24 +10361,78 @@ function requirePurify_cjs () {
|
|
|
9597
10361
|
return dirty;
|
|
9598
10362
|
}
|
|
9599
10363
|
/* Assign config vars */
|
|
9600
|
-
if (
|
|
10364
|
+
if (SET_CONFIG) {
|
|
10365
|
+
/* Persistent setConfig() path: _parseConfig is skipped, so the sets are
|
|
10366
|
+
* not re-derived per call. Restore them from the pristine bindings
|
|
10367
|
+
* captured at setConfig() time so a previous call's hook clone (mutated
|
|
10368
|
+
* below) does not carry over. */
|
|
10369
|
+
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
10370
|
+
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
10371
|
+
} else {
|
|
9601
10372
|
_parseConfig(cfg);
|
|
9602
10373
|
}
|
|
10374
|
+
/* Clone the hook-mutable allowlists before the walk whenever an
|
|
10375
|
+
* uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
|
|
10376
|
+
* and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
|
|
10377
|
+
* a hook that widens them would otherwise mutate the shared set
|
|
10378
|
+
* permanently: across later calls and across every element. Cloning per
|
|
10379
|
+
* walk keeps documented in-call widening working while scoping it to the
|
|
10380
|
+
* call. A single guard for both config paths - the per-call path rebinds
|
|
10381
|
+
* the sets in _parseConfig each call, the persistent path restores them
|
|
10382
|
+
* from the captured bindings just above - so the two cannot diverge. */
|
|
10383
|
+
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
|
|
10384
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
10385
|
+
}
|
|
10386
|
+
if (hooks.uponSanitizeAttribute.length > 0) {
|
|
10387
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
10388
|
+
}
|
|
9603
10389
|
/* Clean up removed elements */
|
|
9604
10390
|
DOMPurify.removed = [];
|
|
9605
|
-
/*
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
10391
|
+
/* Resolve IN_PLACE for this call without mutating persistent config.
|
|
10392
|
+
Writing the IN_PLACE closure variable here leaks under setConfig(),
|
|
10393
|
+
where _parseConfig is skipped on later calls: a single string call would
|
|
10394
|
+
disable in-place mode for every subsequent node call, returning a
|
|
10395
|
+
sanitized copy while leaving the caller's node — which in-place callers
|
|
10396
|
+
keep using and whose return value they ignore — unsanitized. REPORT-2. */
|
|
10397
|
+
const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
|
|
10398
|
+
if (inPlace) {
|
|
10399
|
+
/* Do some early pre-sanitization to avoid unsafe root nodes.
|
|
10400
|
+
Read nodeName through the cached prototype getter — a clobbering
|
|
10401
|
+
child named "nodeName" on the form root would otherwise shadow
|
|
10402
|
+
the property and let this check skip the root-allowlist
|
|
10403
|
+
validation entirely. */
|
|
10404
|
+
const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
|
|
10405
|
+
if (typeof nn === 'string') {
|
|
10406
|
+
const tagName = transformCaseFunc(nn);
|
|
9613
10407
|
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
9614
10408
|
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
|
|
9615
10409
|
}
|
|
9616
10410
|
}
|
|
9617
|
-
|
|
10411
|
+
/* Pre-flight the root through _isClobbered. The iterator-driven
|
|
10412
|
+
removal path can not detach a parent-less root: _forceRemove
|
|
10413
|
+
falls through to Element.prototype.remove(), which per spec
|
|
10414
|
+
is a no-op on a node with no parent. A clobbered root would
|
|
10415
|
+
then survive the main loop with its attributes uninspected,
|
|
10416
|
+
because _sanitizeAttributes early-returns on _isClobbered. The
|
|
10417
|
+
result would be an attacker-controlled form, complete with any
|
|
10418
|
+
event-handler attributes the caller passed in, handed back to
|
|
10419
|
+
the application unsanitized. Refuse to sanitize such a root
|
|
10420
|
+
the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
|
|
10421
|
+
if (_isClobbered(dirty)) {
|
|
10422
|
+
throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
|
|
10423
|
+
}
|
|
10424
|
+
/* Sanitize attached shadow roots before the main iterator runs.
|
|
10425
|
+
The iterator does not descend into shadow trees. Same fail-closed
|
|
10426
|
+
barrier as the main walk (campaign-3 F2): a custom-element reaction
|
|
10427
|
+
inside a shadow root could abort this pre-pass before the walk runs,
|
|
10428
|
+
which would otherwise leave the entire live tree unsanitized. */
|
|
10429
|
+
try {
|
|
10430
|
+
_sanitizeAttachedShadowRoots(dirty);
|
|
10431
|
+
} catch (error) {
|
|
10432
|
+
_neutralizeRoot(dirty);
|
|
10433
|
+
throw error;
|
|
10434
|
+
}
|
|
10435
|
+
} else if (_isNode(dirty)) {
|
|
9618
10436
|
/* If dirty is a DOM element, append to an empty document to avoid
|
|
9619
10437
|
elements being stripped by the parser */
|
|
9620
10438
|
body = _initDocument('<!---->');
|
|
@@ -9628,12 +10446,18 @@ function requirePurify_cjs () {
|
|
|
9628
10446
|
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
9629
10447
|
body.appendChild(importedNode);
|
|
9630
10448
|
}
|
|
10449
|
+
/* Clonable shadow roots are deep-cloned by importNode(); sanitize
|
|
10450
|
+
them before the main iterator runs, since the iterator does not
|
|
10451
|
+
descend into shadow trees. The walk routes every read through a
|
|
10452
|
+
cached prototype getter so clobbering descendants on a form root
|
|
10453
|
+
cannot hide a shadow host from this pass. */
|
|
10454
|
+
_sanitizeAttachedShadowRoots(importedNode);
|
|
9631
10455
|
} else {
|
|
9632
10456
|
/* Exit directly if we have nothing to do */
|
|
9633
10457
|
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
|
|
9634
10458
|
// eslint-disable-next-line unicorn/prefer-includes
|
|
9635
10459
|
dirty.indexOf('<') === -1) {
|
|
9636
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
10460
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
|
|
9637
10461
|
}
|
|
9638
10462
|
/* Initialize the document to work on */
|
|
9639
10463
|
body = _initDocument(dirty);
|
|
@@ -9647,31 +10471,59 @@ function requirePurify_cjs () {
|
|
|
9647
10471
|
_forceRemove(body.firstChild);
|
|
9648
10472
|
}
|
|
9649
10473
|
/* Get node iterator */
|
|
9650
|
-
const nodeIterator = _createNodeIterator(
|
|
9651
|
-
/* Now start iterating over the created document
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
10474
|
+
const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
|
|
10475
|
+
/* Now start iterating over the created document.
|
|
10476
|
+
The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
|
|
10477
|
+
engine/custom-element mutation can detach a node mid-walk so
|
|
10478
|
+
`_forceRemove`'s parentless guard throws, aborting the loop. Without the
|
|
10479
|
+
barrier the caller's in-place tree would be left half-sanitized with the
|
|
10480
|
+
unvisited tail still armed. On any throw we fail closed — strip the
|
|
10481
|
+
in-place root bare — then rethrow so the existing throw contract is
|
|
10482
|
+
preserved. (String/DOM-copy paths never return the partial body, so the
|
|
10483
|
+
propagating throw is already fail-closed there.) */
|
|
10484
|
+
try {
|
|
10485
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
10486
|
+
/* Sanitize tags and elements */
|
|
10487
|
+
_sanitizeElements(currentNode);
|
|
10488
|
+
/* Check attributes next */
|
|
10489
|
+
_sanitizeAttributes(currentNode);
|
|
10490
|
+
/* Shadow DOM detected, sanitize it.
|
|
10491
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
10492
|
+
instead of instanceof, so foreign-realm <template>.content is
|
|
10493
|
+
walked correctly. */
|
|
10494
|
+
if (_isDocumentFragment(currentNode.content)) {
|
|
10495
|
+
_sanitizeShadowDOM2(currentNode.content);
|
|
10496
|
+
}
|
|
9660
10497
|
}
|
|
10498
|
+
} catch (error) {
|
|
10499
|
+
if (inPlace) {
|
|
10500
|
+
_neutralizeRoot(dirty);
|
|
10501
|
+
}
|
|
10502
|
+
throw error;
|
|
9661
10503
|
}
|
|
9662
10504
|
/* If we sanitized `dirty` in-place, return it. */
|
|
9663
|
-
if (
|
|
10505
|
+
if (inPlace) {
|
|
10506
|
+
/* Fail-closed completion of the audit-5 F1 fix: every node removed from
|
|
10507
|
+
the caller's live tree is detached but may still hold a queued
|
|
10508
|
+
resource-event handler that fires in page scope after we return. The
|
|
10509
|
+
move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
|
|
10510
|
+
non-allow-listed attributes off every other removed subtree (clobber,
|
|
10511
|
+
mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
|
|
10512
|
+
cancelled before any event can fire. Runs synchronously, pre-return. */
|
|
10513
|
+
arrayForEach(DOMPurify.removed, entry => {
|
|
10514
|
+
if (entry.element) {
|
|
10515
|
+
_neutralizeSubtree(entry.element);
|
|
10516
|
+
}
|
|
10517
|
+
});
|
|
10518
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
10519
|
+
_scrubTemplateExpressions2(dirty);
|
|
10520
|
+
}
|
|
9664
10521
|
return dirty;
|
|
9665
10522
|
}
|
|
9666
10523
|
/* Return sanitized string or DOM */
|
|
9667
10524
|
if (RETURN_DOM) {
|
|
9668
10525
|
if (SAFE_FOR_TEMPLATES) {
|
|
9669
|
-
body
|
|
9670
|
-
let html = body.innerHTML;
|
|
9671
|
-
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
9672
|
-
html = stringReplace(html, expr, ' ');
|
|
9673
|
-
});
|
|
9674
|
-
body.innerHTML = html;
|
|
10526
|
+
_scrubTemplateExpressions2(body);
|
|
9675
10527
|
}
|
|
9676
10528
|
if (RETURN_DOM_FRAGMENT) {
|
|
9677
10529
|
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
@@ -9701,20 +10553,28 @@ function requirePurify_cjs () {
|
|
|
9701
10553
|
}
|
|
9702
10554
|
/* Sanitize final string template-safe */
|
|
9703
10555
|
if (SAFE_FOR_TEMPLATES) {
|
|
9704
|
-
|
|
9705
|
-
serializedHTML = stringReplace(serializedHTML, expr, ' ');
|
|
9706
|
-
});
|
|
10556
|
+
serializedHTML = _stripTemplateExpressions(serializedHTML);
|
|
9707
10557
|
}
|
|
9708
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
10558
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
9709
10559
|
};
|
|
9710
10560
|
DOMPurify.setConfig = function () {
|
|
9711
10561
|
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
9712
10562
|
_parseConfig(cfg);
|
|
9713
10563
|
SET_CONFIG = true;
|
|
10564
|
+
SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
|
|
10565
|
+
SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
|
|
9714
10566
|
};
|
|
9715
10567
|
DOMPurify.clearConfig = function () {
|
|
9716
10568
|
CONFIG = null;
|
|
9717
10569
|
SET_CONFIG = false;
|
|
10570
|
+
SET_CONFIG_ALLOWED_TAGS = null;
|
|
10571
|
+
SET_CONFIG_ALLOWED_ATTR = null;
|
|
10572
|
+
// Drop any caller-supplied Trusted Types policy so it cannot poison later
|
|
10573
|
+
// `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
|
|
10574
|
+
// never recreated — Trusted Types throws on duplicate names) is restored by
|
|
10575
|
+
// the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
|
|
10576
|
+
trustedTypesPolicy = defaultTrustedTypesPolicy;
|
|
10577
|
+
emptyHTML = '';
|
|
9718
10578
|
};
|
|
9719
10579
|
DOMPurify.isValidAttribute = function (tag, attr, value) {
|
|
9720
10580
|
/* Initialize shared config vars if necessary. */
|
|
@@ -9729,9 +10589,19 @@ function requirePurify_cjs () {
|
|
|
9729
10589
|
if (typeof hookFunction !== 'function') {
|
|
9730
10590
|
return;
|
|
9731
10591
|
}
|
|
10592
|
+
/* Reject unknown entry points. Without this, a non-hook key (e.g.
|
|
10593
|
+
* '__proto__') indexes off the prototype chain rather than a real
|
|
10594
|
+
* hook array, and arrayPush then writes to Object.prototype. Guard
|
|
10595
|
+
* with an own-property check against the known hook names. */
|
|
10596
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
10597
|
+
return;
|
|
10598
|
+
}
|
|
9732
10599
|
arrayPush(hooks[entryPoint], hookFunction);
|
|
9733
10600
|
};
|
|
9734
10601
|
DOMPurify.removeHook = function (entryPoint, hookFunction) {
|
|
10602
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
10603
|
+
return undefined;
|
|
10604
|
+
}
|
|
9735
10605
|
if (hookFunction !== undefined) {
|
|
9736
10606
|
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
9737
10607
|
return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
@@ -9739,6 +10609,9 @@ function requirePurify_cjs () {
|
|
|
9739
10609
|
return arrayPop(hooks[entryPoint]);
|
|
9740
10610
|
};
|
|
9741
10611
|
DOMPurify.removeHooks = function (entryPoint) {
|
|
10612
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
10613
|
+
return;
|
|
10614
|
+
}
|
|
9742
10615
|
hooks[entryPoint] = [];
|
|
9743
10616
|
};
|
|
9744
10617
|
DOMPurify.removeAllHooks = function () {
|
|
@@ -9999,10 +10872,26 @@ var WalletBackground = /*#__PURE__*/function (_Background) {
|
|
|
9999
10872
|
}(Background);
|
|
10000
10873
|
|
|
10001
10874
|
/**
|
|
10002
|
-
* Generate a unique id compatible with HTML element id
|
|
10875
|
+
* Generate a unique id compatible with HTML element id.
|
|
10876
|
+
* Uses the Web Crypto API for cryptographically strong randomness, with a
|
|
10877
|
+
* deterministic fallback only when crypto is unavailable.
|
|
10003
10878
|
*/
|
|
10004
10879
|
function getUniqueId() {
|
|
10005
|
-
|
|
10880
|
+
var letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
10881
|
+
var length = 10;
|
|
10882
|
+
var bytes = new Uint8Array(length);
|
|
10883
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
10884
|
+
crypto.getRandomValues(bytes);
|
|
10885
|
+
} else {
|
|
10886
|
+
for (var i = 0; i < length; i++) {
|
|
10887
|
+
bytes[i] = (i * 31 + 7) % 256;
|
|
10888
|
+
}
|
|
10889
|
+
}
|
|
10890
|
+
var id = '';
|
|
10891
|
+
for (var _i = 0; _i < length; _i++) {
|
|
10892
|
+
id += letters[bytes[_i] % letters.length];
|
|
10893
|
+
}
|
|
10894
|
+
return id;
|
|
10006
10895
|
}
|
|
10007
10896
|
|
|
10008
10897
|
function getFlypayV2Button(widgetId) {
|
|
@@ -19134,6 +20023,90 @@ var EVENT$1;
|
|
|
19134
20023
|
EVENT["ON_SHIPPING_OPTIONS_CHANGE"] = "onShippingOptionsChange";
|
|
19135
20024
|
})(EVENT$1 || (EVENT$1 = {}));
|
|
19136
20025
|
|
|
20026
|
+
/** TTL for a cached service configuration: 1 day, in milliseconds. */
|
|
20027
|
+
var CACHE_TTL_MS = 86400000;
|
|
20028
|
+
/** Builds the `localStorage` key used to cache a service's configuration. */
|
|
20029
|
+
function serviceConfigStorageKey(serviceId) {
|
|
20030
|
+
return "paydock-serviceConfig-".concat(serviceId);
|
|
20031
|
+
}
|
|
20032
|
+
/**
|
|
20033
|
+
* Removes the cached service configuration for the given service ID, forcing the next
|
|
20034
|
+
* fetch to go to the network. Called on error / unavailable flows so a potentially
|
|
20035
|
+
* stale cached config is not reused after something changed server-side. No-throw when
|
|
20036
|
+
* `localStorage` is unavailable.
|
|
20037
|
+
*
|
|
20038
|
+
* @param serviceId - The service ID whose cached configuration should be cleared.
|
|
20039
|
+
*/
|
|
20040
|
+
function clearServiceConfigCache(serviceId) {
|
|
20041
|
+
try {
|
|
20042
|
+
localStorage.removeItem(serviceConfigStorageKey(serviceId));
|
|
20043
|
+
} catch (_error) {
|
|
20044
|
+
// localStorage may be unavailable; nothing to clear
|
|
20045
|
+
}
|
|
20046
|
+
}
|
|
20047
|
+
/**
|
|
20048
|
+
* Fetches the wallet service configuration, backed by a 1-day `localStorage` cache
|
|
20049
|
+
* keyed on the service ID. Falls back gracefully (no caching) when `localStorage`
|
|
20050
|
+
* is unavailable (e.g. private browsing). Shared by the instance `load()` flow and
|
|
20051
|
+
* the static availability checks so both reuse the same cached fetch.
|
|
20052
|
+
*
|
|
20053
|
+
* @param api - The configured API client (env must already be set).
|
|
20054
|
+
* @param serviceId - The service ID to fetch the configuration for.
|
|
20055
|
+
* @returns The service configuration response.
|
|
20056
|
+
*/
|
|
20057
|
+
function getServiceConfigCached(api, serviceId) {
|
|
20058
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
20059
|
+
var storageKey, cachedData, _JSON$parse, data, timestamp, serviceConfigResponse, encodedData;
|
|
20060
|
+
return _regenerator().w(function (_context) {
|
|
20061
|
+
while (1) switch (_context.p = _context.n) {
|
|
20062
|
+
case 0:
|
|
20063
|
+
storageKey = serviceConfigStorageKey(serviceId);
|
|
20064
|
+
_context.p = 1;
|
|
20065
|
+
cachedData = localStorage.getItem(storageKey);
|
|
20066
|
+
if (!cachedData) {
|
|
20067
|
+
_context.n = 5;
|
|
20068
|
+
break;
|
|
20069
|
+
}
|
|
20070
|
+
_context.p = 2;
|
|
20071
|
+
_JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
|
|
20072
|
+
if (!(Date.now() - timestamp < CACHE_TTL_MS)) {
|
|
20073
|
+
_context.n = 3;
|
|
20074
|
+
break;
|
|
20075
|
+
}
|
|
20076
|
+
return _context.a(2, JSON.parse(data));
|
|
20077
|
+
case 3:
|
|
20078
|
+
_context.n = 5;
|
|
20079
|
+
break;
|
|
20080
|
+
case 4:
|
|
20081
|
+
_context.p = 4;
|
|
20082
|
+
_context.v;
|
|
20083
|
+
localStorage.removeItem(storageKey);
|
|
20084
|
+
case 5:
|
|
20085
|
+
_context.n = 7;
|
|
20086
|
+
break;
|
|
20087
|
+
case 6:
|
|
20088
|
+
_context.p = 6;
|
|
20089
|
+
_context.v;
|
|
20090
|
+
case 7:
|
|
20091
|
+
_context.n = 8;
|
|
20092
|
+
return api.service().getConfig(serviceId);
|
|
20093
|
+
case 8:
|
|
20094
|
+
serviceConfigResponse = _context.v;
|
|
20095
|
+
try {
|
|
20096
|
+
encodedData = btoa(JSON.stringify({
|
|
20097
|
+
data: JSON.stringify(serviceConfigResponse),
|
|
20098
|
+
timestamp: Date.now()
|
|
20099
|
+
}));
|
|
20100
|
+
localStorage.setItem(storageKey, encodedData);
|
|
20101
|
+
} catch (_error) {
|
|
20102
|
+
// localStorage may be unavailable; proceed without caching
|
|
20103
|
+
}
|
|
20104
|
+
return _context.a(2, serviceConfigResponse);
|
|
20105
|
+
}
|
|
20106
|
+
}, _callee, null, [[2, 4], [1, 6]]);
|
|
20107
|
+
}));
|
|
20108
|
+
}
|
|
20109
|
+
|
|
19137
20110
|
/**
|
|
19138
20111
|
* @classdesc Abstract base class for Open Wallet buttons. **Do not instantiate directly.**
|
|
19139
20112
|
* Use {@link ApplePayOpenWalletButton} or {@link GooglePayOpenWalletButton} instead.
|
|
@@ -19167,10 +20140,30 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19167
20140
|
this.api = new ApiInternal(publicKeyOrAccessToken, this.getApiAuthType(publicKeyOrAccessToken));
|
|
19168
20141
|
this.serviceId = serviceId;
|
|
19169
20142
|
this.meta = meta;
|
|
20143
|
+
this.registerCacheInvalidationOnError();
|
|
19170
20144
|
this.validateBaseMeta();
|
|
19171
20145
|
this.validateWalletMeta();
|
|
19172
20146
|
}
|
|
20147
|
+
/**
|
|
20148
|
+
* Invalidates the cached service configuration whenever an error or unavailable
|
|
20149
|
+
* event fires, so the next `load()` re-fetches a fresh config. The cache is keyed
|
|
20150
|
+
* on the service ID with a 1-day TTL; clearing it on failure means a config that
|
|
20151
|
+
* changed server-side (and caused the failure) is not reused until the TTL expires.
|
|
20152
|
+
* Registered once per button, independently of any merchant-registered handlers.
|
|
20153
|
+
*
|
|
20154
|
+
* @private
|
|
20155
|
+
*/
|
|
19173
20156
|
return _createClass(OpenWalletButtons, [{
|
|
20157
|
+
key: "registerCacheInvalidationOnError",
|
|
20158
|
+
value: function registerCacheInvalidationOnError() {
|
|
20159
|
+
var _this = this;
|
|
20160
|
+
var invalidate = function invalidate() {
|
|
20161
|
+
return clearServiceConfigCache(_this.serviceId);
|
|
20162
|
+
};
|
|
20163
|
+
this.eventEmitter.subscribe(EVENT$1.ERROR, invalidate);
|
|
20164
|
+
this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, invalidate);
|
|
20165
|
+
}
|
|
20166
|
+
}, {
|
|
19174
20167
|
key: "getApiAuthType",
|
|
19175
20168
|
value: function getApiAuthType(publicKeyOrAccessToken) {
|
|
19176
20169
|
if (AccessToken.validateJWT(publicKeyOrAccessToken)) {
|
|
@@ -19204,57 +20197,7 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19204
20197
|
}, {
|
|
19205
20198
|
key: "getOpenWalletServiceConfig",
|
|
19206
20199
|
value: function getOpenWalletServiceConfig() {
|
|
19207
|
-
return
|
|
19208
|
-
var storageKey, cachedData, _JSON$parse, data, timestamp, oneDay, serviceConfigResponse, encodedData;
|
|
19209
|
-
return _regenerator().w(function (_context) {
|
|
19210
|
-
while (1) switch (_context.p = _context.n) {
|
|
19211
|
-
case 0:
|
|
19212
|
-
storageKey = "serviceConfig-".concat(this.serviceId);
|
|
19213
|
-
_context.p = 1;
|
|
19214
|
-
cachedData = localStorage.getItem(storageKey);
|
|
19215
|
-
if (!cachedData) {
|
|
19216
|
-
_context.n = 5;
|
|
19217
|
-
break;
|
|
19218
|
-
}
|
|
19219
|
-
_context.p = 2;
|
|
19220
|
-
_JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
|
|
19221
|
-
oneDay = 86400000;
|
|
19222
|
-
if (!(Date.now() - timestamp < oneDay)) {
|
|
19223
|
-
_context.n = 3;
|
|
19224
|
-
break;
|
|
19225
|
-
}
|
|
19226
|
-
return _context.a(2, JSON.parse(data));
|
|
19227
|
-
case 3:
|
|
19228
|
-
_context.n = 5;
|
|
19229
|
-
break;
|
|
19230
|
-
case 4:
|
|
19231
|
-
_context.p = 4;
|
|
19232
|
-
_context.v;
|
|
19233
|
-
localStorage.removeItem(storageKey);
|
|
19234
|
-
case 5:
|
|
19235
|
-
_context.n = 7;
|
|
19236
|
-
break;
|
|
19237
|
-
case 6:
|
|
19238
|
-
_context.p = 6;
|
|
19239
|
-
_context.v;
|
|
19240
|
-
case 7:
|
|
19241
|
-
_context.n = 8;
|
|
19242
|
-
return this.api.service().getConfig(this.serviceId);
|
|
19243
|
-
case 8:
|
|
19244
|
-
serviceConfigResponse = _context.v;
|
|
19245
|
-
try {
|
|
19246
|
-
encodedData = btoa(JSON.stringify({
|
|
19247
|
-
data: JSON.stringify(serviceConfigResponse),
|
|
19248
|
-
timestamp: Date.now()
|
|
19249
|
-
}));
|
|
19250
|
-
localStorage.setItem(storageKey, encodedData);
|
|
19251
|
-
} catch (_error) {
|
|
19252
|
-
// localStorage may be unavailable; proceed without caching
|
|
19253
|
-
}
|
|
19254
|
-
return _context.a(2, serviceConfigResponse);
|
|
19255
|
-
}
|
|
19256
|
-
}, _callee, this, [[2, 4], [1, 6]]);
|
|
19257
|
-
}));
|
|
20200
|
+
return getServiceConfigCached(this.api, this.serviceId);
|
|
19258
20201
|
}
|
|
19259
20202
|
}, {
|
|
19260
20203
|
key: "handleOnError",
|
|
@@ -19289,13 +20232,13 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19289
20232
|
}, {
|
|
19290
20233
|
key: "load",
|
|
19291
20234
|
value: function load() {
|
|
19292
|
-
var
|
|
20235
|
+
var _this2 = this;
|
|
19293
20236
|
this.getOpenWalletServiceConfig().then(function (serviceConfig) {
|
|
19294
|
-
|
|
19295
|
-
|
|
19296
|
-
|
|
20237
|
+
_this2.validateServiceType(serviceConfig);
|
|
20238
|
+
_this2.walletService = _this2.createWalletService(serviceConfig);
|
|
20239
|
+
_this2.walletService.load();
|
|
19297
20240
|
})["catch"](function (error) {
|
|
19298
|
-
|
|
20241
|
+
_this2.handleOnError(error instanceof Error ? error : new Error(String(error)), exports.ERROR_OPERATION.CONFIGURATION);
|
|
19299
20242
|
});
|
|
19300
20243
|
}
|
|
19301
20244
|
/**
|
|
@@ -19493,28 +20436,28 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19493
20436
|
}, {
|
|
19494
20437
|
key: "onSuccess",
|
|
19495
20438
|
value: function onSuccess(handler) {
|
|
19496
|
-
var
|
|
20439
|
+
var _this3 = this;
|
|
19497
20440
|
if (typeof handler === 'function') {
|
|
19498
20441
|
this.eventEmitter.subscribe(EVENT$1.SUCCESS, function (data) {
|
|
19499
|
-
return __awaiter(
|
|
19500
|
-
var
|
|
19501
|
-
return _regenerator().w(function (
|
|
19502
|
-
while (1) switch (
|
|
20442
|
+
return __awaiter(_this3, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
20443
|
+
var _t;
|
|
20444
|
+
return _regenerator().w(function (_context) {
|
|
20445
|
+
while (1) switch (_context.p = _context.n) {
|
|
19503
20446
|
case 0:
|
|
19504
|
-
|
|
19505
|
-
|
|
20447
|
+
_context.p = 0;
|
|
20448
|
+
_context.n = 1;
|
|
19506
20449
|
return handler(data);
|
|
19507
20450
|
case 1:
|
|
19508
|
-
|
|
20451
|
+
_context.n = 3;
|
|
19509
20452
|
break;
|
|
19510
20453
|
case 2:
|
|
19511
|
-
|
|
19512
|
-
|
|
19513
|
-
console.warn('Merchant onSuccess handler threw (swallowed):',
|
|
20454
|
+
_context.p = 2;
|
|
20455
|
+
_t = _context.v;
|
|
20456
|
+
console.warn('Merchant onSuccess handler threw (swallowed):', _t);
|
|
19514
20457
|
case 3:
|
|
19515
|
-
return
|
|
20458
|
+
return _context.a(2);
|
|
19516
20459
|
}
|
|
19517
|
-
},
|
|
20460
|
+
}, _callee, null, [[0, 2]]);
|
|
19518
20461
|
}));
|
|
19519
20462
|
});
|
|
19520
20463
|
return;
|
|
@@ -19545,28 +20488,28 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19545
20488
|
}, {
|
|
19546
20489
|
key: "onUnavailable",
|
|
19547
20490
|
value: function onUnavailable(handler) {
|
|
19548
|
-
var
|
|
20491
|
+
var _this4 = this;
|
|
19549
20492
|
if (typeof handler === 'function') {
|
|
19550
20493
|
this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, function (data) {
|
|
19551
|
-
return __awaiter(
|
|
19552
|
-
var
|
|
19553
|
-
return _regenerator().w(function (
|
|
19554
|
-
while (1) switch (
|
|
20494
|
+
return __awaiter(_this4, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
20495
|
+
var _t2;
|
|
20496
|
+
return _regenerator().w(function (_context2) {
|
|
20497
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
19555
20498
|
case 0:
|
|
19556
|
-
|
|
19557
|
-
|
|
20499
|
+
_context2.p = 0;
|
|
20500
|
+
_context2.n = 1;
|
|
19558
20501
|
return handler(data);
|
|
19559
20502
|
case 1:
|
|
19560
|
-
|
|
20503
|
+
_context2.n = 3;
|
|
19561
20504
|
break;
|
|
19562
20505
|
case 2:
|
|
19563
|
-
|
|
19564
|
-
|
|
19565
|
-
console.warn('Merchant onUnavailable handler threw (swallowed):',
|
|
20506
|
+
_context2.p = 2;
|
|
20507
|
+
_t2 = _context2.v;
|
|
20508
|
+
console.warn('Merchant onUnavailable handler threw (swallowed):', _t2);
|
|
19566
20509
|
case 3:
|
|
19567
|
-
return
|
|
20510
|
+
return _context2.a(2);
|
|
19568
20511
|
}
|
|
19569
|
-
},
|
|
20512
|
+
}, _callee2, null, [[0, 2]]);
|
|
19570
20513
|
}));
|
|
19571
20514
|
});
|
|
19572
20515
|
return;
|
|
@@ -19598,28 +20541,28 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19598
20541
|
}, {
|
|
19599
20542
|
key: "onError",
|
|
19600
20543
|
value: function onError(handler) {
|
|
19601
|
-
var
|
|
20544
|
+
var _this5 = this;
|
|
19602
20545
|
if (typeof handler === 'function') {
|
|
19603
20546
|
this.eventEmitter.subscribe(EVENT$1.ERROR, function (data) {
|
|
19604
|
-
return __awaiter(
|
|
19605
|
-
var
|
|
19606
|
-
return _regenerator().w(function (
|
|
19607
|
-
while (1) switch (
|
|
20547
|
+
return __awaiter(_this5, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
20548
|
+
var _t3;
|
|
20549
|
+
return _regenerator().w(function (_context3) {
|
|
20550
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
19608
20551
|
case 0:
|
|
19609
|
-
|
|
19610
|
-
|
|
20552
|
+
_context3.p = 0;
|
|
20553
|
+
_context3.n = 1;
|
|
19611
20554
|
return handler(data);
|
|
19612
20555
|
case 1:
|
|
19613
|
-
|
|
20556
|
+
_context3.n = 3;
|
|
19614
20557
|
break;
|
|
19615
20558
|
case 2:
|
|
19616
|
-
|
|
19617
|
-
|
|
19618
|
-
console.warn('Merchant onError handler threw (swallowed):',
|
|
20559
|
+
_context3.p = 2;
|
|
20560
|
+
_t3 = _context3.v;
|
|
20561
|
+
console.warn('Merchant onError handler threw (swallowed):', _t3);
|
|
19619
20562
|
case 3:
|
|
19620
|
-
return
|
|
20563
|
+
return _context3.a(2);
|
|
19621
20564
|
}
|
|
19622
|
-
},
|
|
20565
|
+
}, _callee3, null, [[0, 2]]);
|
|
19623
20566
|
}));
|
|
19624
20567
|
});
|
|
19625
20568
|
return;
|
|
@@ -19650,28 +20593,28 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19650
20593
|
}, {
|
|
19651
20594
|
key: "onCancel",
|
|
19652
20595
|
value: function onCancel(handler) {
|
|
19653
|
-
var
|
|
20596
|
+
var _this6 = this;
|
|
19654
20597
|
if (typeof handler === 'function') {
|
|
19655
20598
|
this.eventEmitter.subscribe(EVENT$1.CHECKOUT_CLOSE, function (data) {
|
|
19656
|
-
return __awaiter(
|
|
19657
|
-
var
|
|
19658
|
-
return _regenerator().w(function (
|
|
19659
|
-
while (1) switch (
|
|
20599
|
+
return __awaiter(_this6, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
20600
|
+
var _t4;
|
|
20601
|
+
return _regenerator().w(function (_context4) {
|
|
20602
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
19660
20603
|
case 0:
|
|
19661
|
-
|
|
19662
|
-
|
|
20604
|
+
_context4.p = 0;
|
|
20605
|
+
_context4.n = 1;
|
|
19663
20606
|
return handler(data);
|
|
19664
20607
|
case 1:
|
|
19665
|
-
|
|
20608
|
+
_context4.n = 3;
|
|
19666
20609
|
break;
|
|
19667
20610
|
case 2:
|
|
19668
|
-
|
|
19669
|
-
|
|
19670
|
-
console.warn('Merchant onCancel handler threw (swallowed):',
|
|
20611
|
+
_context4.p = 2;
|
|
20612
|
+
_t4 = _context4.v;
|
|
20613
|
+
console.warn('Merchant onCancel handler threw (swallowed):', _t4);
|
|
19671
20614
|
case 3:
|
|
19672
|
-
return
|
|
20615
|
+
return _context4.a(2);
|
|
19673
20616
|
}
|
|
19674
|
-
},
|
|
20617
|
+
}, _callee4, null, [[0, 2]]);
|
|
19675
20618
|
}));
|
|
19676
20619
|
});
|
|
19677
20620
|
return;
|
|
@@ -19695,28 +20638,28 @@ var OpenWalletButtons = /*#__PURE__*/function () {
|
|
|
19695
20638
|
}, {
|
|
19696
20639
|
key: "onLoaded",
|
|
19697
20640
|
value: function onLoaded(handler) {
|
|
19698
|
-
var
|
|
20641
|
+
var _this7 = this;
|
|
19699
20642
|
if (typeof handler === 'function') {
|
|
19700
20643
|
this.eventEmitter.subscribe(EVENT$1.LOADED, function (data) {
|
|
19701
|
-
return __awaiter(
|
|
19702
|
-
var
|
|
19703
|
-
return _regenerator().w(function (
|
|
19704
|
-
while (1) switch (
|
|
20644
|
+
return __awaiter(_this7, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
20645
|
+
var _t5;
|
|
20646
|
+
return _regenerator().w(function (_context5) {
|
|
20647
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
19705
20648
|
case 0:
|
|
19706
|
-
|
|
19707
|
-
|
|
20649
|
+
_context5.p = 0;
|
|
20650
|
+
_context5.n = 1;
|
|
19708
20651
|
return handler(data);
|
|
19709
20652
|
case 1:
|
|
19710
|
-
|
|
20653
|
+
_context5.n = 3;
|
|
19711
20654
|
break;
|
|
19712
20655
|
case 2:
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
console.warn('Merchant onLoaded handler threw (swallowed):',
|
|
20656
|
+
_context5.p = 2;
|
|
20657
|
+
_t5 = _context5.v;
|
|
20658
|
+
console.warn('Merchant onLoaded handler threw (swallowed):', _t5);
|
|
19716
20659
|
case 3:
|
|
19717
|
-
return
|
|
20660
|
+
return _context5.a(2);
|
|
19718
20661
|
}
|
|
19719
|
-
},
|
|
20662
|
+
}, _callee5, null, [[0, 2]]);
|
|
19720
20663
|
}));
|
|
19721
20664
|
});
|
|
19722
20665
|
return;
|
|
@@ -20064,7 +21007,143 @@ exports.WALLET_TYPES = void 0;
|
|
|
20064
21007
|
WALLET_TYPES["GOOGLE_PAY"] = "google";
|
|
20065
21008
|
})(exports.WALLET_TYPES || (exports.WALLET_TYPES = {}));
|
|
20066
21009
|
|
|
20067
|
-
|
|
21010
|
+
/** CDN location of Apple's web SDK (provides the `<apple-pay-button>` web component). */
|
|
21011
|
+
var APPLE_PAY_SDK_URL = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
21012
|
+
/**
|
|
21013
|
+
* Statuses that count as available when the merchant does not override them.
|
|
21014
|
+
* Includes `paymentCredentialStatusUnknown` so the button is shown in third-party /
|
|
21015
|
+
* cross-device (QR) browsers, per Apple's guidance.
|
|
21016
|
+
*/
|
|
21017
|
+
var DEFAULT_APPLE_PAY_CAPABILITIES$1 = ['paymentCredentialsAvailable', 'paymentCredentialStatusUnknown'];
|
|
21018
|
+
/**
|
|
21019
|
+
* Maps the SDK's friendly capability tokens to Apple's `PaymentCredentialStatus` values.
|
|
21020
|
+
* Unknown tokens are passed through unchanged.
|
|
21021
|
+
*/
|
|
21022
|
+
function formatCapabilities(capabilities) {
|
|
21023
|
+
var fieldMap = {
|
|
21024
|
+
credentials_available: 'paymentCredentialsAvailable',
|
|
21025
|
+
credentials_status_unknown: 'paymentCredentialStatusUnknown',
|
|
21026
|
+
credentials_unavailable: 'paymentCredentialsUnavailable'
|
|
21027
|
+
};
|
|
21028
|
+
return capabilities.map(function (capability) {
|
|
21029
|
+
return fieldMap[capability] || capability;
|
|
21030
|
+
});
|
|
21031
|
+
}
|
|
21032
|
+
/**
|
|
21033
|
+
* Synchronous, network-free check for a **native, same-device** Apple Pay session
|
|
21034
|
+
* (`window.ApplePaySession` exists and `canMakePayments()` is `true`). Safe to call in
|
|
21035
|
+
* any environment (never throws).
|
|
21036
|
+
*
|
|
21037
|
+
* Note: this is a legacy/Safari-oriented signal. It is **not** authoritative for
|
|
21038
|
+
* cross-browser / cross-device (QR) availability — in Chrome/Edge/Firefox
|
|
21039
|
+
* `window.ApplePaySession` is supplied by the CDN SDK and may be absent until it loads,
|
|
21040
|
+
* and the cross-device flow is reflected by `applePayCapabilities()`, not this call.
|
|
21041
|
+
* Use {@link evaluateApplePayAvailability} for the authoritative, cross-browser answer.
|
|
21042
|
+
*/
|
|
21043
|
+
function hasNativeApplePaySession() {
|
|
21044
|
+
try {
|
|
21045
|
+
return typeof window !== 'undefined' && !!window.ApplePaySession && typeof ApplePaySession !== 'undefined' && ApplePaySession.canMakePayments();
|
|
21046
|
+
} catch (_a) {
|
|
21047
|
+
return false;
|
|
21048
|
+
}
|
|
21049
|
+
}
|
|
21050
|
+
var sdkLoadPromise = null;
|
|
21051
|
+
/**
|
|
21052
|
+
* Idempotently loads Apple's web SDK from the CDN.
|
|
21053
|
+
* Resolves immediately if the `<apple-pay-button>` custom element is already
|
|
21054
|
+
* registered, and de-duplicates concurrent loads. Rejects if the script fails to load.
|
|
21055
|
+
*/
|
|
21056
|
+
function loadApplePaySdk() {
|
|
21057
|
+
if (typeof customElements !== 'undefined' && customElements.get('apple-pay-button')) {
|
|
21058
|
+
return Promise.resolve();
|
|
21059
|
+
}
|
|
21060
|
+
if (sdkLoadPromise) {
|
|
21061
|
+
return sdkLoadPromise;
|
|
21062
|
+
}
|
|
21063
|
+
sdkLoadPromise = new Promise(function (resolve, reject) {
|
|
21064
|
+
var script = document.createElement('script');
|
|
21065
|
+
script.src = APPLE_PAY_SDK_URL;
|
|
21066
|
+
script.type = 'text/javascript';
|
|
21067
|
+
script.crossOrigin = 'anonymous';
|
|
21068
|
+
script.onload = function () {
|
|
21069
|
+
return resolve();
|
|
21070
|
+
};
|
|
21071
|
+
script.onerror = function () {
|
|
21072
|
+
// Allow a future retry after a transient failure.
|
|
21073
|
+
sdkLoadPromise = null;
|
|
21074
|
+
reject(new Error('Failed to load Apple Pay script'));
|
|
21075
|
+
};
|
|
21076
|
+
document.head.appendChild(script);
|
|
21077
|
+
});
|
|
21078
|
+
return sdkLoadPromise;
|
|
21079
|
+
}
|
|
21080
|
+
/**
|
|
21081
|
+
* Core Apple Pay availability evaluation, shared by the instance flow
|
|
21082
|
+
* (`ApplePayOpenWalletService`) and the static `ApplePayOpenWalletButton.checkAvailability`.
|
|
21083
|
+
*
|
|
21084
|
+
* Assumes the Apple Pay SDK is already loaded (call {@link loadApplePaySdk} first).
|
|
21085
|
+
*/
|
|
21086
|
+
function evaluateApplePayAvailability(params) {
|
|
21087
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
21088
|
+
var _a, hasNativeSession, allowed, capabilities, paymentCredentialStatus, available;
|
|
21089
|
+
return _regenerator().w(function (_context) {
|
|
21090
|
+
while (1) switch (_context.p = _context.n) {
|
|
21091
|
+
case 0:
|
|
21092
|
+
if (!(typeof window === 'undefined' || !window.ApplePaySession)) {
|
|
21093
|
+
_context.n = 1;
|
|
21094
|
+
break;
|
|
21095
|
+
}
|
|
21096
|
+
return _context.a(2, {
|
|
21097
|
+
available: false,
|
|
21098
|
+
supported: false,
|
|
21099
|
+
has_native_session: false,
|
|
21100
|
+
reason: 'unsupported_browser'
|
|
21101
|
+
});
|
|
21102
|
+
case 1:
|
|
21103
|
+
hasNativeSession = hasNativeApplePaySession();
|
|
21104
|
+
allowed = ((_a = params.apple_pay_capabilities) === null || _a === void 0 ? void 0 : _a.length) ? formatCapabilities(params.apple_pay_capabilities) : DEFAULT_APPLE_PAY_CAPABILITIES$1;
|
|
21105
|
+
_context.p = 2;
|
|
21106
|
+
_context.n = 3;
|
|
21107
|
+
return ApplePaySession.applePayCapabilities(params.merchantId);
|
|
21108
|
+
case 3:
|
|
21109
|
+
capabilities = _context.v;
|
|
21110
|
+
paymentCredentialStatus = capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus; // `applePayCapabilities` is authoritative: trust an explicit `applePayUnsupported`
|
|
21111
|
+
// (e.g. an unregistered/misconfigured merchant) rather than overriding it with the
|
|
21112
|
+
// coarse `canMakePayments()` signal.
|
|
21113
|
+
if (!(paymentCredentialStatus === 'applePayUnsupported')) {
|
|
21114
|
+
_context.n = 4;
|
|
21115
|
+
break;
|
|
21116
|
+
}
|
|
21117
|
+
return _context.a(2, {
|
|
21118
|
+
available: false,
|
|
21119
|
+
supported: false,
|
|
21120
|
+
has_native_session: hasNativeSession,
|
|
21121
|
+
payment_credential_status: paymentCredentialStatus,
|
|
21122
|
+
reason: 'unsupported_browser'
|
|
21123
|
+
});
|
|
21124
|
+
case 4:
|
|
21125
|
+
available = allowed.includes(paymentCredentialStatus);
|
|
21126
|
+
return _context.a(2, {
|
|
21127
|
+
available: available,
|
|
21128
|
+
supported: true,
|
|
21129
|
+
has_native_session: hasNativeSession,
|
|
21130
|
+
payment_credential_status: paymentCredentialStatus,
|
|
21131
|
+
reason: available ? undefined : 'no_credentials'
|
|
21132
|
+
});
|
|
21133
|
+
case 5:
|
|
21134
|
+
_context.p = 5;
|
|
21135
|
+
_context.v;
|
|
21136
|
+
return _context.a(2, {
|
|
21137
|
+
available: false,
|
|
21138
|
+
supported: hasNativeSession,
|
|
21139
|
+
has_native_session: hasNativeSession,
|
|
21140
|
+
reason: 'query_failed'
|
|
21141
|
+
});
|
|
21142
|
+
}
|
|
21143
|
+
}, _callee, null, [[2, 5]]);
|
|
21144
|
+
}));
|
|
21145
|
+
}
|
|
21146
|
+
|
|
20068
21147
|
/**
|
|
20069
21148
|
* Apple Pay implementation of the OpenWallet service.
|
|
20070
21149
|
*
|
|
@@ -20340,7 +21419,6 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20340
21419
|
value: function load() {
|
|
20341
21420
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
20342
21421
|
var _this4 = this;
|
|
20343
|
-
var applePayScript;
|
|
20344
21422
|
return _regenerator().w(function (_context3) {
|
|
20345
21423
|
while (1) switch (_context3.n) {
|
|
20346
21424
|
case 0:
|
|
@@ -20351,26 +21429,12 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20351
21429
|
this.handleOnUnavailable('Promises not supported');
|
|
20352
21430
|
return _context3.a(2);
|
|
20353
21431
|
case 1:
|
|
20354
|
-
|
|
20355
|
-
_context3.n = 2;
|
|
20356
|
-
break;
|
|
20357
|
-
}
|
|
20358
|
-
this.onScriptLoaded();
|
|
20359
|
-
return _context3.a(2);
|
|
20360
|
-
case 2:
|
|
20361
|
-
applePayScript = document.createElement('script');
|
|
20362
|
-
applePayScript.src = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
20363
|
-
applePayScript.type = 'text/javascript';
|
|
20364
|
-
applePayScript.crossOrigin = 'anonymous';
|
|
20365
|
-
applePayScript.onload = function () {
|
|
21432
|
+
loadApplePaySdk().then(function () {
|
|
20366
21433
|
_this4.onScriptLoaded();
|
|
20367
|
-
}
|
|
20368
|
-
applePayScript.onerror = function () {
|
|
21434
|
+
})["catch"](function () {
|
|
20369
21435
|
_this4.handleOnUnavailable('Failed to load Apple Pay script');
|
|
20370
|
-
|
|
20371
|
-
|
|
20372
|
-
document.head.appendChild(applePayScript);
|
|
20373
|
-
case 3:
|
|
21436
|
+
});
|
|
21437
|
+
case 2:
|
|
20374
21438
|
return _context3.a(2);
|
|
20375
21439
|
}
|
|
20376
21440
|
}, _callee3, this);
|
|
@@ -20398,26 +21462,22 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20398
21462
|
}, {
|
|
20399
21463
|
key: "checkAvailability",
|
|
20400
21464
|
value: function checkAvailability() {
|
|
20401
|
-
|
|
20402
|
-
|
|
20403
|
-
|
|
20404
|
-
|
|
20405
|
-
|
|
20406
|
-
|
|
20407
|
-
|
|
20408
|
-
|
|
20409
|
-
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
21465
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
21466
|
+
var result;
|
|
21467
|
+
return _regenerator().w(function (_context4) {
|
|
21468
|
+
while (1) switch (_context4.n) {
|
|
21469
|
+
case 0:
|
|
21470
|
+
_context4.n = 1;
|
|
21471
|
+
return evaluateApplePayAvailability({
|
|
21472
|
+
merchantId: this.getMerchantId(),
|
|
21473
|
+
apple_pay_capabilities: this.meta.apple_pay_capabilities
|
|
21474
|
+
});
|
|
21475
|
+
case 1:
|
|
21476
|
+
result = _context4.v;
|
|
21477
|
+
return _context4.a(2, result.available);
|
|
20414
21478
|
}
|
|
20415
|
-
|
|
20416
|
-
|
|
20417
|
-
})["catch"](function () {
|
|
20418
|
-
resolve(false);
|
|
20419
|
-
});
|
|
20420
|
-
});
|
|
21479
|
+
}, _callee4, this);
|
|
21480
|
+
}));
|
|
20421
21481
|
}
|
|
20422
21482
|
}, {
|
|
20423
21483
|
key: "mount",
|
|
@@ -20443,7 +21503,7 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20443
21503
|
}, {
|
|
20444
21504
|
key: "onApplePayButtonClicked",
|
|
20445
21505
|
value: function onApplePayButtonClicked() {
|
|
20446
|
-
var
|
|
21506
|
+
var _this6 = this;
|
|
20447
21507
|
if (this.isButtonDisabled()) {
|
|
20448
21508
|
return;
|
|
20449
21509
|
}
|
|
@@ -20462,26 +21522,27 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20462
21522
|
// As part of PAYCA-2065 we detect that the paymentSession.onvalidatemerchant is not
|
|
20463
21523
|
// executed if the browser is not safari. In that case, we handle it outside the
|
|
20464
21524
|
// actual merchant validation function.
|
|
20465
|
-
var
|
|
20466
|
-
var
|
|
21525
|
+
var userAgent = navigator.userAgent || '';
|
|
21526
|
+
var isIOS = userAgent.includes('iPhone') || userAgent.includes('iPad') || userAgent.includes('iPod');
|
|
21527
|
+
var isDesktopRequestIOS = navigator.maxTouchPoints > 1 && userAgent.includes('Macintosh');
|
|
20467
21528
|
if (!window.safari && !isIOS && !isDesktopRequestIOS) {
|
|
20468
21529
|
this.handleMerchantOnButtonClickEvent()["catch"](function (err) {
|
|
20469
21530
|
console.error('Error while processing merchant callback', err);
|
|
20470
|
-
|
|
21531
|
+
_this6.paymentSession.abort();
|
|
20471
21532
|
});
|
|
20472
21533
|
}
|
|
20473
21534
|
}
|
|
20474
21535
|
}, {
|
|
20475
21536
|
key: "getMerchantSession",
|
|
20476
21537
|
value: function getMerchantSession() {
|
|
20477
|
-
var
|
|
21538
|
+
var _this7 = this;
|
|
20478
21539
|
return new Promise(function (resolve, reject) {
|
|
20479
|
-
return
|
|
20480
|
-
service_id:
|
|
21540
|
+
return _this7.api.paymentSource().createSession(_extends({
|
|
21541
|
+
service_id: _this7.serviceId,
|
|
20481
21542
|
session_id: window.location.hostname,
|
|
20482
|
-
store_name:
|
|
20483
|
-
},
|
|
20484
|
-
request_shipping:
|
|
21543
|
+
store_name: _this7.meta.store_name
|
|
21544
|
+
}, _this7.isShippingRequired() && {
|
|
21545
|
+
request_shipping: _this7.meta.request_shipping
|
|
20485
21546
|
})).then(function (res) {
|
|
20486
21547
|
resolve(res);
|
|
20487
21548
|
})["catch"](function (err) {
|
|
@@ -20492,42 +21553,30 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20492
21553
|
}, {
|
|
20493
21554
|
key: "handleMerchantOnButtonClickEvent",
|
|
20494
21555
|
value: function handleMerchantOnButtonClickEvent() {
|
|
20495
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function
|
|
21556
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
20496
21557
|
var results;
|
|
20497
|
-
return _regenerator().w(function (
|
|
20498
|
-
while (1) switch (
|
|
21558
|
+
return _regenerator().w(function (_context5) {
|
|
21559
|
+
while (1) switch (_context5.n) {
|
|
20499
21560
|
case 0:
|
|
20500
|
-
|
|
21561
|
+
_context5.n = 1;
|
|
20501
21562
|
return this.eventEmitter.emitWithResult(EVENT$1.ON_CLICK, {
|
|
20502
21563
|
event: EVENT$1.ON_CLICK
|
|
20503
21564
|
});
|
|
20504
21565
|
case 1:
|
|
20505
|
-
results =
|
|
21566
|
+
results = _context5.v;
|
|
20506
21567
|
if (!results.some(function (r) {
|
|
20507
21568
|
return r === false;
|
|
20508
21569
|
})) {
|
|
20509
|
-
|
|
21570
|
+
_context5.n = 2;
|
|
20510
21571
|
break;
|
|
20511
21572
|
}
|
|
20512
21573
|
throw new Error('onClick handler aborted the payment flow');
|
|
20513
21574
|
case 2:
|
|
20514
|
-
return
|
|
21575
|
+
return _context5.a(2);
|
|
20515
21576
|
}
|
|
20516
|
-
},
|
|
21577
|
+
}, _callee5, this);
|
|
20517
21578
|
}));
|
|
20518
21579
|
}
|
|
20519
|
-
}, {
|
|
20520
|
-
key: "formatCapabilities",
|
|
20521
|
-
value: function formatCapabilities(capabilities) {
|
|
20522
|
-
var fieldMap = {
|
|
20523
|
-
credentials_available: 'paymentCredentialsAvailable',
|
|
20524
|
-
credentials_status_unknown: 'paymentCredentialStatusUnknown',
|
|
20525
|
-
credentials_unavailable: 'paymentCredentialsUnavailable'
|
|
20526
|
-
};
|
|
20527
|
-
return capabilities.map(function (capability) {
|
|
20528
|
-
return fieldMap[capability] || capability;
|
|
20529
|
-
});
|
|
20530
|
-
}
|
|
20531
21580
|
}, {
|
|
20532
21581
|
key: "formatErrorFields",
|
|
20533
21582
|
value: function formatErrorFields(error) {
|
|
@@ -20694,11 +21743,6 @@ var ApplePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
20694
21743
|
applePayLaterAvailability: this.meta.apple_pay_later_availability
|
|
20695
21744
|
});
|
|
20696
21745
|
}
|
|
20697
|
-
}, {
|
|
20698
|
-
key: "isUnsuportedBrowser",
|
|
20699
|
-
value: function isUnsuportedBrowser(capabilities) {
|
|
20700
|
-
return (capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus) === 'applePayUnsupported';
|
|
20701
|
-
}
|
|
20702
21746
|
}]);
|
|
20703
21747
|
}(OpenWalletService);
|
|
20704
21748
|
|
|
@@ -20747,17 +21791,57 @@ var ApplePayOpenWalletButton = /*#__PURE__*/function (_OpenWalletButtons) {
|
|
|
20747
21791
|
return _this;
|
|
20748
21792
|
}
|
|
20749
21793
|
/**
|
|
20750
|
-
*
|
|
20751
|
-
*
|
|
21794
|
+
* Checks Apple Pay availability **without instantiating the button** — the single,
|
|
21795
|
+
* authoritative, cross-browser-aware availability entry point.
|
|
20752
21796
|
*
|
|
20753
|
-
*
|
|
20754
|
-
*
|
|
20755
|
-
*
|
|
21797
|
+
* Resolves the merchant identifier (either supplied directly or fetched from the
|
|
21798
|
+
* service configuration), loads Apple's web SDK if needed, then queries
|
|
21799
|
+
* `ApplePaySession.applePayCapabilities()`. Returns a convenience `available` verdict
|
|
21800
|
+
* (computed against `apple_pay_capabilities`), the raw device-reported
|
|
21801
|
+
* `payment_credential_status`, and `has_native_session` so callers can infer the transport:
|
|
21802
|
+
* `available && has_native_session` ⇒ native sheet likely; `available && !has_native_session`
|
|
21803
|
+
* ⇒ cross-device / QR handoff likely.
|
|
21804
|
+
*
|
|
21805
|
+
* Pass `{ sync: true }` for a cheap, network-free native same-device pre-check that
|
|
21806
|
+
* resolves immediately (see {@link ApplePayAvailabilityOptions.sync}).
|
|
21807
|
+
*
|
|
21808
|
+
* @param {ApplePayAvailabilityOptions} [options] - Merchant context, allowed capabilities, and mode.
|
|
21809
|
+
* @returns {Promise<ApplePayAvailabilityResult>} The availability result.
|
|
21810
|
+
*
|
|
21811
|
+
* @example
|
|
21812
|
+
* // Lightest path — no network, when you already know the merchant identifier:
|
|
21813
|
+
* const result = await ApplePayOpenWalletButton.checkAvailability({ merchant_id });
|
|
21814
|
+
*
|
|
21815
|
+
* @example
|
|
21816
|
+
* // Resolve the merchant identifier from the service configuration:
|
|
21817
|
+
* const result = await ApplePayOpenWalletButton.checkAvailability({
|
|
21818
|
+
* public_key_or_access_token,
|
|
21819
|
+
* service_id,
|
|
21820
|
+
* env: 'sandbox',
|
|
21821
|
+
* });
|
|
21822
|
+
* if (result.available) {
|
|
21823
|
+
* // Render the Apple Pay button (native sheet or cross-device QR, per has_native_session).
|
|
21824
|
+
* } else {
|
|
21825
|
+
* console.log('Unavailable:', result.reason, result.payment_credential_status);
|
|
21826
|
+
* }
|
|
21827
|
+
*
|
|
21828
|
+
* @example
|
|
21829
|
+
* // Synchronous native-only fast check (no network / SDK load):
|
|
21830
|
+
* const { has_native_session } = await ApplePayOpenWalletButton.checkAvailability({ sync: true });
|
|
20756
21831
|
*/
|
|
20757
21832
|
_inherits(ApplePayOpenWalletButton, _OpenWalletButtons);
|
|
20758
21833
|
return _createClass(ApplePayOpenWalletButton, [{
|
|
20759
21834
|
key: "validateWalletMeta",
|
|
20760
|
-
value:
|
|
21835
|
+
value:
|
|
21836
|
+
/**
|
|
21837
|
+
* Validates Apple Pay-specific required metadata fields.
|
|
21838
|
+
* Apple Pay requires `amount_label` and `store_name` to be present and strings.
|
|
21839
|
+
*
|
|
21840
|
+
* @private
|
|
21841
|
+
* @throws {Error} If `amount_label` is missing or not a string.
|
|
21842
|
+
* @throws {Error} If `store_name` is missing or not a string.
|
|
21843
|
+
*/
|
|
21844
|
+
function validateWalletMeta() {
|
|
20761
21845
|
if (typeof this.meta.amount_label !== 'string' || this.meta.amount_label.trim() === '') {
|
|
20762
21846
|
throw new Error("meta.amount_label is required for Apple Pay and must be a non-empty string (e.g. 'TOTAL').");
|
|
20763
21847
|
}
|
|
@@ -20791,6 +21875,114 @@ var ApplePayOpenWalletButton = /*#__PURE__*/function (_OpenWalletButtons) {
|
|
|
20791
21875
|
value: function createWalletService(serviceConfig) {
|
|
20792
21876
|
return new ApplePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
|
|
20793
21877
|
}
|
|
21878
|
+
}], [{
|
|
21879
|
+
key: "checkAvailability",
|
|
21880
|
+
value: function checkAvailability() {
|
|
21881
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
21882
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21883
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
21884
|
+
var hasNativeSession, merchantId, authType, api, serviceConfig;
|
|
21885
|
+
return _regenerator().w(function (_context) {
|
|
21886
|
+
while (1) switch (_context.p = _context.n) {
|
|
21887
|
+
case 0:
|
|
21888
|
+
hasNativeSession = hasNativeApplePaySession();
|
|
21889
|
+
if (!options.sync) {
|
|
21890
|
+
_context.n = 1;
|
|
21891
|
+
break;
|
|
21892
|
+
}
|
|
21893
|
+
return _context.a(2, {
|
|
21894
|
+
available: hasNativeSession,
|
|
21895
|
+
supported: hasNativeSession,
|
|
21896
|
+
has_native_session: hasNativeSession,
|
|
21897
|
+
reason: hasNativeSession ? undefined : 'no_native_session'
|
|
21898
|
+
});
|
|
21899
|
+
case 1:
|
|
21900
|
+
merchantId = options.merchant_id;
|
|
21901
|
+
if (merchantId) {
|
|
21902
|
+
_context.n = 6;
|
|
21903
|
+
break;
|
|
21904
|
+
}
|
|
21905
|
+
if (!(!options.public_key_or_access_token || !options.service_id)) {
|
|
21906
|
+
_context.n = 2;
|
|
21907
|
+
break;
|
|
21908
|
+
}
|
|
21909
|
+
return _context.a(2, {
|
|
21910
|
+
available: false,
|
|
21911
|
+
supported: hasNativeSession,
|
|
21912
|
+
has_native_session: hasNativeSession,
|
|
21913
|
+
reason: 'missing_merchant_id'
|
|
21914
|
+
});
|
|
21915
|
+
case 2:
|
|
21916
|
+
_context.p = 2;
|
|
21917
|
+
authType = AccessToken.validateJWT(options.public_key_or_access_token) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
|
|
21918
|
+
api = new ApiInternal(options.public_key_or_access_token, authType);
|
|
21919
|
+
if (options.env) {
|
|
21920
|
+
api.setEnv(options.env);
|
|
21921
|
+
}
|
|
21922
|
+
_context.n = 3;
|
|
21923
|
+
return getServiceConfigCached(api, options.service_id);
|
|
21924
|
+
case 3:
|
|
21925
|
+
serviceConfig = _context.v;
|
|
21926
|
+
if (!(serviceConfig.type !== SERVICE_TYPES.APPLE_PAY)) {
|
|
21927
|
+
_context.n = 4;
|
|
21928
|
+
break;
|
|
21929
|
+
}
|
|
21930
|
+
return _context.a(2, {
|
|
21931
|
+
available: false,
|
|
21932
|
+
supported: hasNativeSession,
|
|
21933
|
+
has_native_session: hasNativeSession,
|
|
21934
|
+
reason: 'service_type_mismatch'
|
|
21935
|
+
});
|
|
21936
|
+
case 4:
|
|
21937
|
+
merchantId = serviceConfig.merchant;
|
|
21938
|
+
_context.n = 6;
|
|
21939
|
+
break;
|
|
21940
|
+
case 5:
|
|
21941
|
+
_context.p = 5;
|
|
21942
|
+
_context.v;
|
|
21943
|
+
return _context.a(2, {
|
|
21944
|
+
available: false,
|
|
21945
|
+
supported: hasNativeSession,
|
|
21946
|
+
has_native_session: hasNativeSession,
|
|
21947
|
+
reason: 'config_fetch_failed'
|
|
21948
|
+
});
|
|
21949
|
+
case 6:
|
|
21950
|
+
if (merchantId) {
|
|
21951
|
+
_context.n = 7;
|
|
21952
|
+
break;
|
|
21953
|
+
}
|
|
21954
|
+
return _context.a(2, {
|
|
21955
|
+
available: false,
|
|
21956
|
+
supported: hasNativeSession,
|
|
21957
|
+
has_native_session: hasNativeSession,
|
|
21958
|
+
reason: 'missing_merchant_id'
|
|
21959
|
+
});
|
|
21960
|
+
case 7:
|
|
21961
|
+
_context.p = 7;
|
|
21962
|
+
_context.n = 8;
|
|
21963
|
+
return loadApplePaySdk();
|
|
21964
|
+
case 8:
|
|
21965
|
+
_context.n = 10;
|
|
21966
|
+
break;
|
|
21967
|
+
case 9:
|
|
21968
|
+
_context.p = 9;
|
|
21969
|
+
_context.v;
|
|
21970
|
+
return _context.a(2, {
|
|
21971
|
+
available: false,
|
|
21972
|
+
supported: hasNativeSession,
|
|
21973
|
+
has_native_session: hasNativeSession,
|
|
21974
|
+
reason: 'sdk_load_failed'
|
|
21975
|
+
});
|
|
21976
|
+
case 10:
|
|
21977
|
+
return _context.a(2, evaluateApplePayAvailability({
|
|
21978
|
+
merchantId: merchantId,
|
|
21979
|
+
apple_pay_capabilities: options.apple_pay_capabilities
|
|
21980
|
+
}));
|
|
21981
|
+
}
|
|
21982
|
+
}, _callee, null, [[7, 9], [2, 5]]);
|
|
21983
|
+
})();
|
|
21984
|
+
});
|
|
21985
|
+
}
|
|
20794
21986
|
}]);
|
|
20795
21987
|
}(OpenWalletButtons);
|
|
20796
21988
|
|
|
@@ -20827,6 +22019,137 @@ var GOOGLE_PAY_CARD_NETWORKS = ['AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCAR
|
|
|
20827
22019
|
SHIPPING_OPTION: EVENT$1.ON_SHIPPING_OPTIONS_CHANGE
|
|
20828
22020
|
});
|
|
20829
22021
|
|
|
22022
|
+
/**
|
|
22023
|
+
* Synchronous, network-free check for whether the Google Pay JS API is already present
|
|
22024
|
+
* in the page (`window.google.payments.api.PaymentsClient`). Safe to call in any
|
|
22025
|
+
* environment (never throws).
|
|
22026
|
+
*
|
|
22027
|
+
* Note: Google Pay has no synchronous device/card capability API — this only reports
|
|
22028
|
+
* whether the SDK script has loaded. The authoritative readiness signal comes from
|
|
22029
|
+
* {@link evaluateGooglePayAvailability} (which runs `isReadyToPay`).
|
|
22030
|
+
*/
|
|
22031
|
+
function isGooglePayApiPresent() {
|
|
22032
|
+
var _a, _b, _c;
|
|
22033
|
+
try {
|
|
22034
|
+
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);
|
|
22035
|
+
} catch (_d) {
|
|
22036
|
+
return false;
|
|
22037
|
+
}
|
|
22038
|
+
}
|
|
22039
|
+
var scriptLoadPromise = null;
|
|
22040
|
+
/**
|
|
22041
|
+
* Idempotently loads the Google Pay JS SDK from the CDN.
|
|
22042
|
+
* Resolves immediately if the API is already present, de-duplicates concurrent loads,
|
|
22043
|
+
* and rejects if the script fails to load.
|
|
22044
|
+
*/
|
|
22045
|
+
function loadGooglePayScript() {
|
|
22046
|
+
if (isGooglePayApiPresent()) {
|
|
22047
|
+
return Promise.resolve();
|
|
22048
|
+
}
|
|
22049
|
+
if (scriptLoadPromise) {
|
|
22050
|
+
return scriptLoadPromise;
|
|
22051
|
+
}
|
|
22052
|
+
scriptLoadPromise = new Promise(function (resolve, reject) {
|
|
22053
|
+
var script = document.createElement('script');
|
|
22054
|
+
script.type = 'text/javascript';
|
|
22055
|
+
script.src = GOOGLE_PAY_SCRIPT_URL;
|
|
22056
|
+
script.async = true;
|
|
22057
|
+
script.onload = function () {
|
|
22058
|
+
if (!isGooglePayApiPresent()) {
|
|
22059
|
+
scriptLoadPromise = null;
|
|
22060
|
+
reject(new Error('Google Pay not available'));
|
|
22061
|
+
return;
|
|
22062
|
+
}
|
|
22063
|
+
resolve();
|
|
22064
|
+
};
|
|
22065
|
+
script.onerror = function () {
|
|
22066
|
+
// Allow a future retry after a transient failure.
|
|
22067
|
+
scriptLoadPromise = null;
|
|
22068
|
+
reject(new Error('Failed to load Google Pay script'));
|
|
22069
|
+
};
|
|
22070
|
+
document.head.appendChild(script);
|
|
22071
|
+
});
|
|
22072
|
+
return scriptLoadPromise;
|
|
22073
|
+
}
|
|
22074
|
+
/**
|
|
22075
|
+
* Builds the base `isReadyToPay` request using the default card configuration
|
|
22076
|
+
* (standard auth methods + card networks). Mirrors the instance service's request:
|
|
22077
|
+
* `existingPaymentMethodRequired` is `false` on Safari (where Google Pay surfaces a
|
|
22078
|
+
* different flow) and `true` elsewhere.
|
|
22079
|
+
*/
|
|
22080
|
+
function buildIsReadyToPayRequest() {
|
|
22081
|
+
var isSafariBrowser = Browser.getBrowserName() === 'Apple Safari';
|
|
22082
|
+
return _extends(_extends({}, GOOGLE_PAY_API_CONFIG), {
|
|
22083
|
+
allowedPaymentMethods: [{
|
|
22084
|
+
type: 'CARD',
|
|
22085
|
+
parameters: {
|
|
22086
|
+
allowedAuthMethods: GOOGLE_PAY_AUTH_METHODS,
|
|
22087
|
+
allowedCardNetworks: GOOGLE_PAY_CARD_NETWORKS
|
|
22088
|
+
}
|
|
22089
|
+
}],
|
|
22090
|
+
existingPaymentMethodRequired: !isSafariBrowser
|
|
22091
|
+
});
|
|
22092
|
+
}
|
|
22093
|
+
/**
|
|
22094
|
+
* Core Google Pay availability evaluation, shared by the instance flow
|
|
22095
|
+
* (`GooglePayOpenWalletService`) and the static `GooglePayOpenWalletButton.checkAvailability`.
|
|
22096
|
+
*
|
|
22097
|
+
* The static check passes no `request`, so it uses the **default** card configuration
|
|
22098
|
+
* (a button instance with a custom `card_config` may produce a different result). The
|
|
22099
|
+
* instance flow passes its own `paymentsClient` and `request` so the readiness check
|
|
22100
|
+
* honours the merchant's `card_config` and runs against the same client it pays with.
|
|
22101
|
+
*
|
|
22102
|
+
* Assumes the Google Pay SDK is already loaded (call {@link loadGooglePayScript} first).
|
|
22103
|
+
*/
|
|
22104
|
+
function evaluateGooglePayAvailability() {
|
|
22105
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
22106
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22107
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
22108
|
+
var _a, _b, paymentsClient, response, available;
|
|
22109
|
+
return _regenerator().w(function (_context) {
|
|
22110
|
+
while (1) switch (_context.p = _context.n) {
|
|
22111
|
+
case 0:
|
|
22112
|
+
if (isGooglePayApiPresent()) {
|
|
22113
|
+
_context.n = 1;
|
|
22114
|
+
break;
|
|
22115
|
+
}
|
|
22116
|
+
return _context.a(2, {
|
|
22117
|
+
available: false,
|
|
22118
|
+
supported: false,
|
|
22119
|
+
reason: 'unsupported_browser'
|
|
22120
|
+
});
|
|
22121
|
+
case 1:
|
|
22122
|
+
_context.p = 1;
|
|
22123
|
+
paymentsClient = (_a = params.paymentsClient) !== null && _a !== void 0 ? _a : new google.payments.api.PaymentsClient({
|
|
22124
|
+
merchantInfo: {
|
|
22125
|
+
merchantId: params.merchantId || ''
|
|
22126
|
+
}
|
|
22127
|
+
});
|
|
22128
|
+
_context.n = 2;
|
|
22129
|
+
return paymentsClient.isReadyToPay((_b = params.request) !== null && _b !== void 0 ? _b : buildIsReadyToPayRequest());
|
|
22130
|
+
case 2:
|
|
22131
|
+
response = _context.v;
|
|
22132
|
+
available = !!response.result;
|
|
22133
|
+
return _context.a(2, {
|
|
22134
|
+
available: available,
|
|
22135
|
+
supported: true,
|
|
22136
|
+
payment_method_present: response.paymentMethodPresent,
|
|
22137
|
+
reason: available ? undefined : 'no_payment_method'
|
|
22138
|
+
});
|
|
22139
|
+
case 3:
|
|
22140
|
+
_context.p = 3;
|
|
22141
|
+
_context.v;
|
|
22142
|
+
return _context.a(2, {
|
|
22143
|
+
available: false,
|
|
22144
|
+
supported: isGooglePayApiPresent(),
|
|
22145
|
+
reason: 'query_failed'
|
|
22146
|
+
});
|
|
22147
|
+
}
|
|
22148
|
+
}, _callee, null, [[1, 3]]);
|
|
22149
|
+
})();
|
|
22150
|
+
});
|
|
22151
|
+
}
|
|
22152
|
+
|
|
20830
22153
|
/**
|
|
20831
22154
|
* Parses intermediate payment data from Google Pay into a normalized format
|
|
20832
22155
|
* for use in shipping address/option change events.
|
|
@@ -21162,14 +22485,18 @@ var GooglePayOpenWalletService = /*#__PURE__*/function (_OpenWalletService) {
|
|
|
21162
22485
|
key: "checkAvailability",
|
|
21163
22486
|
value: function checkAvailability() {
|
|
21164
22487
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
22488
|
+
var result;
|
|
21165
22489
|
return _regenerator().w(function (_context2) {
|
|
21166
22490
|
while (1) switch (_context2.n) {
|
|
21167
22491
|
case 0:
|
|
21168
|
-
|
|
21169
|
-
|
|
21170
|
-
|
|
21171
|
-
|
|
21172
|
-
})
|
|
22492
|
+
_context2.n = 1;
|
|
22493
|
+
return evaluateGooglePayAvailability({
|
|
22494
|
+
paymentsClient: this.paymentsClient,
|
|
22495
|
+
request: this.createRequest()
|
|
22496
|
+
});
|
|
22497
|
+
case 1:
|
|
22498
|
+
result = _context2.v;
|
|
22499
|
+
return _context2.a(2, result.available);
|
|
21173
22500
|
}
|
|
21174
22501
|
}, _callee2, this);
|
|
21175
22502
|
}));
|
|
@@ -21627,14 +22954,46 @@ var GooglePayOpenWalletButton = /*#__PURE__*/function (_OpenWalletButtons) {
|
|
|
21627
22954
|
return _this;
|
|
21628
22955
|
}
|
|
21629
22956
|
/**
|
|
21630
|
-
*
|
|
21631
|
-
*
|
|
21632
|
-
*
|
|
22957
|
+
* Checks Google Pay availability **without instantiating the button** — the static
|
|
22958
|
+
* availability entry point.
|
|
22959
|
+
*
|
|
22960
|
+
* Loads the Google Pay JS SDK if needed, then runs `PaymentsClient.isReadyToPay()` using
|
|
22961
|
+
* the **default** card configuration (a button instance with a custom `card_config` may
|
|
22962
|
+
* produce a different result). All options are optional — unlike Apple Pay, Google Pay's
|
|
22963
|
+
* readiness check does not require a merchant identifier; supplying `service_id` +
|
|
22964
|
+
* `public_key_or_access_token` additionally validates that the service is a Google Pay service.
|
|
22965
|
+
*
|
|
22966
|
+
* Pass `{ sync: true }` for a cheap, network-free check that only reports whether the
|
|
22967
|
+
* Google Pay JS API is already present (see {@link GooglePayAvailabilityOptions.sync}).
|
|
22968
|
+
*
|
|
22969
|
+
* @param {GooglePayAvailabilityOptions} [options] - Optional merchant context and mode.
|
|
22970
|
+
* @returns {Promise<GooglePayAvailabilityResult>} The availability result.
|
|
22971
|
+
*
|
|
22972
|
+
* @example
|
|
22973
|
+
* // Simplest form — no merchant context needed:
|
|
22974
|
+
* const result = await GooglePayOpenWalletButton.checkAvailability();
|
|
22975
|
+
* if (result.available) {
|
|
22976
|
+
* // Render the Google Pay button.
|
|
22977
|
+
* }
|
|
22978
|
+
*
|
|
22979
|
+
* @example
|
|
22980
|
+
* // Validate the service is a Google Pay service while checking:
|
|
22981
|
+
* const result = await GooglePayOpenWalletButton.checkAvailability({
|
|
22982
|
+
* public_key_or_access_token,
|
|
22983
|
+
* service_id,
|
|
22984
|
+
* env: 'sandbox',
|
|
22985
|
+
* });
|
|
21633
22986
|
*/
|
|
21634
22987
|
_inherits(GooglePayOpenWalletButton, _OpenWalletButtons);
|
|
21635
22988
|
return _createClass(GooglePayOpenWalletButton, [{
|
|
21636
22989
|
key: "validateWalletMeta",
|
|
21637
|
-
value:
|
|
22990
|
+
value:
|
|
22991
|
+
/**
|
|
22992
|
+
* Validates Google Pay-specific required metadata fields.
|
|
22993
|
+
* Google Pay has no additional required fields beyond the base (amount, currency, country).
|
|
22994
|
+
* @private
|
|
22995
|
+
*/
|
|
22996
|
+
function validateWalletMeta() {
|
|
21638
22997
|
// Google Pay has no additional required meta fields beyond the base.
|
|
21639
22998
|
// Optional fields (merchant_name, card_config, etc.) are validated
|
|
21640
22999
|
// at runtime by the Google Pay SDK.
|
|
@@ -21665,6 +23024,87 @@ var GooglePayOpenWalletButton = /*#__PURE__*/function (_OpenWalletButtons) {
|
|
|
21665
23024
|
value: function createWalletService(serviceConfig) {
|
|
21666
23025
|
return new GooglePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
|
|
21667
23026
|
}
|
|
23027
|
+
}], [{
|
|
23028
|
+
key: "checkAvailability",
|
|
23029
|
+
value: function checkAvailability() {
|
|
23030
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
23031
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23032
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
23033
|
+
var present, merchantId, authType, api, serviceConfig;
|
|
23034
|
+
return _regenerator().w(function (_context) {
|
|
23035
|
+
while (1) switch (_context.p = _context.n) {
|
|
23036
|
+
case 0:
|
|
23037
|
+
if (!options.sync) {
|
|
23038
|
+
_context.n = 1;
|
|
23039
|
+
break;
|
|
23040
|
+
}
|
|
23041
|
+
present = isGooglePayApiPresent();
|
|
23042
|
+
return _context.a(2, {
|
|
23043
|
+
available: present,
|
|
23044
|
+
supported: present,
|
|
23045
|
+
reason: present ? undefined : 'api_not_loaded'
|
|
23046
|
+
});
|
|
23047
|
+
case 1:
|
|
23048
|
+
merchantId = options.merchant_id;
|
|
23049
|
+
if (!(!merchantId && options.public_key_or_access_token && options.service_id)) {
|
|
23050
|
+
_context.n = 6;
|
|
23051
|
+
break;
|
|
23052
|
+
}
|
|
23053
|
+
_context.p = 2;
|
|
23054
|
+
authType = AccessToken.validateJWT(options.public_key_or_access_token) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
|
|
23055
|
+
api = new ApiInternal(options.public_key_or_access_token, authType);
|
|
23056
|
+
if (options.env) {
|
|
23057
|
+
api.setEnv(options.env);
|
|
23058
|
+
}
|
|
23059
|
+
_context.n = 3;
|
|
23060
|
+
return getServiceConfigCached(api, options.service_id);
|
|
23061
|
+
case 3:
|
|
23062
|
+
serviceConfig = _context.v;
|
|
23063
|
+
if (!(serviceConfig.type !== SERVICE_TYPES.GOOGLE_PAY)) {
|
|
23064
|
+
_context.n = 4;
|
|
23065
|
+
break;
|
|
23066
|
+
}
|
|
23067
|
+
return _context.a(2, {
|
|
23068
|
+
available: false,
|
|
23069
|
+
supported: isGooglePayApiPresent(),
|
|
23070
|
+
reason: 'service_type_mismatch'
|
|
23071
|
+
});
|
|
23072
|
+
case 4:
|
|
23073
|
+
merchantId = serviceConfig.merchant;
|
|
23074
|
+
_context.n = 6;
|
|
23075
|
+
break;
|
|
23076
|
+
case 5:
|
|
23077
|
+
_context.p = 5;
|
|
23078
|
+
_context.v;
|
|
23079
|
+
return _context.a(2, {
|
|
23080
|
+
available: false,
|
|
23081
|
+
supported: isGooglePayApiPresent(),
|
|
23082
|
+
reason: 'config_fetch_failed'
|
|
23083
|
+
});
|
|
23084
|
+
case 6:
|
|
23085
|
+
_context.p = 6;
|
|
23086
|
+
_context.n = 7;
|
|
23087
|
+
return loadGooglePayScript();
|
|
23088
|
+
case 7:
|
|
23089
|
+
_context.n = 9;
|
|
23090
|
+
break;
|
|
23091
|
+
case 8:
|
|
23092
|
+
_context.p = 8;
|
|
23093
|
+
_context.v;
|
|
23094
|
+
return _context.a(2, {
|
|
23095
|
+
available: false,
|
|
23096
|
+
supported: isGooglePayApiPresent(),
|
|
23097
|
+
reason: 'sdk_load_failed'
|
|
23098
|
+
});
|
|
23099
|
+
case 9:
|
|
23100
|
+
return _context.a(2, evaluateGooglePayAvailability({
|
|
23101
|
+
merchantId: merchantId
|
|
23102
|
+
}));
|
|
23103
|
+
}
|
|
23104
|
+
}, _callee, null, [[6, 8], [2, 5]]);
|
|
23105
|
+
})();
|
|
23106
|
+
});
|
|
23107
|
+
}
|
|
21668
23108
|
}]);
|
|
21669
23109
|
}(OpenWalletButtons);
|
|
21670
23110
|
|