Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bazel/http-server/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ export class HttpServer {

// Detect if the url escapes the server's root path
for (const rootPath of this._rootPaths) {
const absoluteRootPath = path.resolve(rootPath);
const absoluteJoinedPath = path.resolve(path.posix.join(rootPath, getManifestPath(req.url)));
const resolvedRoot = path.resolve(rootPath);
const absoluteRootPath = resolvedRoot.endsWith(path.sep)
? resolvedRoot
: resolvedRoot + path.sep;
const resolvedJoined = path.resolve(path.posix.join(rootPath, getManifestPath(req.url)));
const absoluteJoinedPath = resolvedJoined.endsWith(path.sep)
? resolvedJoined
: resolvedJoined + path.sep;
if (!absoluteJoinedPath.startsWith(absoluteRootPath)) {
res.statusCode = 500;
res.end('Error: Detected directory traversal');
Expand Down