-
Notifications
You must be signed in to change notification settings - Fork 147
Open
Description
I recently analyzed nsepython using Bandit and identified a critical security vulnerability involving Command Injection.
Location
File:nsepython/rahu.py
Line: 32cmd = f'curl -b cookies.txt "{encoded_url}" {curl_headers}' raw = os.popen(cmd).read()The Vulnerability
The code constructs a system command using f-strings and executes it directly viaos.popen. This is dangerous because if any part ofencoded_urlorcurl_headerscontains untrusted input (or if the library is used in a web app context), an attacker could inject shell commands (e.g., using;or&&).
Recommendation
Avoid usingos.popenwith shell commands. Instead, use the standard pythonrequestslibrary to handle HTTP requests, which is secure by design and does not spawn a system shell.# Suggested Fix import requests response = requests.get(encoded_url, headers=headers, cookies=cookies)
Metadata
Metadata
Assignees
Labels
No labels