- Location
- scripts/index.js:88
- Finding
- Interactive Command Routing Bypasses Safety Classification<![CDATA[
## Vulnerability Details
**File Location**: `scripts/index.js:88-95`
**Vulnerability Type**: Safety-gate bypass and shell injection through interactive command handling
**Risk Level**: Critical
### Vulnerable Code
Interactive detection is performed before normal detection and dangerous-command analysis:
```javascript
function handleInput(input) {
// First check if it's an interactive command
if (isInteractiveCommand(input)) {
return {
action: 'interactive',
message: `🔧 检测到交互式命令,正在打开新终端窗口...`,
command: input
};
}
const detection = detectCommand(input);
```
Several patterns allow unrestricted trailing content:
```javascript
const interactivePatterns = [
/^adb\s+shell\s*$/,
/^ssh\s+/,
/^docker\s+exec\s+-it\s+/,
/^docker\s+attach\s+/,
/^mysql\s+/,
/^psql\s+/,
/^sqlite3\s+/,
/^mongo\s+/,
/^redis-cli\s*/,
/^ftp\s+/,
/^sftp\s+/,
/^telnet\s+/,
/^nc\s+/,
/^screen\s+/,
/^tmux\s+/,
/^bash\s*$/,
/^sh\s*$/,
/^zsh\s*$/,
/^python\s*$/,
/^python3\s*$/,
/^node\s*$/,
/^irb\s*$/,
];
```
The resulting input is later concatenated into shell text:
```javascript
function openInteractiveShell(command) {
const platform = os.platform();
const initCmd = getShellInitCommand();
const fullCommand = initCmd + command;
```
On macOS, that string is also inserted into AppleScript source:
```javascript
const appleScript = `
tell app "Terminal"
activate
do script "${fullCommand}"
end tell
`;
const osa = spawn('osascript', ['-e', appleScript]);
```
On Windows, shell processing is explicitly enabled:
```javascript
const cmd = `start cmd /k "${fullCommand}"`;
spawn('cmd', ['/c', cmd], { detached: true, shell: true });
```
### Technical Analysis
Broad prefix expressions classify any input beginning with strings such as `ssh `, `nc `, or `mysql ` as interactive. The handler returns before `detectCommand()` and `isDangerous()` run. The original unparsed input is then interpreted as
...[truncated 1560 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
- Run dangerous-command validation before interactive-command classification.
- Reject shell operators, substitutions, control characters, and redirections in interactive commands.
- Parse each supported interactive command into a program and argument array.
- Launch commands with `spawn(program, args, { shell: false })`.
- Replace broad prefix expressions with strict grammars for explicitly supported argument forms.
- Avoid embedding command text in AppleScript. If Terminal automation is unavoidable, pass data through a safely quoted mechanism rather than constructing AppleScript source.
- Remove `shell: true` from Windows execution and use direct process argument arrays.
- Require explicit user approval before opening remote sessions or network listeners.
- Preserve an audit record containing the exact executable, normalized argument list, destination, process identifier, and exit status.
- Add cross-platform tests for appended `;`, `&&`, `|`, newlines, quotes, `$()`, backticks, and AppleScript escape sequences.
]]>