@tianacloud/dsh-remote 0.2.2 → 0.2.3

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/host-main.js CHANGED
@@ -223,7 +223,7 @@ export function createHostController(options = {}) {
223
223
  if (!Array.isArray(graph?.entries)) return [];
224
224
  return graph.entries
225
225
  .map((e) => e.id)
226
- .filter((id) => typeof id === 'string' && !id.startsWith('@deepseek-ai/dsh-client-') && id !== '@tianacloud/dsh-remote');
226
+ .filter((id) => typeof id === 'string' && !id.startsWith('@deepseek-ai/dsh-') && id !== '@tianacloud/dsh-remote');
227
227
  } catch {
228
228
  return [];
229
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tianacloud/dsh-remote",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "使用 Tiana 能力为 DeepSeek Harness 提供零公网 IP 远程访问、侧栏管理面板、无密钥流式子资源桥接与云端一键引导插件。",
6
6
  "license": "Apache-2.0",
package/src/connect.js CHANGED
@@ -394,6 +394,10 @@ export async function isLocalDshResponsive(origin, { fetchFn = fetch, timeoutMs
394
394
  }
395
395
  }
396
396
 
397
+ export function buildDshStartArgs({ profile = 'web', port = 3080 } = {}) {
398
+ return ['--profile', String(profile || 'web'), '--port', String(port), '--no-open'];
399
+ }
400
+
397
401
  export async function waitForLocalDshReady(port, timeoutMs = 15_000, { childState = null, fetchFn = fetch } = {}) {
398
402
  const deadline = Date.now() + timeoutMs;
399
403
  const origin = `http://127.0.0.1:${port}`;
@@ -508,9 +512,11 @@ export async function runConnect(options = {}, deps = {}) {
508
512
  if (deps.startDsh) {
509
513
  dshStarted = await deps.startDsh(dshInfo.bin, { profile, port });
510
514
  } else {
511
- log(`[dsh-remote] Starting local DSH (${dshInfo.bin} web --port ${port} --no-open)...`);
515
+ const spawnFn = deps.spawnFn ?? spawn;
516
+ const startArgs = buildDshStartArgs({ profile, port });
517
+ log(`[dsh-remote] Starting local DSH (${dshInfo.bin} ${startArgs.join(' ')})...`);
512
518
  const childState = { error: null, exited: false, exitCode: null };
513
- const child = spawn(dshInfo.bin, ['web', '--profile', profile, '--port', String(port), '--no-open'], {
519
+ const child = spawnFn(dshInfo.bin, startArgs, {
514
520
  stdio: 'ignore',
515
521
  detached: true,
516
522
  windowsHide: true,
@@ -137,14 +137,14 @@ function cleanBundle(file) {
137
137
  return Buffer.from(readFile(file).toString('utf8').replace(/\r?\n\/\/# source(?:Mapping)?URL=[^\r\n]*/gu, ''));
138
138
  }
139
139
 
140
- const BUILTIN_CLIENT_PREFIX = '@deepseek-ai/dsh-client-';
140
+ const BUILTIN_CLIENT_PREFIX = '@deepseek-ai/dsh-';
141
141
  const SELF_CLIENT_MODULE = '@tianacloud/dsh-remote';
142
142
 
143
143
  /**
144
144
  * Select which active DSH client modules are exposed over the remote tunnel.
145
145
  * - `allowlist: ['*']` (or `'*'`): allow all active modules.
146
146
  * - `allowlist: []` (default) or omitted: allow ONLY builtin DSH core modules
147
- * (`@deepseek-ai/dsh-client-*`) plus `@tianacloud/dsh-remote` itself; third-party plugins are blocked.
147
+ * (`@deepseek-ai/dsh-*`) plus `@tianacloud/dsh-remote` itself; third-party plugins are blocked.
148
148
  * - Explicit IDs: allow builtin core + `@tianacloud/dsh-remote` + exact allowlisted active plugins.
149
149
  */
150
150
  export function selectAllowedWebPlugins(modules, allowlist) {
@@ -1874,6 +1874,7 @@ function installSwScopeAlignment(appBasePath, signal, getNavToken) {
1874
1874
  const dlUrl = new URL(next, location.href);
1875
1875
  dlUrl.searchParams.set('__dsh_dl', (anchor.getAttribute('download') || '').trim() || '1');
1876
1876
  const f = document.createElement('iframe');
1877
+ f.referrerPolicy = 'same-origin';
1877
1878
  f.style.display = 'none';
1878
1879
  f.setAttribute('aria-hidden', 'true');
1879
1880
  f.src = dlUrl.href;
@@ -1883,6 +1884,13 @@ function installSwScopeAlignment(appBasePath, signal, getNavToken) {
1883
1884
 
1884
1885
  if (!iframeNavHooksInstalled && typeof HTMLIFrameElement !== 'undefined') {
1885
1886
  iframeNavHooksInstalled = true;
1887
+ const ensureSameOriginReferrer = (el, nextUrl) => {
1888
+ if (nextUrl && nextUrl.includes('__dsh_nav=')) {
1889
+ // Override document-level `Referrer-Policy: no-referrer` strictly for same-origin SW-tunneled iframes
1890
+ // without ever leaking referrers cross-origin.
1891
+ try { el.referrerPolicy = 'same-origin'; } catch { /* ignore */ }
1892
+ }
1893
+ };
1886
1894
  const desc = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'src');
1887
1895
  if (desc?.set && desc.configurable) {
1888
1896
  Object.defineProperty(HTMLIFrameElement.prototype, 'src', {
@@ -1891,6 +1899,7 @@ function installSwScopeAlignment(appBasePath, signal, getNavToken) {
1891
1899
  get: desc.get,
1892
1900
  set(val) {
1893
1901
  const next = activeSwNavRewriter ? activeSwNavRewriter(String(val)) : String(val);
1902
+ ensureSameOriginReferrer(this, next);
1894
1903
  return desc.set.call(this, next);
1895
1904
  },
1896
1905
  });
@@ -1899,6 +1908,7 @@ function installSwScopeAlignment(appBasePath, signal, getNavToken) {
1899
1908
  HTMLIFrameElement.prototype.setAttribute = function setAttribute(name, value) {
1900
1909
  if (String(name).toLowerCase() === 'src') {
1901
1910
  const next = activeSwNavRewriter ? activeSwNavRewriter(String(value)) : String(value);
1911
+ ensureSameOriginReferrer(this, next);
1902
1912
  return origSetAttr.call(this, name, next);
1903
1913
  }
1904
1914
  return origSetAttr.call(this, name, value);
@@ -349,6 +349,33 @@ function resolvePortByNavToken(navToken) {
349
349
 
350
350
  async function resolvePortForEvent(event, url) {
351
351
  const directClientId = event.clientId || '';
352
+ const dest = event.request.destination || '';
353
+ const referrer = event.request.referrer || '';
354
+ if (dest === 'iframe' || dest === 'frame') {
355
+ if (referrer) {
356
+ if (!isTrustedAppUrl(referrer)) {
357
+ return null;
358
+ }
359
+ } else {
360
+ const secFetchSite = String(event.request.headers.get('sec-fetch-site') || '').trim().toLowerCase();
361
+ if (secFetchSite !== 'same-origin') {
362
+ return null;
363
+ }
364
+ if (!directClientId) {
365
+ return null;
366
+ }
367
+ let parentClient = null;
368
+ try {
369
+ parentClient = await self.clients.get(directClientId);
370
+ } catch {
371
+ parentClient = null;
372
+ }
373
+ if (!isTrustedWindowClient(parentClient)) {
374
+ return null;
375
+ }
376
+ }
377
+ }
378
+
352
379
  if (directClientId) {
353
380
  const existingDirect = portsByClientId.get(directClientId);
354
381
  if (existingDirect) return existingDirect;
@@ -366,11 +393,6 @@ async function resolvePortForEvent(event, url) {
366
393
 
367
394
  const navToken = extractNavToken(event.request, url);
368
395
  if (navToken) {
369
- const dest = event.request.destination || '';
370
- const referrer = event.request.referrer || '';
371
- if ((dest === 'iframe' || dest === 'frame') && !isTrustedAppUrl(referrer)) {
372
- return null;
373
- }
374
396
  if (referrer && (referrer.startsWith('http://') || referrer.startsWith('https://')) && !isTrustedAppUrl(referrer)) {
375
397
  return null;
376
398
  }