Skip to content

Commit a46eb7b

Browse files
Refactor code formatting for clarity in project_d_vuln.py
1 parent 55bc153 commit a46eb7b

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

circle_ci/codeql_analysis_pr.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,27 @@ jobs:
2828
# ----------------------------
2929
# set variables for pull request context
3030
# ----------------------------
31-
if [ -n "$CIRCLE_PULL_REQUEST" ]; then
32-
echo "Running in a pull request context"
33-
PR_NUMBER=$(basename $CIRCLE_PULL_REQUEST)
34-
REPO_PATH=$(echo "$CIRCLE_PULL_REQUEST" | sed -E 's|https://github.com/([^/]+/[^/]+)/pull/[0-9]+|\1|')
35-
BASE_REF=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
36-
https://api.github.com/repos/${REPO_PATH}/pulls/${PR_NUMBER} \
37-
| jq -r .base.ref)
38-
BASE_REF="origin/${BASE_REF}"
39-
REF="refs/pull/${PR_NUMBER}/merge"
40-
fi
31+
# if [ -n "$CIRCLE_PULL_REQUEST" ]; then
32+
# echo "Running in a pull request context"
33+
# PR_NUMBER=$(basename $CIRCLE_PULL_REQUEST)
34+
# REPO_PATH=$(echo "$CIRCLE_PULL_REQUEST" | sed -E 's|https://github.com/([^/]+/[^/]+)/pull/[0-9]+|\1|')
35+
# BASE_REF=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
36+
# https://api.github.com/repos/${REPO_PATH}/pulls/${PR_NUMBER} \
37+
# | jq -r .base.ref)
38+
# BASE_REF="origin/${BASE_REF}"
39+
# REF="refs/pull/${PR_NUMBER}/merge"
40+
# fi
4141
curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user
42+
# codeql-wrapper --verbose analyze ./monorepo \
43+
# --monorepo \
44+
# --upload-sarif \
45+
# --only-changed-files \
46+
# --base-ref "$BASE_REF" \
47+
# --ref "$REF"
4248
codeql-wrapper --verbose analyze ./monorepo \
4349
--monorepo \
4450
--upload-sarif \
45-
--only-changed-files \
46-
--base-ref "$BASE_REF" \
47-
--ref "$REF"
51+
--only-changed-files
4852
4953
workflows:
5054
version: 2

monorepo/project-python-2/project_d_vuln.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1+
# This file is part of a CodeQL project that tests for SQL injection vulnerabilities.
2+
# 1
3+
14
import sqlite3
25
from flask import Flask, request
36

47
app = Flask(__name__)
58

9+
610
def initialize_database():
711
connection = sqlite3.connect("example.db")
812
cursor = connection.cursor()
9-
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, password TEXT)")
10-
cursor.execute("INSERT INTO users (username, password) VALUES ('admin', 'adminpass')")
13+
cursor.execute(
14+
"CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, password TEXT)"
15+
)
16+
cursor.execute(
17+
"INSERT INTO users (username, password) VALUES ('admin', 'adminpass')"
18+
)
1119
connection.commit()
1220
connection.close()
1321

22+
1423
@app.route("/login", methods=["POST"])
1524
def login():
1625
username = request.form.get("username")
1726
password = request.form.get("password")
1827

1928
# Vulnerable to SQL injection
20-
query = f"SELECT * FROM users WHERE username = '{username}' AND password = '{password}'"
29+
query = (
30+
f"SELECT * FROM users WHERE username = '{username}' AND password = '{password}'"
31+
)
2132
print(f"Executing query: {query}")
2233

2334
connection = sqlite3.connect("example.db")
@@ -30,6 +41,7 @@ def login():
3041
else:
3142
return "Invalid username or password"
3243

44+
3345
if __name__ == "__main__":
3446
initialize_database()
3547
app.run(debug=True)

0 commit comments

Comments
 (0)