{"id":"GHSA-2mf3-mr2r-r4vf","summary":"@rhinostone/swig: arbitrary local file read via include/extends path traversal","details":"### Overview\n\n`@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.\n\n### Attack scenario\n\nThe 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:\n\n```js\n// application code — a configured filesystem loader with a basepath\nswig.renderFile('page.html', { partial: req.query.partial });\n```\n\n```\n{# page.html — trusted template #}\n{% include partial %}\n```\n\nSetting `?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\" %}`.\n\n### Impact\n\nArbitrary 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.\n\n### Affected & patched\n\nEvery 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.\n\nFixed 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.\n\n**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.\n\n### Workarounds\n\n- Upgrade to `2.7.2` (or later).\n- If you cannot upgrade immediately: configure the filesystem loader with an explicit `basepath`, and never pass untrusted data into an `{% include %}` / `{% extends %}` / `{% import %}` path.\n\n### References\n\n- GHSA-2rq5-699j-x7p6 — https://github.com/advisories/GHSA-2rq5-699j-x7p6\n- CVE-2023-25345 (NVD) — https://nvd.nist.gov/vuln/detail/CVE-2023-25345\n- Upstream issue (swig-templates) — https://github.com/node-swig/swig-templates/issues/88\n- Fix commit — https://github.com/gina-io/swig/commit/381bdc305e0b10e45368d56324328b9b4f7017fc","modified":"2026-08-18T17:15:16.401306500Z","published":"2026-08-18T16:31:16Z","database_specific":{"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-08-18T16:31:16Z","nvd_published_at":null,"cwe_ids":["CWE-22"]},"references":[{"type":"WEB","url":"https://github.com/gina-io/swig/security/advisories/GHSA-2mf3-mr2r-r4vf"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2023-25345"},{"type":"WEB","url":"https://github.com/gina-io/swig/commit/381bdc305e0b10e45368d56324328b9b4f7017fc"},{"type":"PACKAGE","url":"https://github.com/gina-io/swig"}],"affected":[{"package":{"name":"@rhinostone/swig","ecosystem":"npm","purl":"pkg:npm/%40rhinostone/swig"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"2.7.1"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/08/GHSA-2mf3-mr2r-r4vf/GHSA-2mf3-mr2r-r4vf.json"}},{"package":{"name":"@rhinostone/swig-core","ecosystem":"npm","purl":"pkg:npm/%40rhinostone/swig-core"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"2.7.1"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/08/GHSA-2mf3-mr2r-r4vf/GHSA-2mf3-mr2r-r4vf.json"}},{"package":{"name":"@rhinostone/swig-twig","ecosystem":"npm","purl":"pkg:npm/%40rhinostone/swig-twig"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"2.7.1"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/08/GHSA-2mf3-mr2r-r4vf/GHSA-2mf3-mr2r-r4vf.json"}},{"package":{"name":"@rhinostone/swig-jinja2","ecosystem":"npm","purl":"pkg:npm/%40rhinostone/swig-jinja2"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"2.7.1"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/08/GHSA-2mf3-mr2r-r4vf/GHSA-2mf3-mr2r-r4vf.json"}},{"package":{"name":"@rhinostone/swig-django","ecosystem":"npm","purl":"pkg:npm/%40rhinostone/swig-django"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"2.7.1"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/08/GHSA-2mf3-mr2r-r4vf/GHSA-2mf3-mr2r-r4vf.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"}]}