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