-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] security: OS Command Injection vulnerability (x2) #1219 #1227
[FIX] security: OS Command Injection vulnerability (x2) #1219 #1227
Conversation
Removing F-String format. Co-authored-by: Filipe Pina <[email protected]>
@yogeshojha security vulnerabilities in security products should have more priority than other products 😄 |
Hi @0xtejas Thank you for reporting this. Thank you again for reporting. |
…such as color coding
@0xtejas @sa7mon thank you for reporting this and also sending a PR. If any of you have time, can you please go through the changes and test it again? Hopefully, there shouldn't be any issue because Let me know if you find something, if not I will merge this tomorrow. |
except Exception as e: | ||
response = {'status': False, 'message': str(e)} | ||
return Response(response) | ||
return Response(response) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Hi @yogeshojha to comment on the There's shlex.split that you could use there to better split the strings, but usually that's only used when you really need to take a full command line as input. If you only take single arguments as user input, it's cleaner, more secure and more performant to use all the I plan to change my fork to do that:
Would that change make sense to push upstream? |
Hi @fopina sounds good to me. For this issue, I will go ahead and continue to use So until then, I will be going ahead with this approach and will be waiting for your changes. Thanks |
This code is resistant to command injection because it uses the
subprocess.run()
function with a list of arguments instead of a single-string command.When you pass a list of arguments to a subprocess.run(), Python will not invoke a shell to execute the command. This means that shell metacharacters such as
;, &&, ||
etc., which could be used to inject additional commands, are treated as literal characters and not interpreted by the shell.In this case, the URL variable is passed as a separate argument to the command, so even if it contains shell metacharacters, they will not be interpreted as such. This makes the command resistant to command injection attacks.
I have re-tested using the POC and it did not spawn the shell. However, I'd suggest performing a little more extensive test. Let me know if you find anything.