Skip to content

Commit 026439a

Browse files
test circle ci
1 parent e0a132d commit 026439a

File tree

5 files changed

+67
-147
lines changed

5 files changed

+67
-147
lines changed

.github/workflows/docker-build.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/linters.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/workflows/security.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/staging-cd.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

app2.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from flask import Flask, request, jsonify, Response
2+
import sqlite3
3+
4+
app = Flask(__name__)
5+
6+
# Database file
7+
DATABASE = 'app.db'
8+
9+
def get_db_connection():
10+
conn = sqlite3.connect(DATABASE)
11+
return conn
12+
13+
def init_db():
14+
# Create table and insert data
15+
conn = get_db_connection()
16+
cursor = conn.cursor()
17+
# Check if table already exists to prevent overwriting
18+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='users';")
19+
if cursor.fetchone() is None:
20+
cursor.execute('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER);')
21+
cursor.execute("INSERT INTO users (name, age) VALUES ('Alice', 30), ('Bob', 25), ('Charlie', 35);")
22+
conn.commit()
23+
conn.close()
24+
25+
@app.route('/users', methods=['GET'])
26+
def get_user():
27+
name = request.args.get('name')
28+
conn = get_db_connection()
29+
cursor = conn.cursor()
30+
31+
# Vulnerable SQL Query from raw string concatenation
32+
query = f"SELECT * FROM users WHERE name = '{name}'"
33+
cursor.execute(query)
34+
35+
# # Fixed SQL Query using parameterized queries
36+
# query = "SELECT * FROM users WHERE name = ?"
37+
# cursor.execute(query, (name,))
38+
39+
user = cursor.fetchone()
40+
conn.close()
41+
if user:
42+
return jsonify({"id": user[0], "name": user[1], "age": user[2]})
43+
else:
44+
return jsonify({"error": "User not found"}), 404
45+
46+
@app.route('/.env', methods=['GET'])
47+
def get_env():
48+
env_content = """
49+
DB_NAME=crapi
50+
DB_USER=crapi
51+
DB_PASSWORD=crapi
52+
DB_HOST=postgresdb
53+
DB_PORT=5432
54+
SERVER_PORT=8080
55+
MONGO_DB_HOST=mongodb
56+
MONGO_DB_PORT=27017
57+
MONGO_DB_USER=crapi
58+
MONGO_DB_PASSWORD=crapi
59+
MONGO_DB_NAME=crapi
60+
"""
61+
return Response(env_content, headers={
62+
"Content-Disposition": "attachment; filename=env"
63+
})
64+
65+
if __name__ == '__main__':
66+
init_db() # Initialize the database and populate it
67+
app.run(host="0.0.0.0", debug=True)

0 commit comments

Comments
 (0)