1+ A . Commit message :
2+ Fix security vulnerability in subprocess call
3+
4+ B . Change summary :
5+ Removed the use of `shell=True` in the `subprocess.call` . Updated to execute the command without invoking a shell , which prevents command injection vulnerabilities .
6+
7+ C . Compatibility Risk :
8+ Medium
9+
10+ D . Fixed Code :
11+ `` `
112import requests
213import subprocess
314
15+
416def func_calls ():
5- formats .get_format ()
6- algorithms .HMACAlgorithm .prepare_key ()
7- cli .VerifyOperation .perform_operation ()
8- sessions .SessionRedirectMixin .resolve_redirects ()
17+ formats .get_format ()
18+ algorithms .HMACAlgorithm .prepare_key ()
19+ cli .VerifyOperation .perform_operation ()
20+ sessions .SessionRedirectMixin .resolve_redirects ()
21+
922
1023if __name__ == '__main__' :
11- session = requests .Session ()
12- proxies = {
13- 'http' : 'http://test:pass@localhost:8080' ,
14- 'https' : 'http://test:pass@localhost:8090' ,
15- }
16- url = 'http://example.com' # Replace with a valid URL
17- req = requests .Request ('GET' , url )
18- prep = req .prepare ()
19- session .rebuild_proxies (prep , proxies )
20-
21- # Introduce a command injection vulnerability
22- user_input = input ("Enter a command to execute: " )
23- command = "ping " + user_input
24- subprocess .call (command , shell = True )
25-
26- print ("Command executed!" )
24+ session = requests .Session ()
25+ proxies = {
26+ 'http' : 'http://test:pass@localhost:8080' ,
27+ 'https' : 'http://test:pass@localhost:8090' ,
28+ }
29+ url = 'http://example.com' # Replace with a valid URL
30+ req = requests .Request ('GET' , url )
31+ prep = req .prepare ()
32+ session .rebuild_proxies (prep , proxies )
33+
34+ # Removed command injection vulnerability
35+ user_input = input ("Enter a command to execute: " )
36+ command = ["ping" , user_input ]
37+ subprocess .call (command , shell = False )
38+
39+ print ("Command executed!" )
40+ `` `
0 commit comments