The vulnerability allows arbitrary file reads through a path traversal weakness in the readFileFunc method within the Grav\Common\Twig\Extension\GravExtension class. This function is exposed to the Twig templating engine as the read_file function. The vulnerability description and Proof of Concept (PoC) show that an attacker with privileges to edit a page can create a form with a display field. The content of this field can be set to execute the read_file function with a path to a sensitive file on the server (e.g., /etc/passwd).
The provided commit ed640a13143c4177af013cf001969ed2c5e197ee directly patches the readFileFunc function. The original implementation simply checked if the file existed and then read it. The patch adds multiple security controls:
- It resolves the absolute path of the file using
realpath() to prevent traversal sequences like ../.
- It verifies that the resolved path is within the
GRAV_ROOT directory, restricting file access to the application's intended scope.
- It implements a blocklist of regular expressions to prevent access to sensitive files and directories such as user account files (
*.yaml), configuration files, and system directories.
Therefore, the readFileFunc is the exact location of the vulnerability, as it's the function that processes the malicious input (the file path) and performs the insecure file operation.