{"id":"CVE-2026-54540","aliases":["GHSA-9643-6xjp-vx57"],"title":"Pheditor has an authenticated terminal command whitelist bypass","summary":"Pheditor has an authenticated terminal command whitelist bypass","severity":"high","cvss":8.8,"cwe":["CWE-78"],"vendor":"pheditor","product":"pheditor/pheditor","ecosystem":"composer","affected":["pheditor/pheditor <= 2.0.4"],"patched":["pheditor/pheditor 2.0.5"],"published":"2026-07-16","updated":"2026-07-16","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-9643-6xjp-vx57","references":[{"url":"https://github.com/pheditor/pheditor/security/advisories/GHSA-9643-6xjp-vx57"},{"url":"https://github.com/pheditor/pheditor/releases/tag/2.0.5"},{"url":"https://github.com/advisories/GHSA-9643-6xjp-vx57"}],"tags":["ghsa","composer"],"ingestedAt":"2026-07-16T20:58:03.065Z","epss":0.00712,"epssPercentile":0.5174,"slug":"CVE-2026-54540","body":"## Overview\n\n### Summary\n\nPheditor 2.0.4 has an authenticated terminal command whitelist bypass.\n\nThe terminal feature checks whether the submitted command starts with one of the configured `TERMINAL_COMMANDS` values, then passes the full command string to `shell_exec()`. Shell command substitution such as `$()` is not blocked, so an authenticated user with the `terminal` permission can bypass a restricted command allowlist and execute arbitrary shell commands as the web server user.\n\n### Details\n\nTested repository:\n\nhttps://github.com/pheditor/pheditor\n\nTested commit:\n\n`62b43df7cb8956a9b0deb9bec278ca8676c890c5`\n\nAffected version:\n\nPheditor 2.0.4\n\nRelevant code in `pheditor.php`:\n\n- The terminal handler receives `$_POST['command']` and stores it in `$command`.\n- It blocks only `&`, `;`, and `||`.\n- It checks whether `$command` starts with one of the configured values in `TERMINAL_COMMANDS`.\n- It then passes the full command string to `shell_exec()`.\n\nRelevant logic:\n\n```php\n$command = $_POST['command'];\n\nif (strpos($command, '&') !== false || strpos($command, ';') !== false || strpos($command, '||') !== false) {\n    echo json_error(\"Illegal character(s) in command (& ; ||)\\n\");\n    exit;\n}\n\nforeach ($terminal_commands as $value) {\n    $value = trim($value);\n\n    if (strlen($command) >= strlen($value) && substr($command, 0, strlen($value)) == $value) {\n        $command_found = true;\n        break;\n    }\n}\n\n$output = shell_exec((empty($dir) ? null : 'cd ' . escapeshellarg($dir) . ' && ') . $command . ' && echo \\ ; pwd');\n```\n\nBecause the whitelist check is prefix-based and the full command is executed by a shell, a command such as `ls$(...)` passes when `ls` is allowed, while the command substitution is still executed by the shell.\n\n### PoC\n\nThis was reproduced locally with Docker and PHP 8.3.\n\nFor a strict test, the configured command allowlist was changed to only allow `ls`:\n\n```php\ndefine('TERMINAL_COMMANDS', 'ls');\n```\n\nControl request:\n\n```text\ncommand=whoami\n```\n\nObserved result:\n\n```text\nCommand not allowed\nAvailable commands:\nls\n```\n\nBypass request:\n\n```text\ncommand=ls$(printf pheditor-terminal-bypass >/lab/app/site/proof.txt)\n```\n\nObserved result:\n\n```text\nproof.txt is created with the content:\npheditor-terminal-bypass\n```\n\nThis shows that even when only `ls` is allowed, arbitrary shell commands can still be executed through command substitution.\n\n### Impact\n\nAn authenticated user with the `terminal` permission can bypass the intended `TERMINAL_COMMANDS` restriction and execute arbitrary shell commands as the web server user.\n\nThis affects deployments where administrators rely on `TERMINAL_COMMANDS` to restrict terminal access to a small set of safe commands.\n\nSuggested fixes:\n\n- Avoid passing user-controlled command strings to `shell_exec()`.\n- Parse the command into executable and arguments.\n- Require an exact command name match instead of prefix matching.\n- Execute without a shell, for example with an argument-array based process API.\n- If shell execution remains necessary, reject shell metacharacters comprehensively, including command substitution syntax.\n- Consider disabling the terminal feature by default.\n\nReporter credit requested:\n\nshanjijian <shanjijian@gmail.com>\n\n## Affected packages\n\n- `pheditor/pheditor <= 2.0.4`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `pheditor/pheditor 2.0.5`","depth":"twilight","depthScore":49,"depthScoreParts":{"impact":48.4,"likelihood":0.1,"exploitation":0,"ransomware":0},"changes":[]}