@grainulation/orchard 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server.js +8 -0
- package/package.json +1 -1
package/lib/server.js
CHANGED
|
@@ -790,6 +790,14 @@ ${ROUTES.map((r) => "<tr><td><code>" + r.method + "</code></td><td><code>" + r.p
|
|
|
790
790
|
let filePath = url.pathname;
|
|
791
791
|
filePath = join(PUBLIC_DIR, filePath);
|
|
792
792
|
|
|
793
|
+
// Prevent directory traversal
|
|
794
|
+
const resolved = resolve(filePath);
|
|
795
|
+
if (!resolved.startsWith(PUBLIC_DIR + "/") && resolved !== PUBLIC_DIR) {
|
|
796
|
+
res.writeHead(403);
|
|
797
|
+
res.end("Forbidden");
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
|
|
793
801
|
if (existsSync(filePath) && !statSync(filePath).isDirectory()) {
|
|
794
802
|
const ext = extname(filePath);
|
|
795
803
|
const mime = MIME[ext] || "application/octet-stream";
|