Summary
A path traversal flaw in ChurchCRM's backup restore feature allows authenticated administrators to upload files with attacker-controlled names into the web-accessible filesystem.
By overwriting Apache .htaccess configuration files, an attacker can change web server behavior and potentially achieve remote code execution on the underlying server.
Affected context
The vulnerability occurs in ChurchCRM's backup restore functionality, specifically in src/ChurchCRM/Backup/RestoreJob.php, where uploaded backup files are written into /var/www/html/tmp_attach/ChurchCRMBackups/ using the user-controlled $rawUploadedFile['name'] parameter.
Affected instances are those where:
- The ChurchCRM application is deployed behind Apache (or a similar server honoring
.htaccess), - The web server process has write permissions to the backup directory or nearby paths,
- Administrative users can access the backup restore interface and upload files.
Exploit preconditions
- Attack surface: Web-based backup restore endpoint within the ChurchCRM administrative interface.
- Required access: Authenticated ChurchCRM account with administrator-level permissions or equivalent privileges to use backup restore.
- Trigger point: Submission of a crafted backup upload request where the
namefield of the uploaded file is manipulated to include path traversal sequences or targeted filenames such as.htaccess. - Why exploitation is possible: The server uses the unvalidated
$rawUploadedFile['name']parameter to construct filesystem paths, allowing traversal and overwriting of sensitive configuration files under the web root. Combined with the ability of.htaccessto modify execution rules, this can escalate into remote code execution.
Why this happens
The root cause is insufficient normalization and validation of user-controlled file names in the backup restore path, combined with overly permissive upload behavior.
The code in RestoreJob.php trusts $rawUploadedFile['name'] when constructing the destination path under /var/www/html/tmp_attach/ChurchCRMBackups/ without robust checks for:
- Path traversal sequences (e.g.,
../) that escape the intended directory (mapping to CWE-22: Improper Limitation of a Pathname to a Restricted Directory). - Restricting the set of allowable filenames, paths, and extensions to safe, expected backup formats (relating to CWE-434: Unrestricted Upload of File with Dangerous Type).
This insecure pattern turns an internal backup mechanism into a write-primitive for arbitrary files under the web server's control, enabling configuration tampering and code execution.
Potential impact
- Overwriting
.htaccessfiles to: - Enable execution of previously non-executable content,
- Route requests to malicious scripts,
- Bypass or weaken existing access controls.
- Remote code execution in the context of the web server process.
- Installation of persistent web shells or backdoors in the application directory.
- Tampering with application behavior, logging, and access control rules.
- Escalation from an application-level administrative account to full server compromise, depending on server configuration.
General mitigation guidance
Defensive measures should focus on constraining file paths, filenames, and upload semantics in the backup restore workflow:
- Enforce strict allowlists for destination directories and perform canonicalization of paths before any filesystem write, rejecting uploads if the resolved path escapes the intended backup directory.
- Replace user-provided filenames with server-generated names (e.g., based on UUIDs or timestamps) and maintain metadata separately, preventing user control over filesystem paths.
- Restrict acceptable file types and extensions to specific backup formats, and validate file contents where feasible rather than trusting client-supplied metadata.
- Ensure backup directories cannot influence server configuration: avoid storing uploads in locations where
.htaccessor other configuration files are evaluated, or disable.htaccessprocessing for upload paths. - Apply least-privilege to the web server's filesystem permissions so that it cannot overwrite configuration files or executable code outside designated data directories.
How teams detect issues like this
Detection efforts can combine code-based and operational monitoring approaches:
- Static analysis and code review:
- Search for use of user-controlled filename fields (e.g.,
$_FILES['...']['name']) directly in filesystem operations (move_uploaded_file,fopen,file_put_contents). - Flag concatenation of raw request parameters into file paths without normalization and checks against path traversal patterns.
- Review upload and backup-related code for absence of extension and directory allowlists, as well as missing checks against critical filenames (e.g.,
.htaccess,web.config,index.php). - Configuration and policy checks:
- Enforce policies that disallow
.htaccessprocessing in upload directories and ensure configuration files are immutable by the web server process. - Use infrastructure-as-code or configuration management tools to verify permission boundaries between application data and configuration/code.
- Runtime and log monitoring:
- Monitor web server and application logs for suspicious upload filenames containing traversal sequences or targeting known configuration files.
- Track unexpected changes to
.htaccessor other key configuration files using file integrity monitoring to detect potential exploitation early.

