@ozura/elements 1.2.4-next.53 → 1.2.4-next.54

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.
@@ -1,6 +1,41 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { createContext, useContext, useRef, useCallback, useState, useMemo, useEffect } from 'react';
3
3
 
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
19
+
20
+
21
+ function __classPrivateFieldGet(receiver, state, kind, f) {
22
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
23
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
24
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
25
+ }
26
+
27
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
28
+ if (kind === "m") throw new TypeError("Private method is not writable");
29
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
30
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
31
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
32
+ }
33
+
34
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
+ var e = new Error(message);
36
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
+ };
38
+
4
39
  const THEME_DEFAULT = {
5
40
  base: {
6
41
  color: '#1a1a2e',
@@ -952,6 +987,7 @@ function createSessionFetcher(url) {
952
987
  };
953
988
  }
954
989
 
990
+ var _OzVault_waxKey;
955
991
  function isCardMetadata(v) {
956
992
  if (!v || typeof v !== 'object')
957
993
  return false;
@@ -995,6 +1031,11 @@ class OzVault {
995
1031
  */
996
1032
  constructor(options, waxKey, tokenizationSessionId) {
997
1033
  var _a, _b, _c, _d, _e;
1034
+ // Hard-private: JavaScript WeakMap-based enforcement (not just TypeScript
1035
+ // compile-time). Runtime code cannot read this via vault['waxKey'] or
1036
+ // (vault as any).waxKey — prevents wax key exfiltration if merchant-page
1037
+ // JS were somehow inspected at runtime (e.g. after an XSS).
1038
+ _OzVault_waxKey.set(this, '');
998
1039
  this.elements = new Map();
999
1040
  this.elementsByType = new Map();
1000
1041
  this.bankElementsByType = new Map();
@@ -1020,7 +1061,7 @@ class OzVault {
1020
1061
  this.loadErrorTimeoutId = null;
1021
1062
  // Proactive wax refresh on visibility restore after long idle
1022
1063
  this._hiddenAt = null;
1023
- this.waxKey = waxKey;
1064
+ __classPrivateFieldSet(this, _OzVault_waxKey, waxKey, "f");
1024
1065
  this.tokenizationSessionId = tokenizationSessionId;
1025
1066
  this.pubKey = options.pubKey;
1026
1067
  // Strip trailing slash so URL construction never produces double-slash paths
@@ -1132,8 +1173,8 @@ class OzVault {
1132
1173
  vault.destroy();
1133
1174
  throw new OzError('Session fetch returned an empty key. Check your session endpoint response — it must return { sessionKey: "..." }.');
1134
1175
  }
1135
- // Static methods can access private fields of instances of the same class.
1136
- vault.waxKey = waxKey;
1176
+ // Static methods can access hard-private fields of instances of the same class.
1177
+ __classPrivateFieldSet(vault, _OzVault_waxKey, waxKey, "f");
1137
1178
  vault._storedFetchWaxKey = resolvedFetchKey;
1138
1179
  // If the tokenizer iframe fired OZ_FRAME_READY before fetchWaxKey resolved,
1139
1180
  // the OZ_INIT sent at that point had an empty waxKey. Send a follow-up now
@@ -1650,7 +1691,7 @@ class OzVault {
1650
1691
  isReady: this.tokenizerReady,
1651
1692
  tokenizing: this._tokenizing,
1652
1693
  destroyed: this._destroyed,
1653
- waxKeyPresent: Boolean(this.waxKey),
1694
+ waxKeyPresent: Boolean(__classPrivateFieldGet(this, _OzVault_waxKey, "f")),
1654
1695
  tokenizeSuccessCount: this._tokenizeSuccessCount,
1655
1696
  maxTokenizeCalls: this._maxTokenizeCalls,
1656
1697
  resetCount: this._resetCount,
@@ -1668,6 +1709,17 @@ class OzVault {
1668
1709
  iframe.style.cssText = 'position:absolute;top:-9999px;left:-9999px;width:1px;height:1px;';
1669
1710
  iframe.setAttribute('aria-hidden', 'true');
1670
1711
  iframe.tabIndex = -1;
1712
+ // allow-scripts: JS runs. allow-same-origin: frame keeps its actual origin
1713
+ // (elements.ozura.com) so fetch() CORS requests carry the correct Origin
1714
+ // header. Without allow-same-origin the frame gets a null opaque origin and
1715
+ // the vault API's CORS policy would reject it.
1716
+ // NOT included: allow-top-navigation, allow-popups, allow-forms — prevents
1717
+ // a compromised tokenizer frame from navigating the merchant page or opening
1718
+ // popups even if the CDN bundle were somehow replaced.
1719
+ // Note: allow-scripts + allow-same-origin on a cross-origin iframe does NOT
1720
+ // expose window.parent — Same Origin Policy still applies between
1721
+ // elements.ozura.com and the merchant domain.
1722
+ iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
1671
1723
  const parentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
1672
1724
  iframe.src = `${this.frameBaseUrl}/frame/tokenizer-frame.html#vaultId=${encodeURIComponent(this.vaultId)}${parentOrigin ? `&parentOrigin=${encodeURIComponent(parentOrigin)}` : ''}`;
1673
1725
  document.body.appendChild(iframe);
@@ -1803,7 +1855,7 @@ class OzVault {
1803
1855
  // Deliver the wax key via OZ_INIT so the tokenizer stores it internally.
1804
1856
  // If waxKey is still empty (fetchWaxKey hasn't resolved yet), it will be
1805
1857
  // sent again from create() once the key is available.
1806
- this.sendToTokenizer(Object.assign(Object.assign({ type: 'OZ_INIT', frameId: '__tokenizer__' }, (this.waxKey ? { waxKey: this.waxKey } : {})), { debug: this._debug }));
1858
+ this.sendToTokenizer(Object.assign(Object.assign({ type: 'OZ_INIT', frameId: '__tokenizer__' }, (__classPrivateFieldGet(this, _OzVault_waxKey, "f") ? { waxKey: __classPrivateFieldGet(this, _OzVault_waxKey, "f") } : {})), { debug: this._debug }));
1807
1859
  (_c = this._onReady) === null || _c === void 0 ? void 0 : _c.call(this);
1808
1860
  this.log('tokenizer iframe ready', { protocolVersion: (_d = msg.__ozVersion) !== null && _d !== void 0 ? _d : null });
1809
1861
  this.log('vault state', this.debugState());
@@ -2109,7 +2161,7 @@ class OzVault {
2109
2161
  throw new OzError('fetchWaxKey returned an empty string during auto-refresh.', undefined, 'auth');
2110
2162
  }
2111
2163
  if (!this._destroyed) {
2112
- this.waxKey = newWaxKey;
2164
+ __classPrivateFieldSet(this, _OzVault_waxKey, newWaxKey, "f");
2113
2165
  this.tokenizationSessionId = newSessionId;
2114
2166
  this._tokenizeSuccessCount = 0;
2115
2167
  }
@@ -2133,6 +2185,7 @@ class OzVault {
2133
2185
  (_a = this.tokenizerWindow) === null || _a === void 0 ? void 0 : _a.postMessage(msg, this.frameOrigin, transfer !== null && transfer !== void 0 ? transfer : []);
2134
2186
  }
2135
2187
  }
2188
+ _OzVault_waxKey = new WeakMap();
2136
2189
 
2137
2190
  const OzContext = createContext({
2138
2191
  vault: null,