/

CVE-2026-40484

Severity:

CRITICAL RISK

(9.1)

Unrestricted File Upload / Arbitrary File Write

CVE-2026-40484

Deferred

Vulnerability type

Category:

Unrestricted File Upload / Arbitrary File Write

CWE:

CWE-269, CWE-434, CWE-552

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

ChurchCRM's backup restore feature can be abused to place attacker-controlled PHP files into a web-accessible directory with no file type or extension filtering.

An authenticated administrator, or an attacker leveraging CSRF against one, can upload a crafted backup archive that results in a webshell being deployed and executed remotely as the web server user.

Affected context

This vulnerability affects ChurchCRM deployments where the backup restore functionality is enabled and accessible to administrator accounts.

During restoration, archive contents are extracted and files from the Images/ directory are recursively copied into a web-accessible document root without validating file types, extensions, or execution risk.

The restore endpoint also does not enforce CSRF token checks, so exploitation may occur via a crafted web page if an administrator is logged in and has permission to restore backups.

Exploit preconditions

  • Attack surface: HTTP(S) interface exposing the ChurchCRM admin backup restore endpoint.
  • Required access:
  • Direct exploit: Authenticated ChurchCRM administrator with permission to perform backup restore operations, or
  • Indirect exploit: Ability to perform CSRF against an authenticated administrator's browser.
  • Trigger point: Uploading a specially crafted backup archive that includes a malicious PHP file inside the Images/ directory, then initiating a restore operation.
  • Why exploitation is possible:
  • The recursiveCopyDirectory() routine copies files from the extracted Images/ directory into the web root without any extension or MIME filtering.
  • The restored PHP file ends up in a publicly accessible path and can be invoked directly via HTTP, allowing arbitrary PHP code execution as the web server user.
  • Lack of CSRF token validation on the restore endpoint allows an attacker to trigger the restore workflow without the administrator's explicit intent.

Why this happens

The core issue is a combination of unrestricted file upload/placement and missing request integrity controls.

The restore mechanism trusts the contents and structure of uploaded backup archives and uses recursiveCopyDirectory() to move files from the Images/ directory into a web-accessible location without validating file types, disallowing executable content, or constraining destination paths.

This aligns with CWE-434: Unrestricted Upload of File with Dangerous Type, where user-controlled input is allowed to become an executable resource in the application's runtime environment.

Additionally, the absence of CSRF protection on the restore endpoint means state-changing operations can be triggered cross-origin, mapping to an authorization and request-forgery weakness rather than a single logic bug.

Together, these design flaws create a path from an authenticated or CSRF-coerced action to arbitrary code execution.

Potential impact

  • Remote execution of arbitrary PHP code as the web server user.
  • Installation of persistent webshells for ongoing access.
  • Access to and exfiltration of sensitive application and database data.
  • Tampering with or deletion of ChurchCRM records and stored assets.
  • Lateral movement within the hosting environment, depending on server configuration.
  • Use of the compromised site as a pivot point for further attacks on users or internal systems.

General mitigation guidance

Effective mitigation focuses on tightening file handling and strengthening request integrity for sensitive operations:

  • Restrict the types of files that can be restored into web-accessible directories, explicitly blocking executable extensions such as .php, .php5, .phtml, and similar.
  • Treat backup archives as untrusted input and validate extracted contents against an allowlist of safe directories and file extensions before copying.
  • Separate storage for user-restored content from executable code paths, for example by placing restored images and documents on non-executable volumes or behind indirect access mechanisms.
  • Enforce strong server-side CSRF protections on all state-changing administrative endpoints, including backup restore operations.
  • Apply least-privilege principles to the web server user so that, even if files are written, their ability to impact the broader system is constrained.
  • Log and monitor administrative backup and restore actions, including file paths affected, to support rapid detection and response to misuse.

How teams detect issues like this

Organizations can detect this class of issue and its exploitation using layered approaches:

  • Static analysis and code review:
  • Flag recursive directory copy utilities used in conjunction with user-uploaded archives, especially where destinations are web-accessible.
  • Identify file write operations that lack extension/mime checks or rely solely on client-side validation.
  • Verify that administrative endpoints performing state-changing actions invoke CSRF token validation and robust permission checks.
  • Configuration and policy enforcement:
  • Enforce web server rules that prevent execution of scripts from upload or media directories (e.g., disabling PHP execution in image or document paths).
  • Use security policies or frameworks that require explicit opt-in for executable locations.
  • Runtime and log-based monitoring:
  • Monitor web server logs for requests to unexpected .php files under image or upload directories.
  • Alert on unusual backup restore activity patterns or large numbers of files written into public directories.
  • Automated SAST/DAST and secure code review tools can be configured to highlight unrestricted file upload paths, missing CSRF protections, and executable content in public file trees.

Sources

SourceLink
github.comgithub.com/ChurchCRM/CRM/commit/68be1d12bc4cc1429575ae797ef05efe47030d39
github.comgithub.com/ChurchCRM/CRM/pull/8610
github.comgithub.com/ChurchCRM/CRM/security/advisories/GHSA-2932-77f9-62fx

Frequently asked

questions

Exploitation requires an authenticated administrator session to trigger the restore operation, but this can be achieved either by the attacker directly having admin credentials or by coercing an authenticated admin through CSRF. Once a malicious backup is restored, the attacker can run arbitrary code remotely.

Direct exploitation requires administrator-level access to the ChurchCRM interface with permission to restore backups. Indirect exploitation is possible if the attacker can get a logged-in administrator to visit a malicious page that issues a forged restore request, due to the missing CSRF validation.

Ensure that restored archives are processed as untrusted input: validate and strictly filter extracted files, block executable content from being written into web-accessible locations, and enforce non-executable storage for user-controlled files. Additionally, protect the restore endpoint with robust CSRF defenses and confirm that only intended administrators can invoke it.

Adopt secure design patterns for all upload and restore workflows: use allowlists for file types and destinations, segregate static content from executable code, and mandate CSRF and authorization checks for all administrative state-changing operations. Incorporate security review and automated analysis into development pipelines to catch unrestricted file write and missing-CSRF patterns before release.

Find out what's already
exploitable in your codebase.