dsh-remote 1.2.1 → 1.3.0
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/README.en.md +2 -2
- package/README.md +2 -2
- package/lib/binding.js +86 -26
- package/lib/client.js +420 -152
- package/lib/forwards.js +18 -6
- package/lib/main.js +45 -12
- package/lib/mirror-paths.js +17 -0
- package/lib/registry.js +6 -1
- package/lib/routes-forwards.js +81 -10
- package/lib/update.js +55 -0
- package/package.json +2 -2
package/lib/forwards.js
CHANGED
|
@@ -207,22 +207,34 @@ export class ForwardManager {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
|
-
* Patch an existing definition's mutable fields and persist it.
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
210
|
+
* Patch an existing definition's mutable fields and persist it.
|
|
211
|
+
*
|
|
212
|
+
* Two callers share this: the row's 自动重连 checkbox patches only
|
|
213
|
+
* `autoStart`; the edit form sends the whole definition (direction, ports,
|
|
214
|
+
* target host, owning machine). Fields that are absent stay untouched — the
|
|
215
|
+
* route validates them first, so a typo never reaches this merge.
|
|
216
|
+
*
|
|
217
|
+
* It does NOT start or stop the tunnel. Changing a BIND of a running forward
|
|
218
|
+
* is refused by the route (the live socket would keep the old bind); toggling
|
|
219
|
+
* `autoStart` on a running forward is fine.
|
|
214
220
|
*
|
|
215
221
|
* @param {string} id
|
|
216
|
-
* @param {{autoStart?: boolean
|
|
222
|
+
* @param {{autoStart?: boolean, direction?: 'local'|'reverse', listenPort?: number,
|
|
223
|
+
* targetHost?: string, targetPort?: number, machineId?: string|null}} patch
|
|
217
224
|
* @returns {object|null} the updated definition, or null when the id is unknown.
|
|
218
225
|
*/
|
|
219
|
-
update(id, { autoStart } = {}) {
|
|
226
|
+
update(id, { autoStart, direction, listenPort, targetHost, targetPort, machineId } = {}) {
|
|
220
227
|
const d = this.defs.find((x) => x.id === id)
|
|
221
228
|
if (!d) return null
|
|
222
229
|
if (typeof autoStart === 'boolean') {
|
|
223
230
|
d.autoStart = autoStart
|
|
224
231
|
delete d.needsReconsent
|
|
225
232
|
}
|
|
233
|
+
if (direction === 'local' || direction === 'reverse') d.direction = direction
|
|
234
|
+
if (Number.isInteger(listenPort)) d.listenPort = listenPort
|
|
235
|
+
if (typeof targetHost === 'string' && targetHost) d.targetHost = targetHost
|
|
236
|
+
if (Number.isInteger(targetPort)) d.targetPort = targetPort
|
|
237
|
+
if (machineId !== undefined) d.machineId = machineId || null
|
|
226
238
|
this._save()
|
|
227
239
|
return d
|
|
228
240
|
}
|
package/lib/main.js
CHANGED
|
@@ -51,6 +51,7 @@ import { createInstructionIndex, formatInstructionIndex } from './instructions.j
|
|
|
51
51
|
import { resolveExecTimeout, formatExecResult, startExecJob, execWithOptionalPromotion } from './exec-job.js'
|
|
52
52
|
import { createInjectionTracker, refreshTouched, buildInstructionMessage, pickUserMessageFactory, loadBundledUserMessageFactory } from './instructions-dynamic.js'
|
|
53
53
|
import { REMOTE_SANDBOX_MODES, checkRemoteSandbox, remoteSandboxDenial } from './remote-sandbox.js'
|
|
54
|
+
import { mirrorConstrainLocalTarget, mirrorDownloadTarget, assertDownloadHasNoSymlinks } from './mirror-paths.js'
|
|
54
55
|
import { createTerminalManager } from './terminal.js'
|
|
55
56
|
import { createTerminalRoutes } from './routes-term.js'
|
|
56
57
|
import { searchRemote } from './search.js'
|
|
@@ -3116,34 +3117,51 @@ export async function apply(ctx, config) {
|
|
|
3116
3117
|
defineTool({
|
|
3117
3118
|
name: 'rw_download',
|
|
3118
3119
|
description:
|
|
3119
|
-
'Download a single remote file over SFTP into the local mirror of the current workspace
|
|
3120
|
+
'Download a single remote file over SFTP into the local mirror of the current workspace. Use when you need the actual file content locally, not just its text. Streams to disk (fastGet). The destination must stay inside that mirror, and the session sandbox must allow a write.',
|
|
3120
3121
|
parameters: {
|
|
3121
3122
|
path: { type: 'string', required: true, description: 'Absolute remote file path' },
|
|
3122
|
-
localPath: { type: 'string', description: '
|
|
3123
|
+
localPath: { type: 'string', description: 'Destination INSIDE the workspace mirror (default: the mirror path that preserves the remote relative path). Paths outside the mirror are refused.' },
|
|
3123
3124
|
},
|
|
3124
3125
|
output: okOut,
|
|
3125
3126
|
async execute(args, exec) {
|
|
3126
3127
|
const b = requireMachine(exec, 'rw_download')
|
|
3128
|
+
// Landing a file on THIS machine is a state change the session's
|
|
3129
|
+
// sandbox must have a say over: read-only refuses it outright, and
|
|
3130
|
+
// workspace-write keeps the remote source inside the workspace.
|
|
3131
|
+
requireRemoteSandbox(exec, 'write', { tool: 'rw_download', path: String(args.path || '') })
|
|
3127
3132
|
const p = resolveRemoteArg(b, args.path)
|
|
3128
3133
|
if (!p || p === '/') throw new Error('rw_download: a remote file path is required')
|
|
3129
|
-
const
|
|
3130
|
-
let
|
|
3131
|
-
if (
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3134
|
+
const ws = b.ws
|
|
3135
|
+
let base = b.mirrorDir || (ws ? mirrorDirFor(ws, b.host, b.username, b.port) : '')
|
|
3136
|
+
if (!ws || !base) throw new Error('rw_download: no remote workspace set — downloads land inside the local mirror of the workspace')
|
|
3137
|
+
// Both destination forms resolve inside the mirror with the same
|
|
3138
|
+
// grammar-aware mapping + symlink guard the HTTP download route applies
|
|
3139
|
+
// (routes-fs.js op=download): an unchecked local path can no longer
|
|
3140
|
+
// write outside the mirror or through a symlinked target.
|
|
3141
|
+
const local = args.localPath
|
|
3142
|
+
? mirrorConstrainLocalTarget(base, String(args.localPath))
|
|
3143
|
+
: mirrorDownloadTarget(base, ws, p)
|
|
3144
|
+
assertDownloadHasNoSymlinks(base, local)
|
|
3145
|
+
// Persist the mirror meta once downloads start landing here: the
|
|
3146
|
+
// registry lookup is only idempotent when the meta exists, and a
|
|
3147
|
+
// session opened inside this mirror binds to the machine through it.
|
|
3148
|
+
// Persist the mirror meta before landing anything: the directory
|
|
3149
|
+
// lookup is only idempotent once the meta exists, and a bare download
|
|
3150
|
+
// used to leave the dir anonymous — the next call would then resolve
|
|
3151
|
+
// to a hashed sibling and "move" the mirror. Also lets a session
|
|
3152
|
+
// opened inside this mirror bind back to the machine.
|
|
3153
|
+
if (!existsSync(path.join(base, '.dsh-remote-meta.json'))) {
|
|
3154
|
+
try { ensureMirror(ws, b.host, b.username, b.port) } catch { /* meta is an optimization, not a gate */ }
|
|
3139
3155
|
}
|
|
3140
3156
|
mkdirSync(path.dirname(local), { recursive: true })
|
|
3157
|
+
const sftp = await b.pool.sftp()
|
|
3141
3158
|
const st = await sftp.stat(p).catch(() => null)
|
|
3142
3159
|
if (config.maxFileBytes > 0 && st && st.size > config.maxFileBytes) {
|
|
3143
3160
|
throw new Error(`rw_download: file is ${st.size} bytes (over ${config.maxFileBytes} cap)`)
|
|
3144
3161
|
}
|
|
3145
3162
|
await sftp.fastGet(p, local)
|
|
3146
3163
|
const bytes = existsSync(local) ? statSync(local).size : 0
|
|
3164
|
+
audit('download', `download ${p} → ${local}`, 0, b)
|
|
3147
3165
|
return { ok: true, bytes, text: `downloaded ${bytes} bytes from ${p} → ${local}` }
|
|
3148
3166
|
},
|
|
3149
3167
|
}),
|
|
@@ -3872,6 +3890,20 @@ export async function apply(ctx, config) {
|
|
|
3872
3890
|
// alone, so a fresh registry stays "no choice yet" (not an
|
|
3873
3891
|
// explicit none) and a previously-cleared registry stays cleared.
|
|
3874
3892
|
saveMachines(machines, store.currentId, false)
|
|
3893
|
+
// Editing the ACTIVE machine must re-point the live pool, not just the
|
|
3894
|
+
// registry. The pool keeps the target it was APPLIED with, and every
|
|
3895
|
+
// forward start / rw_* call dials through it — so without this the settings
|
|
3896
|
+
// page showed the new address while 启动 still connected to the old one
|
|
3897
|
+
// ("ssh: connect to host <old>: Host is down"). setTarget() closes a live
|
|
3898
|
+
// connection only when an identity field actually changed.
|
|
3899
|
+
let poolWarning = ''
|
|
3900
|
+
if (!ephemeral && store.currentId === rec.id) {
|
|
3901
|
+
try {
|
|
3902
|
+
await applyActiveMachine()
|
|
3903
|
+
} catch (err) {
|
|
3904
|
+
poolWarning = String((err && err.message) || err)
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3875
3907
|
// Issue #67: an EDITED connection identity (host/user/port) must
|
|
3876
3908
|
// carry the machine's existing workspaces over — without this the
|
|
3877
3909
|
// mirrors stayed bound to the old address and the user had to
|
|
@@ -3923,6 +3955,7 @@ export async function apply(ctx, config) {
|
|
|
3923
3955
|
...(reboundMirrors ? { reboundMirrors } : {}),
|
|
3924
3956
|
...(warning ? { warning, warningDetail } : {}),
|
|
3925
3957
|
...(sshConfigWarning ? { sshConfigWarning } : {}),
|
|
3958
|
+
...(poolWarning ? { poolWarning } : {}),
|
|
3926
3959
|
}
|
|
3927
3960
|
}
|
|
3928
3961
|
|
package/lib/mirror-paths.js
CHANGED
|
@@ -32,3 +32,20 @@ export function assertDownloadHasNoSymlinks(base, target) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
|
|
36
|
+
// An explicit `localPath` argument (the rw_download tool surface) must land
|
|
37
|
+
// inside the same mirror the HTTP route writes into. Resolve it in the local
|
|
38
|
+
// grammar and refuse anything that would escape the root, alias the meta
|
|
39
|
+
// record, or smuggle Windows-unusable names — the same guarantees the
|
|
40
|
+
// remote-derived form gets from mirrorDownloadTarget.
|
|
41
|
+
export function mirrorConstrainLocalTarget(base, localPathArg, localPathApi = path) {
|
|
42
|
+
const root = localPathApi.resolve(base)
|
|
43
|
+
const target = localPathApi.resolve(String(localPathArg || ''))
|
|
44
|
+
const within = localPathApi.relative(root, target)
|
|
45
|
+
if (!within || localPathApi.isAbsolute(within) || within.split(localPathApi.sep).some(part => part === '..')) throw unsafeDownload()
|
|
46
|
+
const parts = within.split(localPathApi.sep)
|
|
47
|
+
// This local-only record determines the session's remote identity.
|
|
48
|
+
if (parts.length === 1 && (localPathApi.sep === '\\' ? parts[0].toLowerCase() : parts[0]) === '.dsh-remote-meta.json') throw unsafeDownload()
|
|
49
|
+
if (localPathApi.sep === '\\' && parts.some(part => /[<>:"|?*\\\x00-\x1f]/.test(part) || /[. ]$/.test(part) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part))) throw unsafeDownload()
|
|
50
|
+
return target
|
|
51
|
+
}
|
package/lib/registry.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// Keeping this logic in one module makes the guarantee unit-testable and
|
|
11
11
|
// shared between the HTTP routes and the tools (rw_connect).
|
|
12
12
|
|
|
13
|
-
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
|
|
13
|
+
import { readFileSync, writeFileSync, mkdirSync, chmodSync } from 'node:fs'
|
|
14
14
|
import path from 'node:path'
|
|
15
15
|
|
|
16
16
|
/** Load { list, currentId, explicitNone } from the registry file. */
|
|
@@ -56,6 +56,11 @@ export function saveMachines(file, list, currentId, keepCurrentKey = true) {
|
|
|
56
56
|
const payload = { list }
|
|
57
57
|
if (hasStored) payload.currentId = stored
|
|
58
58
|
writeFileSync(file, JSON.stringify(payload, null, 2))
|
|
59
|
+
// This file can carry plaintext credentials (password / passphrase under
|
|
60
|
+
// the default 'plain' backend), so keep it user-private — the same rule
|
|
61
|
+
// term-secret.json (main.js) and the ssh-config writer (routes-machines.js)
|
|
62
|
+
// already follow. A pre-existing looser mode is tightened on every save.
|
|
63
|
+
try { chmodSync(file, 0o600) } catch { /* Windows: the parent dir is already user-private */ }
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
/**
|
package/lib/routes-forwards.js
CHANGED
|
@@ -37,27 +37,98 @@ export function createForwardRoutes({ sendJson, readBody, forwards, store, activ
|
|
|
37
37
|
if (!Number.isInteger(targetPort) || targetPort < 1 || targetPort > 65535) {
|
|
38
38
|
return sendJson(res, 400, { ok: false, error: 'targetPort 必须是 1–65535 的整数' })
|
|
39
39
|
}
|
|
40
|
+
// Which host the tunnel belongs to. The settings form names it
|
|
41
|
+
// explicitly (`machineId`): a forward can be DEFINED for a host that
|
|
42
|
+
// is not connected right now — it simply cannot start until that host
|
|
43
|
+
// is. Omitting the field keeps the historical behaviour: tag what the
|
|
44
|
+
// ACTIVE POOL is actually on (ephemeral included), not the registry's
|
|
45
|
+
// currentId, because rw_connect(save:false) keeps currentId on the old
|
|
46
|
+
// machine while the pool talks to the new one.
|
|
47
|
+
//
|
|
48
|
+
// An explicit id must be a real registry record: persisting a typo
|
|
49
|
+
// would create a forward that no machine can ever start and that no
|
|
50
|
+
// UI row can explain.
|
|
51
|
+
let machineId = typeof activeMachineId === 'function' ? activeMachineId() : store.currentId
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(body, 'machineId') && body.machineId !== null && body.machineId !== '') {
|
|
53
|
+
const wanted = String(body.machineId)
|
|
54
|
+
const known = Array.isArray(store.list) && store.list.some((m) => m && m.id === wanted)
|
|
55
|
+
if (!known) return sendJson(res, 404, { ok: false, error: 'machine not found', forwards: forwards.list() })
|
|
56
|
+
machineId = wanted
|
|
57
|
+
}
|
|
40
58
|
const d = forwards.define({
|
|
41
59
|
direction: body.direction === 'reverse' ? 'reverse' : 'local',
|
|
42
60
|
listenPort,
|
|
43
61
|
targetHost: body.targetHost || '127.0.0.1',
|
|
44
62
|
targetPort,
|
|
45
63
|
autoStart: !!body.autoStart,
|
|
46
|
-
|
|
47
|
-
// not the registry's currentId: rw_connect(save:false) keeps
|
|
48
|
-
// currentId on the old machine while the pool talks to the new one.
|
|
49
|
-
machineId: typeof activeMachineId === 'function' ? activeMachineId() : store.currentId,
|
|
64
|
+
machineId,
|
|
50
65
|
})
|
|
51
66
|
return sendJson(res, 200, { ok: true, forward: d, forwards: forwards.list() })
|
|
52
67
|
}
|
|
53
68
|
if (action === 'update') {
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
// Partial patch: the row's 自动重连 checkbox sends only `autoStart`,
|
|
70
|
+
// the edit form sends the whole definition. Every field that IS
|
|
71
|
+
// present is validated; a missing field is left untouched (it must
|
|
72
|
+
// not silently reset anything). `autoStart`, when present, still has
|
|
73
|
+
// to be a real boolean.
|
|
74
|
+
const has = (k) => Object.prototype.hasOwnProperty.call(body, k)
|
|
75
|
+
const id = String(body.id || '')
|
|
76
|
+
const current = forwards.list().find((f) => f.id === id)
|
|
77
|
+
if (!current) return sendJson(res, 404, { ok: false, error: 'forward not found', forwards: forwards.list() })
|
|
78
|
+
const patch = {}
|
|
79
|
+
if (has('autoStart')) {
|
|
80
|
+
if (typeof body.autoStart !== 'boolean') {
|
|
81
|
+
return sendJson(res, 400, { ok: false, error: 'autoStart 必须是布尔值' })
|
|
82
|
+
}
|
|
83
|
+
patch.autoStart = body.autoStart
|
|
84
|
+
}
|
|
85
|
+
if (has('direction')) {
|
|
86
|
+
if (body.direction !== 'local' && body.direction !== 'reverse') {
|
|
87
|
+
return sendJson(res, 400, { ok: false, error: 'direction 只能是 local 或 reverse' })
|
|
88
|
+
}
|
|
89
|
+
patch.direction = body.direction
|
|
90
|
+
}
|
|
91
|
+
if (has('listenPort')) {
|
|
92
|
+
const p = Number(body.listenPort)
|
|
93
|
+
if (!Number.isInteger(p) || p < 1 || p > 65535) {
|
|
94
|
+
return sendJson(res, 400, { ok: false, error: 'listenPort 必须是 1–65535 的整数' })
|
|
95
|
+
}
|
|
96
|
+
patch.listenPort = p
|
|
97
|
+
}
|
|
98
|
+
if (has('targetPort')) {
|
|
99
|
+
// An empty target port means "same as the listen port", exactly
|
|
100
|
+
// like the add form.
|
|
101
|
+
const p = body.targetPort === '' || body.targetPort == null
|
|
102
|
+
? (patch.listenPort !== undefined ? patch.listenPort : current.listenPort)
|
|
103
|
+
: Number(body.targetPort)
|
|
104
|
+
if (!Number.isInteger(p) || p < 1 || p > 65535) {
|
|
105
|
+
return sendJson(res, 400, { ok: false, error: 'targetPort 必须是 1–65535 的整数' })
|
|
106
|
+
}
|
|
107
|
+
patch.targetPort = p
|
|
108
|
+
}
|
|
109
|
+
if (has('targetHost')) {
|
|
110
|
+
const host = String(body.targetHost || '').trim() || '127.0.0.1'
|
|
111
|
+
patch.targetHost = host
|
|
112
|
+
}
|
|
113
|
+
if (has('machineId')) {
|
|
114
|
+
if (body.machineId === null || body.machineId === '') {
|
|
115
|
+
patch.machineId = null
|
|
116
|
+
} else {
|
|
117
|
+
const wanted = String(body.machineId)
|
|
118
|
+
const known = Array.isArray(store.list) && store.list.some((m) => m && m.id === wanted)
|
|
119
|
+
if (!known) return sendJson(res, 404, { ok: false, error: 'machine not found', forwards: forwards.list() })
|
|
120
|
+
patch.machineId = wanted
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// A live tunnel keeps its OLD bind until it is torn down; editing it
|
|
124
|
+
// in place would show one port while the socket listens on another.
|
|
125
|
+
// Only the bind matters — 自动重连 may still be toggled while running.
|
|
126
|
+
const bindChanged = ['direction', 'listenPort', 'targetHost', 'targetPort', 'machineId']
|
|
127
|
+
.some((k) => k in patch && patch[k] !== (current[k] === undefined ? null : current[k]))
|
|
128
|
+
if (current.active && bindChanged) {
|
|
129
|
+
return sendJson(res, 409, { ok: false, error: '先停止这条转发再修改监听/目标/主机', forwards: forwards.list() })
|
|
59
130
|
}
|
|
60
|
-
const d = forwards.update(
|
|
131
|
+
const d = forwards.update(id, patch)
|
|
61
132
|
if (!d) return sendJson(res, 404, { ok: false, error: 'forward not found', forwards: forwards.list() })
|
|
62
133
|
return sendJson(res, 200, { ok: true, forward: d, forwards: forwards.list() })
|
|
63
134
|
}
|
package/lib/update.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// Every failure aborts without touching the installed files (a bad download or
|
|
23
23
|
// a version mismatch must never break the running plugin).
|
|
24
24
|
|
|
25
|
+
import { createHash } from 'node:crypto'
|
|
25
26
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
26
27
|
import { createRequire } from 'node:module'
|
|
27
28
|
import path from 'node:path'
|
|
@@ -140,6 +141,52 @@ export async function fetchLatestVersion(timeoutMs = 8000) {
|
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Fetch the npm metadata for one exact published version and return its
|
|
146
|
+
* `dist.integrity` (issue #169) — the SRI string the registry itself computed
|
|
147
|
+
* over the tarball bytes. This is the root of trust `applyUpdate` verifies
|
|
148
|
+
* the downloaded bytes against: TLS protects the transport, not the content.
|
|
149
|
+
*
|
|
150
|
+
* @param {string} version - exact published version.
|
|
151
|
+
* @param {Function} [fetchImpl] - fetch stand-in (tests inject here).
|
|
152
|
+
* @param {number} [timeoutMs] - watchdog budget; the caller does not await the timer.
|
|
153
|
+
* @returns {Promise<string>} the SRI string ("sha512-…").
|
|
154
|
+
*/
|
|
155
|
+
export async function fetchDistIntegrity(version, fetchImpl = fetch, timeoutMs = 15000) {
|
|
156
|
+
const controller = new AbortController()
|
|
157
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
158
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
159
|
+
try {
|
|
160
|
+
const res = await fetchImpl(`https://registry.npmjs.org/${NPM_PACKAGE}/${encodeURIComponent(version)}`, {
|
|
161
|
+
signal: controller.signal,
|
|
162
|
+
headers: { accept: 'application/vnd.npm.install-v1+json' },
|
|
163
|
+
})
|
|
164
|
+
if (!res.ok) throw new Error(`registry metadata returned HTTP ${res.status}`)
|
|
165
|
+
const data = await res.json().catch(() => null)
|
|
166
|
+
const integrity = data?.dist?.integrity
|
|
167
|
+
if (typeof integrity !== 'string' || !/^(sha512|sha256)-[A-Za-z0-9+/=]+$/.test(integrity)) {
|
|
168
|
+
throw new Error('registry metadata carries no usable dist.integrity')
|
|
169
|
+
}
|
|
170
|
+
return integrity
|
|
171
|
+
} finally { clearTimeout(timer) }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Verify downloaded bytes against an npm `dist.integrity` SRI string.
|
|
176
|
+
* Throws (never returns false) so a mismatch aborts the update before the
|
|
177
|
+
* tar is even gunzipped.
|
|
178
|
+
* @param {Buffer} buf - the downloaded tarball bytes.
|
|
179
|
+
* @param {string} integrity - SRI string from the registry metadata.
|
|
180
|
+
*/
|
|
181
|
+
export function assertIntegrity(buf, integrity) {
|
|
182
|
+
const [alg, expected] = String(integrity || '').split('-')
|
|
183
|
+
if ((alg !== 'sha512' && alg !== 'sha256') || !expected) {
|
|
184
|
+
throw new Error(`unsupported dist.integrity: ${integrity}`)
|
|
185
|
+
}
|
|
186
|
+
const actual = createHash(alg).update(buf).digest('base64')
|
|
187
|
+
if (actual !== expected) throw new Error(`tarball integrity mismatch: expected ${alg}-${expected}, got ${alg}-${actual}`)
|
|
188
|
+
}
|
|
189
|
+
|
|
143
190
|
/** Minimal POSIX ustar reader (regular files only) — npm tarballs are gzipped tar. */
|
|
144
191
|
function parseTar(buf) {
|
|
145
192
|
const files = []
|
|
@@ -188,6 +235,13 @@ export async function applyUpdate(targetVersion, options = {}) {
|
|
|
188
235
|
// Offline repair must not contact the registry at all.
|
|
189
236
|
buf = readFileSync(options.tarballPath)
|
|
190
237
|
} else {
|
|
238
|
+
// Supply-chain root (#169): take the registry's own dist.integrity for
|
|
239
|
+
// this exact version FIRST — an unknown or garbage version fails here
|
|
240
|
+
// without downloading anything, and the downloaded bytes must match it
|
|
241
|
+
// before a single byte is extracted. The version check further below
|
|
242
|
+
// reads the tarball's own package.json, which an attacker-controlled
|
|
243
|
+
// response can simply echo back; only this hash is external.
|
|
244
|
+
const integrity = options.integrity ?? await fetchDistIntegrity(targetVersion, doFetch)
|
|
191
245
|
const controller = new AbortController()
|
|
192
246
|
const timer = setTimeout(() => controller.abort(), 60000)
|
|
193
247
|
let res
|
|
@@ -198,6 +252,7 @@ export async function applyUpdate(targetVersion, options = {}) {
|
|
|
198
252
|
}
|
|
199
253
|
if (!res.ok) throw new Error(`download failed (HTTP ${res.status})`)
|
|
200
254
|
buf = Buffer.from(await res.arrayBuffer())
|
|
255
|
+
assertIntegrity(buf, integrity)
|
|
201
256
|
}
|
|
202
257
|
// npm tarballs are gzipped tar; extract the package/ directory.
|
|
203
258
|
const { gunzipSync } = await import('node:zlib')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "SSH remote workspaces for DeepSeek Harness: parallel projects across hosts, remote file browsing and editing, recursive search, terminals, Git diffs, and workspace-bound Agent tools to edit, build and test remotely. Optional IDE layout.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flymysql <flyphp@outlook.com>",
|
|
@@ -102,6 +102,6 @@
|
|
|
102
102
|
"test:coverage": "node scripts/coverage-union.mjs",
|
|
103
103
|
"test:coverage:gate": "node scripts/coverage-union.mjs --gate 70 --file-gate 60"
|
|
104
104
|
},
|
|
105
|
-
"readme": "[English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md) · **中文**\n\n# dsh-remote\n\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n[](https://github.com/topics/dsh-plugin)\n\n由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)\n\n\n\n在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:管理多主机项目,浏览和编辑远程文件、递归搜索文件与内容、使用终端、查看 Git 差异、建立本地/反向端口隧道;让 Agent 在所属远程工作区中读写文件、执行命令、构建和测试。多个工作区可独立并行。\n\n可按习惯使用普通布局,或切换 **IDE 三栏布局**,并排查看远程文件、编辑器与原生 Agent 会话;切换时保留任务和未保存编辑。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png\" alt=\"DSH 远程工作区 IDE 模式:远程文件树、代码编辑器和原生 Agent 会话三栏\" width=\"1200\"/>\n\n## 安装\n\n```bash\ndsh plugin --profile web add dsh-remote\n```\n\n安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。\n\n## 3 步开始\n\n1. **配置主机**:设置 → 远程工作区,编辑 SSH
|
|
105
|
+
"readme": "[English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md) · **中文**\n\n# dsh-remote\n\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n[](https://github.com/topics/dsh-plugin)\n\n由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)\n\n\n\n在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:管理多主机项目,浏览和编辑远程文件、递归搜索文件与内容、使用终端、查看 Git 差异、建立本地/反向端口隧道;让 Agent 在所属远程工作区中读写文件、执行命令、构建和测试。多个工作区可独立并行。\n\n可按习惯使用普通布局,或切换 **IDE 三栏布局**,并排查看远程文件、编辑器与原生 Agent 会话;切换时保留任务和未保存编辑。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png\" alt=\"DSH 远程工作区 IDE 模式:远程文件树、代码编辑器和原生 Agent 会话三栏\" width=\"1200\"/>\n\n## 安装\n\n```bash\ndsh plugin --profile web add dsh-remote\n```\n\n安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。\n\n## 3 步开始\n\n1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;直接写在 `~/.ssh/config` 里的 Host 会出现在主机列表中,点该行的「…」菜单 →「编辑」即可保存成机器并填写登录密码(保存前后入口都是同一个「…」菜单)。打开设置会自动检查连通性,无需手动“连接”。\n2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。\n3. **开始开发**:打开工作区文件或切换 IDE 模式,文件打开即可编辑并显示语法高亮,在远端搜索、运行命令并与 Agent 协作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-picker-browse.png\" alt=\"选择远程目录:固定路径与确认栏,目录列表占据弹窗主要区域\" width=\"720\"/>\n\n## 本地工作区也能用\n\n打开普通本地项目后,点击 **IDE 模式** 或 **工作区文件**,即可使用同一套文件树、高亮编辑、递归搜索、Git 差异与本地终端。无需配置 SSH;Agent 继续使用宿主原生文件和命令工具,多个本地、远程项目可并行工作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-local.png\" alt=\"本地工作区:文件搜索、高亮编辑和原生 Agent 会话,Agent 已实际完成本地构建\" width=\"1200\"/>\n\n## 日常开发\n\n### 搜索远端文件与内容\n\n文件、目录和内容递归搜索,无需先展开目录或同步镜像。默认界面只显示搜索范围与进度摘要;按需展开搜索选项、扫描详情,支持大小写、忽略项、停止与重试。点击结果进入目录或文件对应行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-search-results.png\" alt=\"简洁远程搜索:名称搜索结果包含嵌套目录与文件\" width=\"675\"/>\n\n### 查看远端 Git 改动\n\n分别查看工作区和已暂存 diff,筛选文件,点击改动行定位源码。面板只读,不提交或修改暂存区。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-git.png\" alt=\"远端 Git 工作区与已暂存改动、文件列表和源码 diff\" width=\"675\"/>\n\n### 在远端运行终端\n\n终端进入当前会话的远程目录;像素鱼欢迎图后接真实 SSH shell。已保存凭据可自动应答,支持多终端并行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-terminal.png\" alt=\"DSH 远程终端:像素鱼欢迎图与实际 SSH 命令输出\" width=\"1000\"/>\n\n### 端口转发(SSH 隧道)\n\n谁要发起访问,就在谁那边开监听口:监听口开在本机是本地转发(`ssh -L`),开在远端是远程转发(`ssh -R`)。可同时运行多条;添加转发时可以选择「主机」,每条转发只属于一台机器——给还没连接的主机也能先存下转发,连上后再启动。每条转发都可以点「编辑」调整方向、端口、目标或所属主机,运行中的会先停止、保存后按新配置重新启动。每行能直接勾选「自动重连」——只恢复上次运行中的转发,且按机器隔离,反向转发首次勾选会提示远端监听风险。\n\n从旧版本升级:旧版没有 `lastActive` 的「自动重连」配置会暂停,行上显示「需重新确认」;重新勾选后才会参与自动恢复(反向转发需重新确认远端监听)。\n\n<img src=\"docs/shots/port-forwards.png\" alt=\"端口转发面板:本地/反向方向、自动重连勾选框与添加转发表单\" width=\"900\"/>\n\n### 与 Agent 一起修改和构建\n\n工具卡展示已应用改动、实际退出码和构建输出,编译诊断可跳转源码。编辑器保存会检测远端冲突、保留 CRLF,并保护保存期间继续输入的内容。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-applied-diff.png\" alt=\"Agent 远程编辑成功后的已应用 diff、路径与增删行数\" width=\"485\"/>\n\n## 兼容与边界\n\n- 主要面向 **DSH Web 0.2.x**;0.2.2 需要 **Node.js ≥24.9**。旧版宿主回退、Desktop/TUI 与 Agent diff 差异见[兼容说明](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md#dsh-版本兼容性)。\n- 文件栏直接访问远端;镜像按需同步。草稿在当前页面内存,崩溃或强制退出仍可能丢失。\n- 不提供远端语言服务、扩展宿主或调试器。Agent 使用配置的 SSH 身份执行命令,请只配置可信主机。\n\n## 文档与社区\n\n[完整工具与配置参考](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md) · [排障](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [自更新修复](https://github.com/flymysql/dsh-remote/blob/main/docs/self-heal.md) · [升级指南](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [更新记录](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)\n\n[主页](https://flymysql.github.io/dsh-remote/) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [反馈问题](https://github.com/flymysql/dsh-remote/issues) · [贡献指南](https://github.com/flymysql/dsh-remote/blob/main/CONTRIBUTING.md) · [贡献者与致谢](#贡献者与致谢)\n\n由 [@flymysql](https://github.com/flymysql) 与社区共同维护 · [MIT](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n\n### 贡献者与致谢\n\n感谢每一位让这个项目更好的朋友(头像可点进主页;按提交数排序,机器人不计):\n\n<p align=\"left\">\n <a href=\"https://github.com/flymysql\"><img src=\"https://avatars.githubusercontent.com/u/37113068?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@flymysql\" title=\"@flymysql\" /></a>\n <a href=\"https://github.com/baiseraku\"><img src=\"https://avatars.githubusercontent.com/u/139727690?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@baiseraku\" title=\"@baiseraku\" /></a>\n <a href=\"https://github.com/glzhangzhi\"><img src=\"https://avatars.githubusercontent.com/u/36995275?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@glzhangzhi\" title=\"@glzhangzhi\" /></a>\n <a href=\"https://github.com/hjwsm1989\"><img src=\"https://avatars.githubusercontent.com/u/1067541?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@hjwsm1989\" title=\"@hjwsm1989\" /></a>\n <a href=\"https://github.com/j10ha0\"><img src=\"https://avatars.githubusercontent.com/u/72346906?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@j10ha0\" title=\"@j10ha0\" /></a>\n <a href=\"https://github.com/FoolishWiser\"><img src=\"https://avatars.githubusercontent.com/u/104308087?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FoolishWiser\" title=\"@FoolishWiser\" /></a>\n <a href=\"https://github.com/kakaa-nju\"><img src=\"https://avatars.githubusercontent.com/u/79886619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@kakaa-nju\" title=\"@kakaa-nju\" /></a>\n <a href=\"https://github.com/4FMTWRV\"><img src=\"https://avatars.githubusercontent.com/u/190457700?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@4FMTWRV\" title=\"@4FMTWRV\" /></a>\n <a href=\"https://github.com/dahaipeng\"><img src=\"https://avatars.githubusercontent.com/u/25660610?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@dahaipeng\" title=\"@dahaipeng\" /></a>\n <a href=\"https://github.com/davidlin2k\"><img src=\"https://avatars.githubusercontent.com/u/17074619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@davidlin2k\" title=\"@davidlin2k\" /></a>\n <a href=\"https://github.com/FlintyLemming\"><img src=\"https://avatars.githubusercontent.com/u/19165511?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FlintyLemming\" title=\"@FlintyLemming\" /></a>\n <a href=\"https://github.com/GDWhisper\"><img src=\"https://avatars.githubusercontent.com/u/129148123?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@GDWhisper\" title=\"@GDWhisper\" /></a>\n <a href=\"https://github.com/YiHui-Liu\"><img src=\"https://avatars.githubusercontent.com/u/30190271?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@YiHui-Liu\" title=\"@YiHui-Liu\" /></a>\n <a href=\"https://github.com/Minggle\"><img src=\"https://avatars.githubusercontent.com/u/35053182?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@Minggle\" title=\"@Minggle\" /></a>\n <a href=\"https://github.com/nekomona\"><img src=\"https://avatars.githubusercontent.com/u/25474483?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@nekomona\" title=\"@nekomona\" /></a>\n <a href=\"https://github.com/shis23\"><img src=\"https://avatars.githubusercontent.com/u/189869650?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@shis23\" title=\"@shis23\" /></a>\n</p>\n\n<details>\n<summary>贡献记录与早期贡献者</summary>\n\n近期的亮点贡献(欢迎随时加入这个名单):\n\n| 贡献者 | 做了什么 |\n| --- | --- |\n| [@baiseraku](https://github.com/baiseraku) | 整个 dsh-tui 适配层([#92](https://github.com/flymysql/dsh-remote/pull/92))+ 底栏机器名修正([#98](https://github.com/flymysql/dsh-remote/pull/98)) |\n| [@hjwsm1989](https://github.com/hjwsm1989) | 远程 .md 渲染连环两道:memo 守卫([#102](https://github.com/flymysql/dsh-remote/pull/102))+ labels 契约([#107](https://github.com/flymysql/dsh-remote/pull/107)) |\n| [@shis23](https://github.com/shis23) | rw_sync 路径映射纠偏 + SFTP 超时韧性([#105](https://github.com/flymysql/dsh-remote/pull/105)) |\n| [@davidlin2k](https://github.com/davidlin2k) | 无凭据机器走用户自有 ssh([#100](https://github.com/flymysql/dsh-remote/pull/100)) |\n| [@GDWhisper](https://github.com/GDWhisper) | 目录补全逐字符重连修复([#42](https://github.com/flymysql/dsh-remote/pull/42),issue #41) |\n| [@glzhangzhi](https://github.com/glzhangzhi) | 多远端会话的连接池隔离(issue #25 的主体修复) |\n\n早期已合并 PR 的贡献者(考古名单):\n\n\n\n[@dahaipeng](https://github.com/dahaipeng) (#31) ·\n[@YiHui-Liu](https://github.com/YiHui-Liu) (#28) ·\n[@nekomona](https://github.com/nekomona) (#24) ·\n[@zhz1667](https://github.com/zhz1667) (#43) ·\n[FoolishWiser](https://github.com/FoolishWiser) (#17) ·\n[@jace1cch](https://github.com/jace1cch) (#16) ·\n[@Minggle](https://github.com/Minggle) (#10) ·\n[4FMTWRV](https://github.com/4FMTWRV) (#6) ·\n[glzhangzhi](https://github.com/glzhangzhi)(per-session SSH 连接池修复)\n\n> 名单随版本更新;头像墙之外的每一份 issue 报告、复现步骤、根因线索同样珍贵——\n> 本仓库近半修复的起点都是一条写清楚的 issue。\n\n</details>\n",
|
|
106
106
|
"readmeFilename": "README.md"
|
|
107
107
|
}
|