Summary
baserCMS has a path traversal flaw in its theme-file API: when a selected theme subdirectory does not exist, a failed realpath() can cause the path containment check to be skipped. An authenticated administrator may exploit this behavior to access paths outside the theme directory, potentially allowing file changes within the PHP process's permissions and, in some circumstances, remote code execution.
Affected context
The issue is in BcThemeFileService::getFullpath() in the theme-file plugin. It affects baserCMS releases from 5.2.3 up to, but not including, 5.3.0 when a theme-file API request selects a nonexistent theme subdirectory and the resulting path is not contained within the intended theme directory.
Exploit preconditions
- Attack surface: The baserCMS theme-file API
- Required access: An authenticated administrator able to submit requests to the API
- Trigger point: Path resolution for a theme-file operation using a
typevalue that selects a nonexistent subdirectory - Why exploitation is possible: If
realpath()fails, the containment check may be skipped, allowing a traversal path to resolve outside the theme directory
Why this happens
The path validation logic depends on successful canonicalization with realpath(). When canonicalization fails for a nonexistent subdirectory, the containment check is bypassed rather than rejecting the path. This is a path traversal weakness mapped to CWE-22, where input used to construct a file path is not reliably constrained to its intended directory.
Potential impact
- An attacker may write, overwrite, or delete files accessible to the PHP process outside the theme directory.
- Application files or configuration may be altered, depending on filesystem permissions.
- Remote code execution could occur if the attacker can place executable PHP in a location where it is served or run.
General mitigation guidance
Defensive patterns for this class of issue include:
- Rejecting paths when canonicalization fails, rather than skipping containment checks.
- Constraining file operations to an allowlisted set of names and directories.
- Validating resolved paths against a trusted base directory for every operation.
- Avoiding reliance on user-controlled path components, including values such as
type. - Running the PHP process with only the filesystem permissions required for normal operation.
How teams detect issues like this
- Use static analysis to identify file operations whose paths incorporate request-controlled values and whose containment checks depend on successful canonicalization.
- Review error paths around
realpath()and confirm that failed resolution results in rejection. - Check that read, write, overwrite, and delete operations all enforce the same trusted-directory boundary.
- Apply code-review or CI policies that flag filesystem paths built from API input without robust allowlisting and containment validation.

