@andy.ian/dsh-homing 2.0.2 → 2.0.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/index.js +71 -8
- package/lib/files-page.mjs +10 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1037,7 +1037,7 @@ function sendLogin(res, message = '', requireTotp = false) {
|
|
|
1037
1037
|
'cache-control': 'no-store',
|
|
1038
1038
|
// 登录页的安全头:禁止被嵌入(防点击劫持)、禁止外链、限制表单只能提交给自己
|
|
1039
1039
|
'x-frame-options': 'DENY',
|
|
1040
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
1040
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
1041
1041
|
'x-content-type-options': 'nosniff',
|
|
1042
1042
|
'referrer-policy': 'no-referrer',
|
|
1043
1043
|
});
|
|
@@ -1276,6 +1276,35 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1276
1276
|
const touchActivity = createActivityRecorder(dir);
|
|
1277
1277
|
|
|
1278
1278
|
const handler = async (req, res) => {
|
|
1279
|
+
// 每个响应生成一次性 nonce:内联脚本必须带 nonce 才能执行,
|
|
1280
|
+
// 攻击者注入的脚本没有 nonce,即使 HTML 转义出漏洞也跑不起来。
|
|
1281
|
+
const nonce = crypto.randomBytes(16).toString('base64url');
|
|
1282
|
+
let responseType = '';
|
|
1283
|
+
const rawWriteHead = res.writeHead.bind(res);
|
|
1284
|
+
res.writeHead = (status, headers, ...rest) => {
|
|
1285
|
+
if (headers && typeof headers === 'object' && typeof headers['content-type'] === 'string') {
|
|
1286
|
+
responseType = headers['content-type'];
|
|
1287
|
+
}
|
|
1288
|
+
if (headers && typeof headers === 'object' && typeof headers['content-security-policy'] === 'string') {
|
|
1289
|
+
headers = {
|
|
1290
|
+
...headers,
|
|
1291
|
+
'content-security-policy': headers['content-security-policy'].replace(
|
|
1292
|
+
"script-src 'self'",
|
|
1293
|
+
`script-src 'self' 'nonce-${nonce}'`,
|
|
1294
|
+
),
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
return rawWriteHead(status, headers, ...rest);
|
|
1298
|
+
};
|
|
1299
|
+
const rawEnd = res.end.bind(res);
|
|
1300
|
+
res.end = (body, ...rest) => {
|
|
1301
|
+
const type = responseType || String(res.getHeader('content-type') ?? '');
|
|
1302
|
+
if (typeof body === 'string' && type.includes('text/html')) {
|
|
1303
|
+
body = body.replaceAll('<script', `<script nonce="${nonce}"`);
|
|
1304
|
+
}
|
|
1305
|
+
return rawEnd(body, ...rest);
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1279
1308
|
|
|
1280
1309
|
const url = new URL(req.url ?? '/', 'http://dsh-homing.invalid');
|
|
1281
1310
|
// 任何来自浏览器的请求都算"人在用"(静态资源除外,避免预加载把空闲判断拖长)
|
|
@@ -1421,7 +1450,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1421
1450
|
'content-type': 'text/html; charset=utf-8',
|
|
1422
1451
|
'cache-control': 'no-store',
|
|
1423
1452
|
'x-frame-options': 'DENY',
|
|
1424
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
1453
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
1425
1454
|
'x-content-type-options': 'nosniff',
|
|
1426
1455
|
'referrer-policy': 'no-referrer',
|
|
1427
1456
|
});
|
|
@@ -1445,7 +1474,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1445
1474
|
'content-type': 'text/html; charset=utf-8',
|
|
1446
1475
|
'cache-control': 'no-store',
|
|
1447
1476
|
'x-frame-options': 'DENY',
|
|
1448
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
1477
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
1449
1478
|
'x-content-type-options': 'nosniff',
|
|
1450
1479
|
'referrer-policy': 'no-referrer',
|
|
1451
1480
|
});
|
|
@@ -1721,7 +1750,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1721
1750
|
'content-type': 'text/html; charset=utf-8',
|
|
1722
1751
|
'cache-control': 'no-store',
|
|
1723
1752
|
'x-frame-options': 'DENY',
|
|
1724
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
1753
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
1725
1754
|
'x-content-type-options': 'nosniff',
|
|
1726
1755
|
'referrer-policy': 'no-referrer',
|
|
1727
1756
|
});
|
|
@@ -1786,7 +1815,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1786
1815
|
'content-type': 'text/html; charset=utf-8',
|
|
1787
1816
|
'cache-control': 'no-store',
|
|
1788
1817
|
'x-frame-options': 'DENY',
|
|
1789
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
1818
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
1790
1819
|
'x-content-type-options': 'nosniff',
|
|
1791
1820
|
'referrer-policy': 'no-referrer',
|
|
1792
1821
|
});
|
|
@@ -1832,6 +1861,40 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1832
1861
|
return;
|
|
1833
1862
|
}
|
|
1834
1863
|
|
|
1864
|
+
if (url.pathname === '/files/delete' && req.method === 'POST') {
|
|
1865
|
+
const form = new URLSearchParams(await readBody(req, 64 * 1024));
|
|
1866
|
+
const target = form.get('path') ?? '';
|
|
1867
|
+
const result = filebrowse.deleteEntry(target);
|
|
1868
|
+
appendAudit(dir, 'file-delete', { target, ok: result.ok, error: result.error ?? null });
|
|
1869
|
+
res.writeHead(303, { location: '/files?path=' + encodeURIComponent(path.dirname(target)), 'cache-control': 'no-store' });
|
|
1870
|
+
res.end();
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
if (url.pathname === '/files/paste' && req.method === 'POST') {
|
|
1875
|
+
const form = new URLSearchParams(await readBody(req, 64 * 1024));
|
|
1876
|
+
const src = form.get('src') ?? '';
|
|
1877
|
+
const destDir = form.get('dir') ?? '';
|
|
1878
|
+
const op = form.get('op') === 'cut' ? 'cut' : 'copy';
|
|
1879
|
+
const result = op === 'cut' ? filebrowse.moveInto(src, destDir) : filebrowse.copyInto(src, destDir);
|
|
1880
|
+
appendAudit(dir, op === 'cut' ? 'file-move' : 'file-paste', { src, dir: destDir, ok: result.ok, target: result.path ?? null, error: result.error ?? null });
|
|
1881
|
+
res.writeHead(303, { location: '/files?path=' + encodeURIComponent(destDir), 'cache-control': 'no-store' });
|
|
1882
|
+
res.end();
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
if ((url.pathname === '/files/mkdir' || url.pathname === '/files/newfile') && req.method === 'POST') {
|
|
1887
|
+
const form = new URLSearchParams(await readBody(req, 64 * 1024));
|
|
1888
|
+
const targetDir = form.get('dir') ?? '';
|
|
1889
|
+
const name = form.get('name') ?? '';
|
|
1890
|
+
const isDir = url.pathname === '/files/mkdir';
|
|
1891
|
+
const result = filebrowse.createEntry(targetDir, name, isDir);
|
|
1892
|
+
appendAudit(dir, isDir ? 'file-mkdir' : 'file-newfile', { dir: targetDir, name, ok: result.ok, error: result.error ?? null });
|
|
1893
|
+
res.writeHead(303, { location: '/files?path=' + encodeURIComponent(targetDir), 'cache-control': 'no-store' });
|
|
1894
|
+
res.end();
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1835
1898
|
if (url.pathname === '/files/rename' && req.method === 'POST') {
|
|
1836
1899
|
const form = new URLSearchParams(await readBody(req, 64 * 1024));
|
|
1837
1900
|
const target = form.get('path') ?? '';
|
|
@@ -1909,7 +1972,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
1909
1972
|
'content-type': 'text/html; charset=utf-8',
|
|
1910
1973
|
'cache-control': 'no-store',
|
|
1911
1974
|
'x-frame-options': 'DENY',
|
|
1912
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; script-src '
|
|
1975
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; script-src 'self'; form-action 'self'; base-uri 'none'",
|
|
1913
1976
|
'x-content-type-options': 'nosniff',
|
|
1914
1977
|
'referrer-policy': 'no-referrer',
|
|
1915
1978
|
});
|
|
@@ -2043,7 +2106,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
2043
2106
|
'content-type': 'text/html; charset=utf-8',
|
|
2044
2107
|
'cache-control': 'no-store',
|
|
2045
2108
|
'x-frame-options': 'DENY',
|
|
2046
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
2109
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
2047
2110
|
'x-content-type-options': 'nosniff',
|
|
2048
2111
|
'referrer-policy': 'no-referrer',
|
|
2049
2112
|
});
|
|
@@ -2441,7 +2504,7 @@ ${revokedRows ? `<h2>已吊销</h2><table><tbody>${revokedRows}</tbody></table>`
|
|
|
2441
2504
|
'content-type': 'text/html; charset=utf-8',
|
|
2442
2505
|
'cache-control': 'no-store',
|
|
2443
2506
|
'x-frame-options': 'DENY',
|
|
2444
|
-
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src '
|
|
2507
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; script-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; img-src 'self' data:",
|
|
2445
2508
|
'x-content-type-options': 'nosniff',
|
|
2446
2509
|
'referrer-policy': 'no-referrer',
|
|
2447
2510
|
...(deviceCookies.length > 0 ? { 'set-cookie': deviceCookies } : {}),
|
package/lib/files-page.mjs
CHANGED
|
@@ -283,6 +283,7 @@ ${entry.dir ? `<a class="mi" role="menuitem" data-act="paste" data-path="${escap
|
|
|
283
283
|
.mm { position: relative; display: inline-block; }
|
|
284
284
|
.mm-btn { margin-left: 6px; padding: 6px 10px; border-radius: 8px; background: #2a2f3a; border: 1px solid #3a4351; color: #c7cdd8; font-size: 14px; line-height: 1; }
|
|
285
285
|
.mm-btn:active { background: #3a4351; }
|
|
286
|
+
.mm-btn-add { background: #2f4a68; border-color: #3f5f84; color: #dce9f7; font-size: 15px; padding: 4px 11px; }
|
|
286
287
|
.rowmenu { position: fixed; z-index: 9999; min-width: 0; padding: 4px 0; background: #20262f; border: 1px solid #3a4351; border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.6); }
|
|
287
288
|
.rowmenu[hidden] { display: none; }
|
|
288
289
|
.rowmenu .mi { display: flex; align-items: center; gap: 9px; padding: 8px 14px 8px 10px; color: #e3e9f1; text-decoration: none; font-size: 13px; line-height: 1.35; white-space: nowrap; text-align: left; }
|
|
@@ -297,6 +298,15 @@ ${entry.dir ? `<a class="mi" role="menuitem" data-act="paste" data-path="${escap
|
|
|
297
298
|
<button type="button" class="sortbtn" data-sort="name">名称</button>
|
|
298
299
|
<button type="button" class="sortbtn" data-sort="size">大小</button>
|
|
299
300
|
<button type="button" class="sortbtn" data-sort="time">时间</button>
|
|
301
|
+
<span style="margin-left:auto" class="mm">
|
|
302
|
+
<button type="button" class="mm-btn mm-btn-add" title="当前目录操作(新建 / 粘贴 / 复制路径)">\uFF0B</button>
|
|
303
|
+
<span class="rowmenu" hidden role="menu">
|
|
304
|
+
<a class="mi" role="menuitem" data-act="paste" data-path="${escapeHtml(info.path)}" href="#"><span class="ico">\u{1F4E5}</span>粘贴到此处</a>
|
|
305
|
+
<a class="mi" role="menuitem" data-act="mkdir" data-path="${escapeHtml(info.path)}" href="#"><span class="ico">\u{1F4C1}</span>新建文件夹</a>
|
|
306
|
+
<a class="mi" role="menuitem" data-act="newfile" data-path="${escapeHtml(info.path)}" href="#"><span class="ico">\u{1F4C4}</span>新建文件</a>
|
|
307
|
+
<a class="mi" role="menuitem" data-act="copypath" data-path="${escapeHtml(info.path)}" href="#"><span class="ico">\u{1F4CB}</span>复制路径</a>
|
|
308
|
+
</span>
|
|
309
|
+
</span>
|
|
300
310
|
</div>
|
|
301
311
|
<div class="flist">${rows || '<div class="fempty">空目录</div>'}</div>
|
|
302
312
|
${MENU_JS}\n <p class="crumbs">提示:点目录进入,点文件名查看内容;标 ⚙️ 的可直接运行(会在这台电脑上执行)。</p>`
|