@sparkvault/sdk-js 1.27.3 → 1.27.4

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.
@@ -65,14 +65,72 @@ class PopupBlockedError extends SparkVaultError {
65
65
  }
66
66
  }
67
67
 
68
+ /**
69
+ * SparkVault-owned domain registry.
70
+ *
71
+ * Keep platform domain decisions centralized: CSP, redirect safety, custom
72
+ * domain reservation, and Identity postMessage trust all depend on the same
73
+ * ownership boundary.
74
+ */
75
+
76
+ const SPARKVAULT_ROOT_DOMAIN = 'sparkvault.com';
77
+
78
+ const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
79
+ 'auth.sv',
80
+ 'x.sv',
81
+ 'files.sv',
82
+ 'file.sv',
83
+ 'send.sv',
84
+ 'spark.sv',
85
+ 'by.sv',
86
+ 'at.sv',
87
+ 'db.sv'
88
+ ]);
89
+
90
+ const SPARKVAULT_WEBSOCKET_HOSTS = Object.freeze([
91
+ 'ws.sparkvault.com'
92
+ ]);
93
+
94
+ Object.freeze([
95
+ SPARKVAULT_ROOT_DOMAIN,
96
+ 'app.sparkvault.com',
97
+ 'api.sparkvault.com',
98
+ 'cdn.sparkvault.com',
99
+ 'forge.sparkvault.com',
100
+ 'img.sparkvault.com',
101
+ ...SPARKVAULT_WEBSOCKET_HOSTS,
102
+ ...SPARKVAULT_PLATFORM_SV_HOSTS
103
+ ]);
104
+
105
+ function normalizeHostname(hostname) {
106
+ if (typeof hostname !== 'string') return '';
107
+ return hostname.trim().toLowerCase().replace(/\.$/, '');
108
+ }
109
+
110
+ function isSparkVaultRootOrSubdomain(hostname) {
111
+ const normalized = normalizeHostname(hostname);
112
+ return normalized === SPARKVAULT_ROOT_DOMAIN || normalized.endsWith(`.${SPARKVAULT_ROOT_DOMAIN}`);
113
+ }
114
+
115
+ function isSparkVaultPlatformSvHost(hostname) {
116
+ return SPARKVAULT_PLATFORM_SV_HOSTS.includes(normalizeHostname(hostname));
117
+ }
118
+
119
+ function isSparkVaultOwnedHostname(hostname) {
120
+ return isSparkVaultRootOrSubdomain(hostname) || isSparkVaultPlatformSvHost(hostname);
121
+ }
122
+
68
123
  /**
69
124
  * SparkVault SDK Configuration
70
125
  */
126
+ function escapeRegExp(value) {
127
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
128
+ }
129
+ const SPARKVAULT_PLATFORM_SV_DOWNLOAD_PATTERN = new RegExp(`(^|\\.)(${SPARKVAULT_PLATFORM_SV_HOSTS.map(escapeRegExp).join('|')})$`, 'i');
71
130
  // Hosts that are allowed to serve backend-issued ingot download URLs.
72
- // Keep in sync with the sdk-mobile default in packages/sdk-mobile/src/config.ts.
73
131
  const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
74
- /(^|\.)sparkvault\.com$/i,
75
- /(^|\.)(x|files|file|send|spark|by|at|db|auth)\.sv$/i,
132
+ new RegExp(`(^|\\.)${escapeRegExp(SPARKVAULT_ROOT_DOMAIN)}$`, 'i'),
133
+ SPARKVAULT_PLATFORM_SV_DOWNLOAD_PATTERN,
76
134
  /\.amazonaws\.com$/i,
77
135
  /\.cloudfront\.net$/i,
78
136
  ];
@@ -1624,12 +1682,7 @@ class PasskeyHandler {
1624
1682
  isValidMessageOrigin(origin) {
1625
1683
  try {
1626
1684
  const url = new URL(origin);
1627
- const hostname = url.hostname;
1628
- // Allow sparkvault.com and subdomains
1629
- if (hostname === 'sparkvault.com' || hostname.endsWith('.sparkvault.com')) {
1630
- return true;
1631
- }
1632
- return false;
1685
+ return url.protocol === 'https:' && url.origin === origin && !url.port && isSparkVaultOwnedHostname(url.hostname);
1633
1686
  }
1634
1687
  catch {
1635
1688
  return false;