fix: address Path Traversal vulnerability in /assets endpoint by implementing security checks

This commit is contained in:
Davidson Gomes 2025-09-17 14:25:36 -03:00
parent 7ba878742e
commit b514fab30e
2 changed files with 22 additions and 4 deletions

View File

@ -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))

View File

@ -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');
} }