-
Notifications
You must be signed in to change notification settings - Fork 18
add pillar #13
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
base: main
Are you sure you want to change the base?
add pillar #13
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,69 @@ | ||
| from flask import Flask, request, jsonify | ||
| import sqlite3 | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| # Initialize the database | ||
| def init_db(): | ||
| conn = sqlite3.connect('users.db') | ||
| cursor = conn.cursor() | ||
| cursor.execute(''' | ||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id INTEGER PRIMARY KEY, | ||
| username TEXT NOT NULL, | ||
| password TEXT NOT NULL | ||
| )''') | ||
|
|
||
| # Insert some test data | ||
| cursor.execute("INSERT OR IGNORE INTO users (id, username, password) VALUES (1, 'admin', 'admin123')") | ||
| cursor.execute("INSERT OR IGNORE INTO users (id, username, password) VALUES (2, 'user', 'password123')") | ||
| conn.commit() | ||
| conn.close() | ||
|
|
||
| @app.route('/') | ||
| def home(): | ||
| return "Vulnerable API - Don't use this in production!" | ||
|
|
||
| @app.route('/api/users') | ||
| def get_user(): | ||
| username = request.args.get('username', '') | ||
|
|
||
| query = "SELECT * FROM users WHERE username = '" + username + "'" | ||
|
|
||
| conn = sqlite3.connect('users.db') | ||
| cursor = conn.cursor() | ||
| cursor.execute(query) | ||
| user = cursor.fetchone() | ||
| conn.close() | ||
|
|
||
| if user: | ||
| return jsonify({ | ||
| 'id': user[0], | ||
| 'username': user[1], | ||
| 'password': user[2] | ||
| }) | ||
| else: | ||
| return jsonify({'error': 'User not found'}), 404 | ||
|
|
||
| @app.route('/api/login', methods=['POST']) | ||
| def login(): | ||
| data = request.get_json() | ||
| username = data.get('username', '') | ||
| password = data.get('password', '') | ||
|
|
||
| query = f"SELECT * FROM users WHERE username = '{username}' AND password = '{password}'" | ||
|
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 - Tainted SQL stringDetected user input used to manually construct a SQL string. This is usually bad practice because manual construction could accidentally result in a SQL injection. An attacker could use a SQL injection to steal or modify contents of the database. Instead, use a parameterized query which is available by default in most database engines. Alternatively, consider using an object-relational mapper (ORM) such as SQLAlchemy which will protect your queries. Severity: Medium References:
Suggested reviewers 🧐: @confusedcrib DetailsTake action by replying with an [arnica] command 💬ActionsUse [arnica] ack <message>Acknowledge the finding as a valid code risk. Examples[arnica] dismiss <
|
||
|
|
||
| conn = sqlite3.connect('users.db') | ||
| cursor = conn.cursor() | ||
| cursor.execute(query) | ||
| user = cursor.fetchone() | ||
| conn.close() | ||
|
|
||
| if user: | ||
| return jsonify({'success': True, 'message': 'Login successful'}) | ||
| else: | ||
| return jsonify({'success': False, 'message': 'Invalid credentials'}), 401 | ||
|
|
||
| if __name__ == '__main__': | ||
| init_db() | ||
| app.run(debug=True, host='0.0.0.0', port=5000) | ||
|
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: Security Misconfiguration - Debug enabledDetected Flask app with debug=True. Do not deploy to production with this flag enabled as it will leak sensitive information. Instead, consider using Flask configuration variables or setting 'debug' using system environment variables. Severity: High 🚨 References:Suggested reviewers 🧐: @confusedcrib DetailsTake action by replying with an [arnica] command 💬ActionsUse [arnica] ack <message>Acknowledge the finding as a valid code risk. Examples[arnica] dismiss <
|
||
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
Detected user input used to manually construct a SQL string. This is usually bad practice because manual construction could accidentally result in a SQL injection. An attacker could use a SQL injection to steal or modify contents of the database. Instead, use a parameterized query which is available by default in most database engines. Alternatively, consider using an object-relational mapper (ORM) such as SQLAlchemy which will protect your queries.
Severity: Medium⚠️
Status: Open 🔴
References:
Suggested reviewers 🧐: @confusedcrib
Details
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.[arnica] ack <message>
Acknowledge the finding as a valid code risk.
Examples
[arnica] dismiss <
fp|accept|capacity> <message>Dismiss the risk with a reason.
fp: False positive, i.e. the result is incorrect and indicates no actual risk.accept: Tolerable risk, i.e. risk severity is lower than what has been reported or is accepted as it stands.capacity: No capacity, i.e. leave me alone, please.Examples