Skip to content

Commit caf9d6c

Browse files
Copilotcute-omega
andauthored
Changes before error encountered
Agent-Logs-Url: https://github.com/docmirror/dev-sidecar/sessions/ef3b9305-d635-41a4-b7de-7d0e186f780d Co-authored-by: cute-omega <92797441+cute-omega@users.noreply.github.com>
1 parent 0863799 commit caf9d6c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

  • packages/core/src/shell/scripts/set-system-proxy

packages/core/src/shell/scripts/set-system-proxy/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,38 @@ async function getMacNetworkService (exec) {
280280
// macOS exit code 14 = "You don't have permission to change the system preferences."
281281
const MACOS_NETWORKSETUP_PERMISSION_ERROR_CODE = 14
282282

283+
/**
284+
* POSIX single-quote escaping: wraps `arg` in single quotes, escaping any
285+
* embedded single quotes with the '\''-idiom. This prevents shell
286+
* metacharacter expansion regardless of the character set of the value.
287+
* @param {string|number} arg
288+
* @returns {string}
289+
*/
290+
function shellEscapeArg (arg) {
291+
return "'" + String(arg).replace(/'/g, "'\\''") + "'"
292+
}
293+
294+
/**
295+
* Strict-validate a proxy host (IPv4 / IPv6 / hostname) and throw if the
296+
* value looks suspicious. This is a defence-in-depth guard for the sudo
297+
* execution path; the primary protection is `shellEscapeArg`.
298+
*/
299+
function validateProxyIp (ip) {
300+
if (typeof ip !== 'string' || !/^[\w.\-:[\]]+$/.test(ip)) {
301+
throw new Error(`无效的代理 IP 地址: ${ip}`)
302+
}
303+
}
304+
305+
/**
306+
* Strict-validate a TCP port number.
307+
*/
308+
function validateProxyPort (port) {
309+
const n = Number(port)
310+
if (!Number.isInteger(n) || n < 1 || n > 65535) {
311+
throw new Error(`无效的代理端口号: ${port}`)
312+
}
313+
}
314+
283315
function sudoExecMac (cmd) {
284316
return new Promise((resolve, reject) => {
285317
log.info('以管理员权限执行命令:', cmd)

0 commit comments

Comments
 (0)