@andy.ian/dsh-homing 2.3.0 → 2.3.1

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.
Files changed (2) hide show
  1. package/index.js +11 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1314,6 +1314,9 @@ function verifyTotp(secret, code, lastStep) {
1314
1314
  return false;
1315
1315
  }
1316
1316
 
1317
+ /** HSTS 有效期:一年。让浏览器在首次 HTTPS 访问后不再尝试明文 http。 */
1318
+ const HSTS_MAX_AGE = 'max-age=31536000';
1319
+
1317
1320
  function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCookies, caCertPath }) {
1318
1321
  const appRegistry = createLocalAppRegistry({
1319
1322
  settingsPath: path.join(dir, 'settings.json'),
@@ -1512,6 +1515,13 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
1512
1515
  }
1513
1516
  let csp = '';
1514
1517
  if (headers && typeof headers === 'object') csp = String(headers['content-security-policy'] ?? '');
1518
+ // 统一给所有响应加 HSTS(2026-11-19):手机浏览器升级后曾默认走 http://,
1519
+ // 远端 80 端口空关闭导致 ERR_EMPTY_RESPONSE;现在 80 已 301 到 https,
1520
+ // 再加上 HSTS 让浏览器第一次访问后直接走 https、不再经过 80。
1521
+ // 只有 HTTPS 响应会被浏览器采纳,明文响应里带这个头是无害的。
1522
+ if (headers && typeof headers === 'object' && headers['strict-transport-security'] === undefined) {
1523
+ headers = { ...headers, 'strict-transport-security': HSTS_MAX_AGE };
1524
+ }
1515
1525
  // 只有插件自己的页面以 default-src 'none' 开头;DSH 前端页面不能改写,
1516
1526
  // 否则会破坏 0.2.2 动态生成的 <script> 模板。
1517
1527
  if (csp.includes("default-src 'none'")) {
@@ -4099,7 +4109,7 @@ ${message ? `<div class="msg">${escapeHtml(message)}</div>` : ''}
4099
4109
  delete staticHeaders['etag'];
4100
4110
  delete staticHeaders['last-modified'];
4101
4111
  }
4102
- staticHeaders['strict-transport-security'] = 'max-age=31536000';
4112
+ staticHeaders['strict-transport-security'] = HSTS_MAX_AGE;
4103
4113
  res.writeHead(upstreamStatus, staticHeaders);
4104
4114
  // SSE 诊断:应用靠 /plugins/events 拿到插件图。记录时长与字节数开销极小,
4105
4115
  // 出问题时能立刻判断"事件流是否送达"。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andy.ian/dsh-homing",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "type": "module",
5
5
  "description": "把本机 DSH 通过 SSH 反向隧道安全开放到手机浏览器:TLS 端到端(服务器只透传)、账号 + TOTP、局域网与公网双入口,随 DSH 启动。",
6
6
  "keywords": [