mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Add additional path-traversal guards on res.sendFile calls (no-changelog) (#6505)
This commit is contained in:
committed by
GitHub
parent
772ed7ff10
commit
42a9e20e32
@@ -14,7 +14,7 @@ import assert from 'assert';
|
||||
import { exec as callbackExec } from 'child_process';
|
||||
import { access as fsAccess } from 'fs/promises';
|
||||
import os from 'os';
|
||||
import { join as pathJoin, resolve as pathResolve } from 'path';
|
||||
import { join as pathJoin, resolve as pathResolve, relative as pathRelative } from 'path';
|
||||
import { createHmac } from 'crypto';
|
||||
import { promisify } from 'util';
|
||||
import cookieParser from 'cookie-parser';
|
||||
@@ -1467,6 +1467,9 @@ export class Server extends AbstractServer {
|
||||
loader.directory,
|
||||
req.originalUrl.substring(pathPrefix.length),
|
||||
);
|
||||
if (pathRelative(loader.directory, filePath).includes('..')) {
|
||||
return res.status(404).end();
|
||||
}
|
||||
try {
|
||||
await fsAccess(filePath);
|
||||
return res.sendFile(filePath);
|
||||
|
||||
Reference in New Issue
Block a user