mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
fix: address Path Traversal vulnerability in /assets endpoint by implementing security checks
This commit is contained in:
parent
7ba878742e
commit
b514fab30e
@ -1,5 +1,9 @@
|
|||||||
# 2.3.3 (develop)
|
# 2.3.3 (develop)
|
||||||
|
|
||||||
|
### Security
|
||||||
|
|
||||||
|
* **CRITICAL**: Fixed Path Traversal vulnerability in /assets endpoint that allowed unauthenticated local file read
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
|
|
||||||
* Baileys Updates: v7.0.0-rc.3 ([Link](https://github.com/WhiskeySockets/Baileys/releases/tag/v7.0.0-rc.3))
|
* Baileys Updates: v7.0.0-rc.3 ([Link](https://github.com/WhiskeySockets/Baileys/releases/tag/v7.0.0-rc.3))
|
||||||
|
|||||||
@ -106,13 +106,27 @@ if (!serverConfig.DISABLE_MANAGER) router.use('/manager', new ViewsRouter().rout
|
|||||||
|
|
||||||
router.get('/assets/*', (req, res) => {
|
router.get('/assets/*', (req, res) => {
|
||||||
const fileName = req.params[0];
|
const fileName = req.params[0];
|
||||||
|
|
||||||
|
// Security: Reject paths containing traversal patterns
|
||||||
|
if (!fileName || fileName.includes('..') || fileName.includes('\\') || path.isAbsolute(fileName)) {
|
||||||
|
return res.status(403).send('Forbidden');
|
||||||
|
}
|
||||||
|
|
||||||
const basePath = path.join(process.cwd(), 'manager', 'dist');
|
const basePath = path.join(process.cwd(), 'manager', 'dist');
|
||||||
|
const assetsPath = path.join(basePath, 'assets');
|
||||||
|
const filePath = path.join(assetsPath, fileName);
|
||||||
|
|
||||||
const filePath = path.join(basePath, 'assets/', fileName);
|
// Security: Ensure the resolved path is within the assets directory
|
||||||
|
const resolvedPath = path.resolve(filePath);
|
||||||
|
const resolvedAssetsPath = path.resolve(assetsPath);
|
||||||
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (!resolvedPath.startsWith(resolvedAssetsPath + path.sep) && resolvedPath !== resolvedAssetsPath) {
|
||||||
res.set('Content-Type', mimeTypes.lookup(filePath) || 'text/css');
|
return res.status(403).send('Forbidden');
|
||||||
res.send(fs.readFileSync(filePath));
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(resolvedPath)) {
|
||||||
|
res.set('Content-Type', mimeTypes.lookup(resolvedPath) || 'text/css');
|
||||||
|
res.send(fs.readFileSync(resolvedPath));
|
||||||
} else {
|
} else {
|
||||||
res.status(404).send('File not found');
|
res.status(404).send('File not found');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user