GHSA-9643-6XJP-VX57

Vulnerability from github – Published: 2026-07-16 20:01 – Updated: 2026-07-16 20:01
VLAI
Summary
Pheditor has an authenticated terminal command whitelist bypass
Details

Summary

Pheditor 2.0.4 has an authenticated terminal command whitelist bypass.

The 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.

Details

Tested repository:

https://github.com/pheditor/pheditor

Tested commit:

62b43df7cb8956a9b0deb9bec278ca8676c890c5

Affected version:

Pheditor 2.0.4

Relevant code in pheditor.php:

  • The terminal handler receives $_POST['command'] and stores it in $command.
  • It blocks only &, ;, and ||.
  • It checks whether $command starts with one of the configured values in TERMINAL_COMMANDS.
  • It then passes the full command string to shell_exec().

Relevant logic:

$command = $_POST['command'];

if (strpos($command, '&') !== false || strpos($command, ';') !== false || strpos($command, '||') !== false) {
    echo json_error("Illegal character(s) in command (& ; ||)\n");
    exit;
}

foreach ($terminal_commands as $value) {
    $value = trim($value);

    if (strlen($command) >= strlen($value) && substr($command, 0, strlen($value)) == $value) {
        $command_found = true;
        break;
    }
}

$output = shell_exec((empty($dir) ? null : 'cd ' . escapeshellarg($dir) . ' && ') . $command . ' && echo \ ; pwd');

Because 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.

PoC

This was reproduced locally with Docker and PHP 8.3.

For a strict test, the configured command allowlist was changed to only allow ls:

define('TERMINAL_COMMANDS', 'ls');

Control request:

command=whoami

Observed result:

Command not allowed
Available commands:
ls

Bypass request:

command=ls$(printf pheditor-terminal-bypass >/lab/app/site/proof.txt)

Observed result:

proof.txt is created with the content:
pheditor-terminal-bypass

This shows that even when only ls is allowed, arbitrary shell commands can still be executed through command substitution.

Impact

An authenticated user with the terminal permission can bypass the intended TERMINAL_COMMANDS restriction and execute arbitrary shell commands as the web server user.

This affects deployments where administrators rely on TERMINAL_COMMANDS to restrict terminal access to a small set of safe commands.

Suggested fixes:

  • Avoid passing user-controlled command strings to shell_exec().
  • Parse the command into executable and arguments.
  • Require an exact command name match instead of prefix matching.
  • Execute without a shell, for example with an argument-array based process API.
  • If shell execution remains necessary, reject shell metacharacters comprehensively, including command substitution syntax.
  • Consider disabling the terminal feature by default.

Reporter credit requested:

shanjijian shanjijian@gmail.com

Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 2.0.4"
      },
      "package": {
        "ecosystem": "Packagist",
        "name": "pheditor/pheditor"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "2.0.5"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-54540"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-78"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-07-16T20:01:05Z",
    "nvd_published_at": null,
    "severity": "HIGH"
  },
  "details": "### 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[\u0027command\u0027]` and stores it in `$command`.\n- It blocks only `\u0026`, `;`, 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[\u0027command\u0027];\n\nif (strpos($command, \u0027\u0026\u0027) !== false || strpos($command, \u0027;\u0027) !== false || strpos($command, \u0027||\u0027) !== false) {\n    echo json_error(\"Illegal character(s) in command (\u0026 ; ||)\\n\");\n    exit;\n}\n\nforeach ($terminal_commands as $value) {\n    $value = trim($value);\n\n    if (strlen($command) \u003e= strlen($value) \u0026\u0026 substr($command, 0, strlen($value)) == $value) {\n        $command_found = true;\n        break;\n    }\n}\n\n$output = shell_exec((empty($dir) ? null : \u0027cd \u0027 . escapeshellarg($dir) . \u0027 \u0026\u0026 \u0027) . $command . \u0027 \u0026\u0026 echo \\ ; pwd\u0027);\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(\u0027TERMINAL_COMMANDS\u0027, \u0027ls\u0027);\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 \u003e/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 \u003cshanjijian@gmail.com\u003e",
  "id": "GHSA-9643-6xjp-vx57",
  "modified": "2026-07-16T20:01:05Z",
  "published": "2026-07-16T20:01:05Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/pheditor/pheditor/security/advisories/GHSA-9643-6xjp-vx57"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/pheditor/pheditor"
    },
    {
      "type": "WEB",
      "url": "https://github.com/pheditor/pheditor/releases/tag/2.0.5"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Pheditor has an authenticated terminal command whitelist bypass"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…

Loading…