/

CVE-2026-61873

Severity:

HIGH RISK

(8.1)

Arbitrary File Write (CWE-73) in Grav Form Plugin

CVE-2026-61873

Deferred

Vulnerability type

Category:

Arbitrary File Write / File System Manipulation

CWE:

CWE-73

Impact:

Arbitrary File Write and Potential Remote Code Execution

Severity:

HIGH RISK

(8.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

Grav's Form plugin allows attackers to write arbitrary files by abusing the process.save.filename parameter, which is only validated before Twig template rendering.

When user-controlled data with path traversal sequences passes through Twig and is not re-validated, it can result in files such as PHP webshells being written into the web root or other sensitive directories under vulnerable configurations.

Affected context

The vulnerability occurs in Grav installations that use the Form plugin with the process.save feature and dynamic filename values influenced by user input or form data.

Risk is elevated in environments where the application has write permissions to the web root or critical directories and Twig templates are used to construct file paths without performing a second round of path traversal validation after rendering.

Exploit preconditions

  • Attack surface: HTTP form submissions to pages using the Grav Form plugin with process.save enabled.
  • Required access: Ability to submit or modify form data (typically unauthenticated or low-privilege web access, depending on site configuration).
  • Trigger point: Processing of the process.save.filename parameter through Twig templates, followed by file creation or saving.
  • Why exploitation is possible: Path traversal checks are applied only to the pre-Twig filename value, while Twig rendering can reintroduce traversal sequences and arbitrary paths that are never re-validated before the file is written.

Why this happens

This issue stems from improper neutralization of alternate data streams and file paths when constructing file system locations from user-controlled input, mapping to CWE-73: External Control of File Name or Path.

The Form plugin validates the initial filename parameter for path traversal but then passes it through Twig templates, which can reintroduce attacker-controlled sequences into the rendered path.

Because the rendered filename is not subjected to a second validation step, the application treats Twig output as trusted, allowing externally controlled paths to be used for file writes.

Potential impact

  • Attackers may write arbitrary files to directories writable by the web application.
  • They could plant PHP webshells or other executable scripts in the web root, leading to remote code execution.
  • They can overwrite or tamper with existing application or configuration files, potentially causing denial of service or data corruption.
  • They may establish persistent backdoors or modify site content for defacement or phishing.

General mitigation guidance

Mitigation typically focuses on removing external control over file paths and enforcing strict, safe-by-default patterns for file writes.

Common defensive approaches include:

  • Ensuring that any filename derived from user input is constrained to an allowed directory and sanitized after all template or macro processing.
  • Performing path traversal checks and canonicalization on the final, rendered filename before writing files.
  • Avoiding direct use of user-controlled data in path construction; instead, mapping user choices to predefined identifiers or using server-generated names.
  • Running the application with least-privilege file system permissions so that it cannot write to the web root or other sensitive directories.
  • Designing form-processing pipelines so that templating engines like Twig cannot reintroduce unvalidated data into file paths.

How teams detect issues like this

Detection efforts can focus on both code and runtime behavior:

  • Static analysis rules that flag file write operations where paths are derived from HTTP request data or template-rendered values without subsequent validation or canonicalization.
  • Code reviews that look for patterns like process.save.filename or similar constructs where user input flows into Twig or other templating logic and then into file system APIs.
  • Security policies that require all file writes to use whitelisted directories and centralized helper functions that enforce path safety.
  • Runtime monitoring and file integrity checks to detect unexpected creations or modifications of files in the web root or configuration directories.
  • Optional use of automated security scanning tools that can probe form endpoints for path traversal behaviors and unexpected file creation.

Sources

SourceLink
github.comgithub.com/getgrav/grav/security/advisories/GHSA-q532-mvx7-42qg
vulncheck.comvulncheck.com/advisories/grav-before-arbitrary-file-write-via-twig-processed-filename

Frequently asked

questions

Exploitability depends on how forms are exposed and configured, but in many Grav deployments, attackers can submit form data over the web and potentially reach the vulnerable filename handling logic without special privileges.

Generally, an attacker needs only the ability to submit data to vulnerable forms. No direct file system or administrative access is required, although site-specific authentication controls may limit which forms can be targeted.

The safest pattern is to prevent user input from directly controlling file paths by using server-generated or enumerated filenames and validating the final, post-template-rendered path against a strict allowlist and directory constraints before any file write.

Adopt a secure file handling design that centralizes path construction, applies canonicalization and path traversal checks after all transformations, restricts writeable directories, and enforces these rules through code review, static analysis, and development guidelines.

Find out what's already
exploitable in your codebase.