Skip to main content

Boteraser | Website and Server Security Solutions

🛡️ CVE-2023-34252 — grav

🟠 CVSS 8.8 — High ✅ No Known Exploit CWE-1336 NVD
8.8
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

Grav Server-side Template Injection (SSTI) via Twig Default Filters

Hi,

actually we have sent the bug report to [security@getgrav.org](mailto:[email protected]) on 27th March 2023 and on 10th April 2023.

# Grav Server-side Template Injection (SSTI) via Insufficient Validation in filterFilter

Summary:

| Product | Grav CMS |

| ----------------------- | --------------------------------------------- |

| Vendor | Grav |

| Severity | High - Users with login access to Grav Admin panel and page creation/update permissions are able to obtain remote code/command execution |

| Affected Versions | <= [v1.7.40](https://github.com/getgrav/grav/tree/1.7.40) (Commit [685d762](https://github.com/getgrav/grav/commit/685d76231a057416651ed192a6a2e83720800e61)) (Latest version as of writing) |

| Tested Versions | v1.7.40 |

| Internal Identifier | STAR-2023-0007 |

| CVE Identifier | TBD |

| CWE(s) | CWE-20: Improper Input Validation, CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine |

CVSS3.1 Scoring System:

Base Score: 7.2 (High)

Vector String: CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

| Metric | Value |

| ---------------------------- | --------- |

| Attack Vector (AV) | Network |

| Attack Complexity (AC) | Low |

| Privileges Required (PR) | High |

| User Interaction (UI) | None |

| Scope (S) | Unchanged |

| Confidentiality \(C) | High |

| Integrity (I) | High |

| Availability (A) | High |

Product Overview:

Grav is a PHP-based flat-file content management system (CMS) designed to provide a fast and simple way to build websites. It supports rendering of web pages written in Markdown and Twig expressions, and provides an administration panel to manage the entire website via an optional Admin plugin.

Vulnerability Summary:

There is a logic flaw in the GravExtension.filterFilter() function whereby validation against a denylist of unsafe functions is only performed when the argument passed to filter is a string. However, passing an array as a callable argument allows the validation check to be skipped. Consequently, a low privileged attacker with login access to Grav Admin panel and page creation/update permissions is able to inject malicious templates to obtain remote code execution.

Vulnerability Details:

The vulnerability can be found in the GravExtension.filterFilter() function declared in [/system/src/Grav/Common/Twig/Extension/GravExtension.php](https://github.com/getgrav/grav/blob/1.7.40/system/src/Grav/Common/Twig/Extension/GravExtension.php#L1692-L1698):

~~~php

...

class GravExtension extends AbstractExtension implements GlobalsInterface

{

...

/**

  • Return a list of all filters.

*

  • @return array

*/

public function getFilters(): array

{

return [

...

// Security fix

new TwigFilter('filter', [$this, 'filterFilter'], ['needs_environment' => true]),

];

}

...

/**

  • @param Environment $env
  • @param array $array
  • @param callable|string $arrow
  • @return array|CallbackFilterIterator
  • @throws RuntimeError

*/

function filterFilter(Environment $env, $array, $arrow)

{

if (is_string($arrow) && Utils::isDangerousFunction($arrow)) { // [1]

throw new RuntimeError('Twig |filter("' . $arrow . '") is not allowed.');

}

return \twig_array_filter($env, $array, $arrow); // [2]

}

}

~~~

At [1], the $arrow parameter contains the argument supplied to the filter. For example, it may refer to "funcname" in {{ array|filter("funcname") }} or the closure (a.k.a. arrow function) el => el != 'exclude' in {{ array|filter(el => el != 'exclude') }}. Observe that Utils::isDangerousFunction($arrow) is only invoked if $arrow is a string. As such, non-string arguments may be passed to twig_array_filter() at [2] due to the absence of type enforcement at [1].

The implementation of the twig_array_filter() function can be found in [/src/Extension/CoreExtension.php](https://github.com/twigphp/Twig/blob/v1.44.7/src/Extension/CoreExtension.php) within Twig's codebase:

~~~php

function twig_array_filter(Environment $env, $array, $arrow)

{

if (!twig_test_iterable($array)) {

throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));

}

if (!$arrow instanceof Closure && $env->hasExtension('\Twig\Extension\SandboxExtension') && $env->getExte

How this vulnerability can be exploited

This issue can be reached over the network, attack complexity is low, an attacker needs low-level privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality high, integrity high, availability high.

CVSS metrics in full

The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

  • Attack vector: Network — reachable from anywhere that can route to the service.
  • Attack complexity: Low — the attack works reliably, with no preparation.
  • Privileges required: Low — an ordinary user account is enough.
  • User interaction: None — nobody has to be tricked into anything.
  • Scope: Unchanged — the damage stays inside the vulnerable component.
  • Confidentiality impact: High — total loss, or loss the attacker controls.
  • Integrity impact: High — total loss, or loss the attacker controls.
  • Availability impact: High — total loss, or loss the attacker controls.

Weakness class

CVE-2023-34252 is classified as CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine. The product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when…

Affected software

CVE-2023-34252 is recorded against 2 packages.

  • getgrav/grav (fixed in 1.7.42)
  • grav (fixed in 1.7.42)

Timeline and source

Published on 16 June 2023 and last revised on 16 February 2024. No public exploit is currently recorded for this entry. A vendor advisory or fix has been published. Record sourced from NVD.

References

github.com (Web)
nvd.nist.gov (Advisory)
github.com (Web)
github.com (Web)
github.com (Web)
github.com (Web)
github.com (Package)
github.com (Web)
github.com (Web)

Other advisories for this package

getgrav/grav has other advisories on record. If you are patching this one, these are worth checking on the same host:

Same weakness in other software

These advisories are the same class of weakness (CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine) in other software:

Details

Severity HIGH
CVSS Score 8.8
CVSS Vector CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
CWE CWE-1336
Public Exploit ✅ No
Source NVD
Published 2023-06-16
Updated 2026-08-20
Modified 2024-02-16

Affected Packages

Software From version Fixed in
getgrav/grav 1.7.42
grav 1.7.42

Similar Threats

Site Security Check

Is grav part of your stack?

CVE-2023-34252 is rated CVSS 8.8 High. BotEraser scans your installation against known CVE records and tells you whether this vulnerability applies to the versions you actually run.

Scan My Site Free →

No credit card required  ·  Results in minutes

ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.

Browse related advisories

All advisoriesCVECVE 2023