-
Notifications
You must be signed in to change notification settings - Fork 0
Create djangojunk.py #83
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # sql_injection.py | ||
| import sqlite3 | ||
| from flask import Flask, request | ||
|
|
||
| app = Flask(__name__) | ||
| DB = "test.db" | ||
|
|
||
| def init_db(): | ||
| conn = sqlite3.connect(DB) | ||
| conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, password TEXT)") | ||
| conn.execute("INSERT OR IGNORE INTO users (id, username, password) VALUES (1, 'alice', 'passw0rd')") | ||
| conn.commit() | ||
| conn.close() | ||
|
|
||
| @app.route("/user") | ||
| def user(): | ||
| init_db() | ||
| username = request.args.get("username", "") | ||
| # WARNING: vulnerable to SQL injection | ||
| query1 = "SELECT id, username FROM users WHERE username = '%s'" % username | ||
|
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: Software and Data Integrity Failures - Tainted SQL stringUser-controlled input from a Django Recommendation: Use parameterized queries instead of string concatenation or formatting to include user input in SQL statements. When using Django's Severity: Low ⬇️ References:More details:Take action by replying with an [arnica] command 💬ActionsUse To acknowledge the finding as a valid code risk: To dismiss the risk with a reason: Examples
|
||
| conn = sqlite3.connect(DB) | ||
| cursor = conn.cursor() | ||
| cursor.execute(query1) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: Injection - Sqlalchemy execute raw queryA raw SQL query is being constructed using string concatenation, format strings, percent formatting, or f-strings, and then passed to SQLAlchemy's Recommendation: Use SQLAlchemy's Severity: Low ⬇️ References:
More details:Take action by replying with an [arnica] command 💬ActionsUse To acknowledge the finding as a valid code risk: To dismiss the risk with a reason: Examples
Comment on lines
+18
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: Injection - SQL injection DB cursor executeUser-controlled data from a Django Recommendation: Use Django's ORM QuerySets (e.g., Severity: Medium References:More details:Take action by replying with an [arnica] command 💬ActionsUse To acknowledge the finding as a valid code risk: To dismiss the risk with a reason: Examples
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: Injection - Formatted SQL queryThis code constructs an SQL query by embedding external values directly into the query string using Python string formatting (the Recommendation: Use parameterized queries (also called prepared statements) by passing a tuple or dictionary of values as the second argument to Severity: Low ⬇️ References:More details:Take action by replying with an [arnica] command 💬ActionsUse To acknowledge the finding as a valid code risk: To dismiss the risk with a reason: Examples
|
||
| row = cursor.fetchone() | ||
| conn.close() | ||
| return str(row) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static Code Analysis Risk: Injection - Tainted SQL string
User-controlled input from Flask request data or route parameters is concatenated directly into a SQL query string using string formatting operations such as
+,%,.format(), or f-strings. This allows an attacker to inject arbitrary SQL commands by crafting malicious input values. Successful exploitation can lead to unauthorized reading, modification, or deletion of database contents, and in some cases, full compromise of the underlying server.Recommendation: Use parameterized queries instead of string concatenation to build SQL statements. With SQLAlchemy, pass user input as bound parameters using
sqlalchemy.text()with:paramplaceholders (e.g.,db.execute(text("SELECT * FROM users WHERE id = :user_id"), {"user_id": user_input})). Alternatively, use SQLAlchemy's ORM query interface, which handles parameterization automatically.Severity: Medium⚠️
Status: Open 🔴
References:
More details:
🌻 View in Arnica
Take action by replying with an [arnica] command 💬
Actions
Use
[arnica]or[a]to interact with the Arnica bot to acknowledge or dismiss code risks.To acknowledge the finding as a valid code risk:
[arnica] ack <acknowledge additional details>To dismiss the risk with a reason:
[arnica] dismiss <fp|accept|capacity> <dismissal reason>Examples
[arnica] ack This is a valid risk and I'm looking into it[arnica] dismiss fp Dismissed - Risk Not Accurate: (i.e. False Positive)[arnica] dismiss accept Dismiss - Risk Accepted: Allow the risk to exist in the system[arnica] dismiss capacity Dismiss - No Capacity: This will need to wait for a future sprint