fix: patch path traversal and baseUrl normalization in scene generator
- server.js: sanitize static file paths to prevent directory traversal (GET /../../sgclaw_config.json would expose API key) - config-loader.js: fix normalizeBaseUrl to strip /v1 before appending, preventing double /v1 for non-standard base URLs 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
@@ -190,7 +190,13 @@ const server = http.createServer(async (req, res) => {
|
||||
} else if (pathname === "/" || pathname === "/index.html") {
|
||||
serveStatic(res, path.join(__dirname, "sg_scene_generator.html"));
|
||||
} else {
|
||||
const filePath = path.join(__dirname, pathname);
|
||||
const filePath = path.resolve(__dirname, pathname);
|
||||
const resolvedDir = path.resolve(__dirname);
|
||||
if (!filePath.startsWith(resolvedDir + path.sep) && filePath !== resolvedDir) {
|
||||
res.writeHead(403, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ error: "Forbidden" }));
|
||||
return;
|
||||
}
|
||||
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
|
||||
serveStatic(res, filePath);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user