Skip to content
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

Problema de Segurança #4

Open
Gabriel-Goes opened this issue Mar 29, 2024 · 1 comment
Open

Problema de Segurança #4

Gabriel-Goes opened this issue Mar 29, 2024 · 1 comment

Comments

@Gabriel-Goes
Copy link

O uso de subprocess.Popen com shell=True e a interpolação de strings para construir comandos shell apresenta riscos de segurança, especialmente se o conteúdo das variáveis envolvidas puder ser controlado por um ator externo. Isso pode levar a vulnerabilidades de injeção de shell.

@Gabriel-Goes
Copy link
Author

Using only python:

user_input = input("Please enter a filename: ")
try:
with open(user_input, 'r') as file:
print(file.read())
except FileNotFoundError:
print("File not found.")

Using shlex:

import subprocess
import shlex

user_input = input("Please enter a filename: ")
safe_user_input = shlex.quote(user_input)
subprocess.Popen(['cat', safe_user_input])

Not using f' cat {}'

import subprocess

user_input = input("Please enter a filename: ")
subprocess.run(['cat', user_input])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant