Skip to content

Commit fed5ea6

Browse files
author
patched.codes[bot]
committed
Patched /tmp/tmpi4bo6m70/main.py
1 parent 4964f26 commit fed5ea6

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

main.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
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+
```
112
import requests
213
import subprocess
314

15+
416
def 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

1023
if __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

Comments
 (0)