Summary
@rhinostone/swig: arbitrary local file read via include/extends path traversal
Overview
@rhinostone/swig is a maintained fork of the abandoned swig template engine and inherited the directory-traversal vulnerability tracked upstream as CVE-2023-25345 / GHSA-2rq5-699j-x7p6. The {% include %}, {% extends %}, and {% import %} tags resolve their target path through the filesystem loader without confining the result to the configured template root. A path that traverses upward (../) escapes the root and reads an arbitrary file from the host filesystem, whose contents are emitted into the rendered output.
Attack scenario
The dangerous case does not require the attacker to control template source, only template data (the locals passed at render time). An application that renders a trusted template whose include / extends path is variable-driven is exposed:
// application code, a configured filesystem loader with a basepath
swig.renderFile('page.html', { partial: req.query.partial });
{# page.html, trusted template #}
{% include partial %}
Setting ?partial=../../../../etc/passwd makes the loader resolve and read that file, and its contents are rendered into the response. A literal in trusted source is equally affected: {% include "../../../etc/passwd" %}.
Affected & patched
Every published version up to and including 2.7.0 is affected, @rhinostone/swig, and the shared @rhinostone/swig-core loader, hence @rhinostone/swig-twig, @rhinostone/swig-jinja2, and @rhinostone/swig-django as well.
Fixed in 2.7.1: the filesystem loader now rejects any include / extends / import path that resolves outside the configured basepath root, including paths supplied through an untrusted runtime variable. A new allowOutsideRoot loader option is available for the rare case of intentionally reading files from outside the root.
Upgrade to 2.7.2 or later: 2.7.1 fixed the vulnerability but introduced a regression, a relative basepath wrongly rejected every in-root template path. 2.7.2 resolves the basepath to an absolute path before the check and restores correct in-root resolution.
Workarounds
- Upgrade to
2.7.2(or later). - If you cannot upgrade immediately: configure the filesystem loader with an explicit
basepath, and never pass untrusted data into an{% include %}/{% extends %}/{% import %}path.
References
- GHSA-2rq5-699j-x7p6, https://github.com/advisories/GHSA-2rq5-699j-x7p6
- CVE-2023-25345 (NVD), https://nvd.nist.gov/vuln/detail/CVE-2023-25345
- Upstream issue (swig-templates), https://github.com/node-swig/swig-templates/issues/88
- Fix commit, https://github.com/gina-io/swig/commit/381bdc305e0b10e45368d56324328b9b4f7017fc
Impact
Arbitrary local file disclosure (confidentiality). An attacker able to influence an include / extends / import path, directly, or via untrusted locals, can read files outside the template directory: application configuration, credentials, source code, /etc/passwd, and so on. There is no integrity or availability impact.
Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files. Typical impact: unauthorized file read or write outside the intended directory.
GHSA-2MF3-MR2R-R4VF has a CVSS score of 7.5 (High). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (2.7.1); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
@rhinostone/swig to 2.7.1 or later; @rhinostone/swig-core to 2.7.1 or later; @rhinostone/swig-twig to 2.7.1 or later; @rhinostone/swig-jinja2 to 2.7.1 or later; @rhinostone/swig-django to 2.7.1 or later
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is GHSA-2MF3-MR2R-R4VF? GHSA-2MF3-MR2R-R4VF is a high-severity path traversal vulnerability in @rhinostone/swig (npm), affecting versions < 2.7.1. It is fixed in 2.7.1. Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files.
- How severe is GHSA-2MF3-MR2R-R4VF? GHSA-2MF3-MR2R-R4VF has a CVSS score of 7.5 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which packages are affected by GHSA-2MF3-MR2R-R4VF?
@rhinostone/swig(npm) (versions < 2.7.1)@rhinostone/swig-core(npm) (versions < 2.7.1)@rhinostone/swig-twig(npm) (versions < 2.7.1)@rhinostone/swig-jinja2(npm) (versions < 2.7.1)@rhinostone/swig-django(npm) (versions < 2.7.1)
- Is there a fix for GHSA-2MF3-MR2R-R4VF? Yes. GHSA-2MF3-MR2R-R4VF is fixed in 2.7.1. Upgrade to this version or later.
- Is GHSA-2MF3-MR2R-R4VF exploitable, and should I be worried? Whether GHSA-2MF3-MR2R-R4VF is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether GHSA-2MF3-MR2R-R4VF is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix GHSA-2MF3-MR2R-R4VF?
- Upgrade
@rhinostone/swigto 2.7.1 or later - Upgrade
@rhinostone/swig-coreto 2.7.1 or later - Upgrade
@rhinostone/swig-twigto 2.7.1 or later - Upgrade
@rhinostone/swig-jinja2to 2.7.1 or later - Upgrade
@rhinostone/swig-djangoto 2.7.1 or later
- Upgrade