Summary
BrowserStack Runner through version 0.9.5 exposes a remote code execution vulnerability in its /_log HTTP handler, where user-controlled JSON fields are passed into vm.runInNewContext() and eval() without adequate isolation or validation.
An unauthenticated, network-adjacent attacker can craft malicious JSON payloads that escape the Node.js vm sandbox and execute arbitrary system commands in the host process context.
Affected context
The vulnerability manifests in BrowserStack Runner environments that:
- Expose the /_log HTTP endpoint over a network-accessible interface
- Accept JSON request bodies that are processed for logging or formatting
- Dynamically evaluate user-supplied data using vm.runInNewContext() combined with eval() or Function constructors
This typically occurs in Node.js-based logging or diagnostic components where convenience-based dynamic evaluation was added without treating request data as untrusted input.
Exploit preconditions
- Attack surface: The /_log HTTP handler reachable from the local network or any network segment where BrowserStack Runner is listening.
- Required access: No authentication is required; the attacker only needs network-adjacent access to send HTTP requests to the service.
- Trigger point: Submission of a specially crafted JSON request body to the /_log endpoint that flows into vm.runInNewContext() and then eval().
- Why exploitation is possible:
- User-controlled data is interpolated into dynamically evaluated code paths.
- The vm sandbox is bypassed by obtaining a host-context Function reference (e.g., via util.format) and then accessing this.constructor.constructor.
- There is no strong input validation or restriction of the execution context, allowing arbitrary JavaScript and OS-level operations to run in the host process.
Why this happens
This issue is rooted in unsafe dynamic evaluation of untrusted data, aligning with CWE-94: Improper Control of Generation of Code ('Code Injection').
The /_log handler treats request-supplied JSON fields as benign logging or formatting content but passes them into Node.js vm.runInNewContext() and eval(), creating executable code from attacker-controlled strings.
Although vm.runInNewContext() is intended to isolate execution, the code path exposes references (e.g., via util.format) that allow constructed functions to reference the outer, privileged context.
This pattern effectively merges untrusted data with interpreter-level capabilities, creating a direct channel from HTTP input to arbitrary code execution in the Node.js host environment.
Potential impact
- Full remote code execution on the underlying host running BrowserStack Runner.
- Reading, modifying, or deleting files accessible to the BrowserStack Runner process.
- Exfiltration of sensitive data such as credentials, test artifacts, or environment variables.
- Lateral movement by using the compromised host as a pivot into adjacent systems or CI infrastructure.
- Deployment of backdoors, malware, or persistent agents within the host environment.
General mitigation guidance
Effective mitigation focuses on eliminating unsafe dynamic evaluation and reducing the trust placed in log or diagnostic input:
- Remove use of eval(), new Function(), or equivalent dynamic code generation for processing log or request data.
- Avoid vm.runInNewContext() for untrusted input; if isolation is required, use hardened sandboxing mechanisms that do not expose host-object references and enforce explicit whitelists for accessible APIs.
- Treat all HTTP request data, including log messages and metadata, as untrusted and subject it to strict validation and sanitization.
- Refactor logging and formatting to use static templates with variable substitution that does not construct executable code.
- Run BrowserStack Runner with least-privilege OS accounts, constrained file system access, and minimal network permissions to limit blast radius if similar bugs occur.
- Place sensitive diagnostic endpoints behind strong authentication, access control lists, or internal-only interfaces.
How teams detect issues like this
Detection can be approached through a combination of code-centric and operational techniques:
- Static analysis and code scanning:
- Flag uses of eval(), new Function(), or vm.runInNewContext() where arguments are derived from HTTP request bodies, query parameters, headers, or other untrusted sources.
- Detect patterns where util.format or similar formatting utilities combine untrusted data with code fragments.
- Enforce linting rules or security policies that prohibit unsafe dynamic evaluation in production code.
- Code review practices:
- Treat any use of dynamic evaluation APIs as high-risk and require explicit security approval.
- Review logging, debugging, and "internal tooling" endpoints with the same rigor as main application endpoints, focusing on how they handle user input.
- Runtime and operational detection:
- Monitor logs for anomalous payloads targeting the /_log endpoint, such as JavaScript code fragments or unusual format strings.
- Use application-layer firewalls or API gateways to enforce schemas on JSON inputs and block obviously malicious patterns.
- Integrate automated security testing (e.g., DAST tools) into CI/CD to probe exposed endpoints for code injection behavior.

