-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## Two handlers in the same dispatch table branch on the UUID. The third uses it as a label.\n\nThe three handlers live in the same object literal at `lib/server.js`. `_progress` starts on line 369:\n\n```js\n'_progress': function progressHandler(uri, body, request, response) {\n var uuid = getWorkerUuid(request);\n\n if (!uuid) {\n sendError(response, 'worker not found', 404);\n return;\n }\n ...\n```\n\n`_report` starts on line 405:\n\n```js\n'_report': function reportHandler(uri, body, request, response) {\n var uuid = getWorkerUuid(request);\n if (!uuid) {\n sendError(response, 'worker not found', 404);\n return;\n }\n ...\n```\n\n`_log` starts on line 491:\n\n```js\n'_log': function logHandler(uri, body, request, response) {\n var uuid = getWorkerUuid(request);\n var query = null;\n try {\n query = CircularJSON.parse(body);\n } catch (e) {\n query = body;\n }\n\n logger.trace('[%s] _log', ((uuid && workers[uuid]) || {}).id, query);\n ...\n```\n\nThe variable `uuid` in `_log` is referenced exactly once after assignment. The reference is `((uuid && workers[uuid]) || {}).id`, which `logger.trace` interpolates into the `%s` of the trace message. When no `X-Worker-UUID` header is sent, the expression evaluates to `undefined`, the trace prints `[undefined] _log ...`, and the handler continues. When a valid UUID is sent, the expression evaluates to the worker's id and the trace prints `[ie11-win10] _log ...`. Either way, the remaining 20 lines of the handler do not read the variable again.\n\nThe legitimate caller is patched into every test page by `lib/_patch/browserstack.js`, which wraps `console.log` and `console.warn` to POST `{ arguments: args }` to `/_log/` with `X-Worker-UUID` and `X-Browser-String` headers set from the query string of the test page URL. The credential is provisioned end to end. The cloud browser sends it. The server captures it. The handler binds it to a variable. The variable is the log-line label. This is the shape we are calling gate-was-decoration: the auth helper is in the source, the branch on the auth helper is not, and the only consumer of the call's return value is a string interpolation in a `logger.trace` argument.\n\n## The Node documentation says the vm module is not a sandbox. The comment above it says `safely`.\n\nThe 20 lines that follow the trace are the rest of the handler:\n\n```js\nif (query && Array.isArray(query.arguments)) {\n var context = { input: query.arguments, format: util.format, output: '' };\n var tryEvalOrString = 'function (arg) { try { return eval(\\'o = \\' + arg); } catch (e) { return arg; } }';\n\n try {\n // eval each element of query.arguments safely in an isolated context\n vm.runInNewContext('output = format.apply(null, input.map(' + tryEvalOrString + '));', context);\n logger.info('[' + request.headers['x-browser-string'] + '] ' + context.output);\n logged = true;\n } catch (e) {\n logger.debug('_log: failed to format console log data', query);\n }\n}\n```\n\nMechanically: take the JSON array `query.arguments` from the request body, map each element through a function that calls `eval('o = ' + arg)`, apply `util.format` to the resulting array, and assign the formatted string to `output`. The whole expression runs inside `vm.runInNewContext` with a context object containing the user input, the `util.format` function from Node's standard library, and an `output` slot for the result.\n\nThe comment on the line above `vm.runInNewContext` describes what the code is meant to do: `eval each element of query.arguments safely in an isolated context`. The word `safely` is the developer's belief about the construct they were writing. The Node.js documentation for `vm` is direct about that construct:\n\n> The vm module is not a security mechanism. Do not use it to run untrusted code.\n\nThe sentence sits at the top of every page of the `vm` module documentation. It is there because of the second mechanic of the `vm` context: any non-primitive value bound into the context, a Function, an Array, an Object created in the host realm, carries a reference back to its constructor, which carries a reference to the Function constructor in the host realm, which lets sandboxed code construct a function that runs in the host realm. The escape primitive is `this.constructor.constructor('return process')()`. The `_log` handler binds `util.format` into the context object as the `format` field. That binding alone is sufficient.\n\nThe advisory's PoC reads:\n\n```bash\ncurl -s http://127.0.0.1:8888/_log \\\n -H \"Content-Type: application/json\" \\\n -d '{\"arguments\":[\"this.constructor.constructor(\\\"return process.mainModule.require(`child_process`).execSync(`id`).toString()\\\")()\"]}'\n```\n\nThe runner's terminal prints `[undefined] uid=1000(user) gid=1000(user) ...`. The `[undefined]` is the worker id label, the consequence of `uuid` being null because the curl did not send the header. The variable did exactly what its only call site asked of it.\n\n## The `safely` comment shipped in February 2016. The CVE shipped in June 2026.\n\n`git log -L 491,523:lib/server.js` traces the handler's history through the commits that touched those lines.\n\n| Commit | Date | What the commit did to `_log` |\n|--------|------|-------------------------------|\n| `9888613` | 2015-10-23 | Handler born. Five lines. Logs the request body. No `getWorkerUuid` call. No `eval`. No `vm`. |\n| `4ab2993` | 2016-01-23 | `var uuid = getWorkerUuid(request);` added. Same commit added the same line to `_progress` and `_report`, both of which gated on it. `_log` did not. |\n| `1cb8deb` | 2016-02-08 | `vm.runInNewContext` call lands with the `safely` comment above it. Author wanted console.log of objects in the cloud browser to render as `{foo: 1}` in the runner's terminal instead of as the literal string `[object Object]`. The mechanism they reached for was `eval` wrapped in `vm`. |\n| `ad86ae8` | 2016-02-08 | `tryEvalOrString` refactored from a JS function (serialized via `.toString()`) to a literal source-string. The change makes the sandbox source more stable across Node versions; it does not touch the auth call. |\n| `e21a4b1` | 2017-01-27 | JSON parse error catches and falls back to `query = body`. The author touches the handler a third time. The `uuid` call is still on the first line. It is still not read. |\n| `1e85e55` | 2021-04-21 | Version 0.9.5 published to npm. Handler ships unchanged. |\n| `5ee5ad0` | 2023-07-03 | Repository's most recent commit. It is a `CODEOWNERS` file. No code touched. |\n| `CVE-2026-49143` | 2026-06-04 | GitHub Advisory Database lists \"Patched versions: None.\" |\n\nTen years and four months separate the author's belief that `vm` is a sandbox from the advisory that says it is not.\n\n## The advisory's remediation list is addressed to a project with no maintainer.\n\nThe advisory's three-item remediation reads:\n\n1. Remove `eval()` and `vm.runInNewContext()` from the `_log` handler, use `JSON.stringify()` for safe logging.\n2. Add UUID authentication to `_log` (matching `_progress` and `_report` handlers).\n3. Bind the HTTP server on `127.0.0.1` instead of `0.0.0.0`.\n\nItem 1 is the actual fix. Item 2 is the four-line check the two sibling handlers already have. Item 3 is the host argument that was never passed to `server.listen`:\n\n```js\n// bin/cli.js, line 131\nserver.listen(parseInt(config.test_server_port, 10));\n```\n\nNode's `http.Server#listen` documentation: \"If host is omitted, the server will accept connections on the unspecified IPv6 address (`::`) when IPv6 is available, or the unspecified IPv4 address (`0.0.0.0`) otherwise.\" The author wrote one argument. Node filled in the other.\n\nAll three items are fixes a maintainer would write in an afternoon. The `browserstack/browserstack-runner` repository's last commit landed on July 3, 2023. The last npm publish was 0.9.5 on April 21, 2021. The advisory was filed in June 2026. The Patched versions field reads `None`. The npm registry still serves the same tarball, and every developer who runs `npm install browserstack-runner` receives the code the author shipped in February 2016.\n\nThis is the same shape that has made browserstack-runner an exhibit on [The Detector Is The Target](/patterns/the-detector-is-the-target): the QA engineer's instrument becomes the attacker's foothold on the QA engineer's workstation, the way [Apktool's path-decoder bug](/posts/apktool-path-was-two-names) becomes the malware-analyst's foothold on the malware-analyst's. The blast radius is one developer laptop at a time. The prerequisite is one packet on the same LAN.\n\n## The threat model was \"BrowserStack will call this.\" The implementation was \"everyone on the LAN will call this.\"\n\nbrowserstack-runner exists because BrowserStack's cloud browsers, running in BrowserStack's data center, need to fetch the test HTML and JS that live on the developer's local filesystem. The product solves this with a local HTTP server (the runner, on port 8888) and a tunnel binary (`BrowserStackLocal`) that BrowserStack runs to forward requests from the cloud browser back to the dev's `localhost:8888`. The architecture's expected caller of `localhost:8888` is the tunnel, which is a localhost-only process on the dev's machine.\n\nThat is the threat model the `_log` handler was written under. The caller is a cloud browser. The cloud browser is on BrowserStack's side of the tunnel. The cloud browser is calling because the test it is running just executed `console.log({foo: 1})` and wants the runner to print that in the dev's terminal. Inside that threat model, `vm.runInNewContext` of attacker-controlled JavaScript is still wrong, but it is wrong against an attacker who already controls the cloud browser, which is a population of one: BrowserStack.\n\n`server.listen(8888)` with no host argument is not the implementation of that threat model. It is the implementation of \"any TCP client on any interface that can reach port 8888.\" On a developer's machine joined to a co-working space wireless network, that population includes every other person at the co-working space. On a CI runner sharing a Kubernetes node with other tenants, it includes every other pod on the node. On a hotel conference Wi-Fi the morning before a release, it includes every device in the conference. The CVSS vector reads `AV:A`, adjacent network, which is the polite phrasing of \"anyone the developer is sharing a broadcast domain with.\"\n\nWhat the attacker collects on a successful curl: the `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables (`lib/config.js` reads them at startup and they live in `process.env` for the life of the node process), the contents of the working directory, any AWS or GCP credentials the developer happened to have exported, the dev's SSH agent socket if it is forwarded, and whatever the dev's shell history says about what else they were doing this morning. The `_log` handler was written to print formatted console output. The same handler returns shell output formatted by `util.format`.\n\nPoC: [GHSA-6vr3-7wcx-v5g5](https://github.com/advisories/GHSA-6vr3-7wcx-v5g5)","closing_line":"The advisory shipped its remediation list in June 2026. The repository shipped its last commit in July 2023.","hook_md":"browserstack-runner is a Node CLI that QA engineers run on their laptops. It launches an HTTP server on port 8888, opens a BrowserStack tunnel to that server, and waits for cloud browsers to call back with test results. The dispatch table in `lib/server.js` has three handlers the cloud browsers post to: `_progress`, `_report`, and `_log`. The first two call `getWorkerUuid(request)` on the first line of the handler and send a 404 on the second if the return value is null.\n\n`_log` also calls `getWorkerUuid(request)` on the first line of the handler. It binds the return value to a variable named `uuid`. The variable's only consumer is the log-line label that follows.\n\nCVE-2026-49143 is what you get when the gate is in the code and the branch on the gate is not.","post_id":549,"slug":"browserstack-runner-cve-2026-49143-uuid-was-a-log-label","title":"CVE-2026-49143: browserstack-runner's _log Handler Called getWorkerUuid. The Return Value Was the Log Label.","type":"initial","unreadable_sentence":"The cloud browser sends the credential. The server captures it. The handler binds it to a variable. The variable is the log-line label."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaqMaNgAKCRDeZjl4jgkQ Ju+cAPwO3mrruMg0fg6rq7hl/CEuj3csS+/HG3RZYYg4jHqMhwEAt6KpKVk0yhnc L5cHFxPSP+oP7H7/LMXPcBm3uqt1zQw= =Y7z3 -----END PGP SIGNATURE-----