Nunjucks autoescape bypass leads to cross site scripting
Published 20 Apr 2023 · Updated 26 Nov 2024
Affected package
- Affected
- <3.2.4
- Fixed in
- 3.2.4
npm install nunjucks@3.2.4Details
Impact
In Nunjucks versions prior to version 3.2.4, it was possible to bypass the restrictions which are provided by the autoescape functionality. If there are two user-controlled parameters on the same line used in the views, it was possible to inject cross site scripting payloads using the backslash \ character.
Example
If the user-controlled parameters were used in the views similar to the following:
<script>
let testObject = { lang: '{{ lang }}', place: '{{ place }}' };
</script>It is possible to inject XSS payload using the below parameters:
https://<application-url>/?lang=jp\&place=};alert(document.domain)//
Patches
The issue was patched in version 3.2.4.
References
- https://bugzilla.mozilla.org/show_bug.cgi?id=1825980
Is GHSA-x77j-w7wf-fjmw in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected nunjucks, and gives you the command that fixes it.
References
- Linkgithub.com/mozilla/nunjucks/security/advisories/GHSA-x77j-w7wf-fjmw
- Advisorynvd.nist.gov/vuln/detail/CVE-2023-2142
- Linkgithub.com/mozilla/nunjucks/pull/1437
- Linkgithub.com/mozilla/nunjucks/commit/ec16d210e7e13f862eccdb0bc9af9f60ff6749d6
- Linkbugzilla.mozilla.org/show_bug.cgi?id=1825980
- Packagegithub.com/mozilla/nunjucks
- Linkgithub.com/mozilla/nunjucks/releases/tag/v3.2.4
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.