From 2e0a457577f555a5cdc375e8dd22d42d6ace94a9 Mon Sep 17 00:00:00 2001 From: Vishaal Date: Wed, 19 Nov 2025 00:44:50 +0530 Subject: [PATCH] feat: Add database utilities with security vulnerabilities for demo - SQL Injection: Direct string interpolation in SQL query - Hardcoded Credentials: Admin username/password in code - Plain Text API Key Storage: No encryption for sensitive data - SSRF Risk: No URL validation in external API calls - DoS Risk: No timeout on HTTP requests --- src/app/utils/__init__.py | 0 src/app/utils/database.py | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/app/utils/__init__.py create mode 100644 src/app/utils/database.py diff --git a/src/app/utils/__init__.py b/src/app/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/app/utils/database.py b/src/app/utils/database.py new file mode 100644 index 0000000..8190fee --- /dev/null +++ b/src/app/utils/database.py @@ -0,0 +1,51 @@ +"""Database utilities with security vulnerabilities for demo.""" + +import sqlite3 + + +def query_user_by_id(user_id, db_path="db.sqlite3"): + """Query user by ID - SQL injection vulnerability.""" + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + + # SECURITY ISSUE: SQL injection vulnerability! + # User input directly interpolated into query + query = f"SELECT * FROM users WHERE id = {user_id}" + + cursor.execute(query) + result = cursor.fetchone() + conn.close() + + return result + + +def authenticate_user(username, password): + """Authenticate user with hardcoded credentials.""" + # SECURITY ISSUE: Hardcoded credentials in code! + ADMIN_USERNAME = "admin" + ADMIN_PASSWORD = "SuperSecret123!" + + if username == ADMIN_USERNAME and password == ADMIN_PASSWORD: + return {"authenticated": True, "role": "admin"} + + return {"authenticated": False} + + +def store_api_key(api_key): + """Store API key without encryption.""" + # SECURITY ISSUE: API key stored in plain text + with open("/tmp/api_keys.txt", "a") as f: + f.write(f"API_KEY={api_key}\n") + + return True + + +def fetch_data_from_external_api(url): + """Fetch data from external API without validation.""" + import requests + + # SECURITY ISSUE: No URL validation - potential SSRF vulnerability + # SECURITY ISSUE: No timeout - potential DoS + response = requests.get(url) + + return response.json()