You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
t.test("it wraps the createServer function of http module",async()=>{
83
87
constserver=http.createServer((req,res)=>{
@@ -550,9 +554,6 @@ t.test("it wraps on request event of http", async () => {
550
554
});
551
555
552
556
t.test("it wraps on request event of https",async()=>{
553
-
const{ readFileSync }=require("fs");
554
-
constpath=require("path");
555
-
556
557
// Otherwise, the self-signed certificate will be rejected
557
558
process.env.NODE_TLS_REJECT_UNAUTHORIZED="0";
558
559
@@ -719,3 +720,71 @@ t.test(
719
720
});
720
721
}
721
722
);
723
+
724
+
/**
725
+
* Explanation:
726
+
* - Makes a request to the server with a path traversal attack inside the pathname
727
+
* - The /../ is not removed from the path during the request because path normalization is not applied (by default many http libraries do this, e.g. if new URL(...) is used)
728
+
* - The server gets the raw string path from the HTTP header that is not normalized and passes it to path.join
729
+
*/
730
+
t.test("it blocks path traversal in path",async(t)=>{
731
+
constserver=http.createServer((req,res)=>{
732
+
try{
733
+
// req.url contains only the path and query string, not the full URL
734
+
// e.g. "/foo/bar?baz=qux"
735
+
// req.url is not sanitized, it's a raw string, thats why /../ is not removed
736
+
constpath=req.url||"/";
737
+
constfile=readFileSync(join(__dirname,path));
738
+
739
+
res.statusCode=200;
740
+
res.end(file);
741
+
}catch(error){
742
+
res.statusCode=500;
743
+
if(errorinstanceofError){
744
+
res.end(error.message);
745
+
return;
746
+
}
747
+
res.end("Internal server error");
748
+
}
749
+
});
750
+
751
+
awaitnewPromise<void>((resolve)=>{
752
+
server.listen(3327,async()=>{
753
+
constresponse=awaitnewPromise((resolve,reject)=>{
754
+
// Directly using http.request with a url-like object to prevent path normalization that would remove /../
0 commit comments