Grav's Twig processing allowing dangerous PHP functions by default

Description

Impact

Twig processing of static pages can be enabled in the front matter by any administrative user allowed to create or edit pages.
As the Twig processor runs unsandboxed, this behavior can be used to gain arbitrary code execution and elevate privileges on the instance.

Patches

The issue was addressed by preventing dangerous functions from being called in Twig templates. A configuration option has been added to manually allow arbitrary PHP functions (system.twig.safe_functions) and filters (system.twig.safe_filters).

Futures major versions of Grav may disable this functionality by default.

Workarounds

Blocking access to the /admin path from untrusted sources will reduce the probability of exploitation.

References

  • https://portswigger.net/research/server-side-template-injection
  • https://blog.sonarsource.com/grav-cms-code-execution-vulnerabilities

For more information

If you have any questions or comments about this advisory, you can contact:
- The original reporters, by sending an email to vulnerability.research [at] sonarsource.com;
- The maintainers, by opening an issue on this repository.

Basic information

Type
reviewed
Severity
high
Advisory on GitHub
Open advisory ↗
Repository advisory
Open repository advisory ↗
Source code
Not specified
Published (advisory)
2021-04-16 19:53:12 UTC
Updated
2023-01-29 05:02:40 UTC
GitHub reviewed
2021-04-13 19:55:46 UTC
NVD published
2021-04-13

EPSS Score

Score Percentile
11.16% 93.50%

CVSS Scores

Base score Version Severity Vector
8.5 3.1
CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:H/I:H/A:H Click to expand
Attack vector (AV:N)
Could be attacked over the internet or any normal routed network—not just someone sitting at the machine.
Attack complexity (AC:L)
Once they can reach the bug, pulling it off is straightforward—no weird race conditions or rare setup.
Privileges required (PR:H)
They need powerful rights—admin, root, or similar—before this pays off.
User interaction (UI:R)
A real person has to do something—click, install, enable—otherwise it doesn’t land.
Scope (S:C)
Breaking this can reach past the original component and bite other resources—bigger blast radius.
Confidentiality (C:H)
Serious risk that confidential data gets exposed in a big way.
Integrity (I:H)
They could widely tamper with or forge data—trust in the data is badly hurt.
Availability (A:H)
Could take the service down hard or make it unusable for people who depend on it.

Identifiers

CWEs

CWE id Name
CWE-94 Improper Control of Generation of Code ('Code Injection')

Credits

  • thomas-chauchefoin-sonarsource (analyst)

Affected packages (1)

Vulnerable version ranges and first patched releases as published by GitHub.

Ecosystem Package Vulnerable range First patched Vulnerable functions
composer getgrav/grav <= 1.7.10 1.7.11

References

cvelogic Threat Intelligence