Skip to content

Commit ec5553b

Browse files
claude-code-bestglm-5.2
andcommitted
fix: bypass 模式在 root/sudo 下改为警告 + y 确认而非直接退出
交互式 TTY 下打印风险警告并等待用户输入 y 才进入 bypass 模式; 非 TTY (pipe/ACP/CI) 维持原 exit(1) 行为,因为无法交互确认。 Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
1 parent dc8d488 commit ec5553b

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

src/setup.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,39 @@ export async function setup(
401401
process.env.IS_SANDBOX !== '1' &&
402402
!isEnvTruthy(process.env.CLAUDE_CODE_BUBBLEWRAP)
403403
) {
404-
console.error(
405-
`--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons`,
406-
)
407-
process.exit(1)
404+
// Root + bypass = every tool call executes without review at uid 0.
405+
// Interactive TTY: warn and require explicit "y" to proceed.
406+
// Non-interactive (pipe, ACP, CI, no TTY): cannot prompt, must abort.
407+
if (process.stdin.isTTY) {
408+
console.error(
409+
chalk.bold.red(
410+
'WARNING: Running as root/sudo with bypass permissions mode is dangerous.',
411+
),
412+
)
413+
console.error(
414+
chalk.yellow(
415+
'Bypass mode skips ALL permission checks. Combined with root, any command (rm -rf /, chmod, dd) executes without review.',
416+
),
417+
)
418+
const readline = await import('readline')
419+
const rl = readline.createInterface({
420+
input: process.stdin,
421+
output: process.stdout,
422+
})
423+
const answer = await new Promise<string>(resolve => {
424+
rl.question('\nI understand the risks. Continue? [y/N] ', resolve)
425+
})
426+
rl.close()
427+
if (answer.trim().toLowerCase() !== 'y') {
428+
console.error('Aborted.')
429+
process.exit(1)
430+
}
431+
} else {
432+
console.error(
433+
`--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons`,
434+
)
435+
process.exit(1)
436+
}
408437
}
409438

410439
if (

0 commit comments

Comments
 (0)