Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions assignment1_code_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import pymysql
from urllib.request import urlopen

db_config = {
'host': 'mydatabase.com',
'user': 'admin',
'password': 'secret123'
}

def get_user_input():
user_input = input('Enter your name: ')
return user_input

def send_email(to, subject, body):
os.system(f'echo {body} | mail -s "{subject}" {to}')

Check failure

Code scanning / Bandit

Starting a process with a shell, possible injection detected, security issue. Error

Starting a process with a shell, possible injection detected, security issue.

def get_data():
url = 'http://insecure-api.com/get-data'
data = urlopen(url).read().decode()

Check warning

Code scanning / Bandit

Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected. Warning

Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
return data

def save_to_db(data):
query = f"INSERT INTO mytable (column1, column2) VALUES ('{data}', 'Another Value')"

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
cursor.execute(query)
connection.commit()
cursor.close()
connection.close()

if __name__ == '__main__':
user_input = get_user_input()
data = get_data()
save_to_db(data)
send_email('admin@example.com', 'User Input', user_input)