|
| 1 | +from fastapi import FastAPI |
| 2 | +from hdbcli import dbapi |
| 3 | +from db_connection import get_conn |
| 4 | +from db_connection import hdb_con |
| 5 | +from db_connection import hdb_con2 |
| 6 | +from db_connection import hdb_con3 |
| 7 | +app = FastAPI() |
| 8 | + |
| 9 | +class DatabaseConnection: |
| 10 | + |
| 11 | + def __init__(self): |
| 12 | + self._conn = dbapi.connect(address='localhost', port=30015, user='system', password='Password123') |
| 13 | + |
| 14 | + def get_conn(self): |
| 15 | + return self._conn |
| 16 | + |
| 17 | +db_connection = DatabaseConnection() |
| 18 | + |
| 19 | +@app.get("/unsafe1/") |
| 20 | +async def unsafe(name: str): # $ Source |
| 21 | + query = "select * from users where name=" + name |
| 22 | + cursor = hdb_con.cursor() |
| 23 | + cursor.execute(query) # $ Alert |
| 24 | + cursor.close() |
| 25 | + |
| 26 | +@app.get("/unsafe2/") |
| 27 | +async def unsafe2(name: str): # $ Source |
| 28 | + query = "select * from users where name=" + name |
| 29 | + cursor = hdb_con2.cursor() |
| 30 | + cursor.execute(query) # $ Alert |
| 31 | + cursor.close() |
| 32 | + |
| 33 | +@app.get("/unsafe3/") # $ MISSING: Source |
| 34 | +async def unsafe3(name: str): |
| 35 | + query = "select * from users where name=" + name |
| 36 | + cursor = hdb_con3.cursor() |
| 37 | + cursor.execute(query) # $ MISSING: Alert |
| 38 | + cursor.close() |
| 39 | + |
| 40 | +@app.get("/unsafe4/") |
| 41 | +async def unsafe4(name: str): # $ Source |
| 42 | + query = "select * from users where name=" + name |
| 43 | + cursor = get_conn().cursor() |
| 44 | + cursor.execute(query) # $ Alert |
| 45 | + cursor.close() |
| 46 | + |
| 47 | +@app.get("/unsafe5/") |
| 48 | +async def unsafe5(name: str): # $ Source |
| 49 | + query = "select * from users where name=" + name |
| 50 | + cursor = db_connection.get_conn().cursor() |
| 51 | + cursor.execute(query) # $ Alert |
| 52 | + cursor.close() |
0 commit comments