Skip to content

Fix SQL injection vulnerability in user registration#12

Merged
studentsca023-rgb merged 1 commit into
masterfrom
semgrep-autofix/1773739670
Mar 17, 2026
Merged

Fix SQL injection vulnerability in user registration#12
studentsca023-rgb merged 1 commit into
masterfrom
semgrep-autofix/1773739670

Conversation

@semgrep-code-studentsca023-rgb

Copy link
Copy Markdown

Fix SQL injection vulnerability in flask_webgoat/users.py by replacing string formatting with parameterized queries.

Changes

  • Replaced manual SQL string construction using % formatting with parameterized query placeholders (?)
  • Passed user inputs (username, password, access_level) as parameters to query_db instead of embedding them directly in the query string

Why

The original code used string formatting to construct the SQL INSERT statement, which allowed user-controlled input to be directly interpolated into the query. This created a SQL injection vulnerability where an attacker could manipulate the query structure by providing malicious input values.

By using parameterized queries, the database driver handles proper escaping and keeps user data separate from the SQL command structure, preventing injection attacks.

Semgrep Finding Details

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 the Django object-relational mappers (ORM) instead of raw SQL queries.

@267212124 requested Semgrep Assistant generate this pull request to fix a finding from the detection rule python.django.security.injection.tainted-sql-string.tainted-sql-string.


⚠️ Review carefully before merging. This PR was generated by AI and may cause breaking changes or introduce new vulnerabilities.

Fix SQL injection vulnerability in `flask_webgoat/users.py` by replacing string formatting with parameterized queries.

## Changes
- Replaced manual SQL string construction using `%` formatting with parameterized query placeholders (`?`)
- Passed user inputs (`username`, `password`, `access_level`) as parameters to `query_db` instead of embedding them directly in the query string

## Why
The original code used string formatting to construct the SQL INSERT statement, which allowed user-controlled input to be directly interpolated into the query. This created a SQL injection vulnerability where an attacker could manipulate the query structure by providing malicious input values.

By using parameterized queries, the database driver handles proper escaping and keeps user data separate from the SQL command structure, preventing injection attacks.

## Semgrep Finding Details
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 the Django object-relational mappers (ORM) instead of raw SQL queries.

@267212124 requested Semgrep Assistant generate this pull request to fix [a finding](https://semgrep.dev/orgs/studentsca023_personal_org/findings/722169013) from the detection rule [python.django.security.injection.tainted-sql-string.tainted-sql-string](https://semgrep.dev/r/python.django.security.injection.tainted-sql-string.tainted-sql-string).
@studentsca023-rgb studentsca023-rgb marked this pull request as ready for review March 17, 2026 09:29
@studentsca023-rgb studentsca023-rgb merged commit 2bef12f into master Mar 17, 2026
2 of 3 checks passed

@studentsca023-rgb studentsca023-rgb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant