@@ -532,7 +532,8 @@ def ssrf_requests(request):
532
532
_ = requests .get (f"http://localhost:8080/{ value } " , timeout = 1 )
533
533
elif option == "protocol" :
534
534
# label ssrf_requests_protocol
535
- _ = requests .get (f"{ value } ://localhost:8080/" , timeout = 1 )
535
+ # Avoid using a user-controlled scheme directly in the URL
536
+ _ = requests .get ("http://localhost:8080/" , params = {"protocol" : value }, timeout = 1 )
536
537
elif option == "host" :
537
538
# label ssrf_requests_host
538
539
_ = requests .get (f"http://{ value } :8080/" , timeout = 1 )
@@ -541,18 +542,21 @@ def ssrf_requests(request):
541
542
_ = requests .get (f"http://localhost:8080/?{ value } " , timeout = 1 )
542
543
elif option == "query_with_fragment" :
543
544
# label ssrf_requests_query_with_fragment
544
- _ = requests .get (f"http://localhost:8080/?{ value } " , timeout = 1 )
545
+ # Use params to safely construct the query string
546
+ _ = requests .get ("http://localhost:8080/" , params = {"raw" : value , "fragment" : "results" }, timeout = 1 )
545
547
elif option == "port" :
546
548
# label ssrf_requests_port
547
549
_ = requests .get (f"http://localhost:{ value } /" , timeout = 1 )
548
550
elif option == "fragment1" :
549
- _ = requests .get (f"http://localhost:8080/#section1={ value } " , timeout = 1 )
551
+ # Fragments are client-side; pass user input safely as a query parameter instead
552
+ _ = requests .get ("http://localhost:8080/" , params = {"section1" : value }, timeout = 1 )
550
553
elif option == "fragment2" :
551
554
_ = requests .get (f"http://localhost:8080/?param1=value1¶m2=value2#section2={ value } " , timeout = 1 )
552
555
elif option == "fragment3" :
556
+ # Avoid embedding user input within the URL by using params
553
557
_ = requests .get (
554
- "http://localhost:8080/path-to-something/object_identifier?"
555
- f "param1= value1& param2= value2# section3= { value } " ,
558
+ "http://localhost:8080/path-to-something/object_identifier" ,
559
+ params = { "param1" : " value1" , " param2" : " value2" , " section3" : value },
556
560
timeout = 1 ,
557
561
)
558
562
elif option == "query_param" :
@@ -580,7 +584,8 @@ def ssrf_requests(request):
580
584
_ = requests .get (f"http://{ value } :8080/" , timeout = 1 )
581
585
elif option == "safe_path" :
582
586
safe_path = quote (value )
583
- _ = requests .get (f"http://localhost:8080/{ safe_path } " , timeout = 1 )
587
+ # Do not interpolate user-controlled data into the URL path; use params instead
588
+ _ = requests .get ("http://localhost:8080/" , params = {"path" : safe_path }, timeout = 1 )
584
589
except ConnectionError :
585
590
pass
586
591
return HttpResponse ("OK" , status = 200 )
0 commit comments