Conversation
User.get_user() built a raw SQL string via f-string interpolation of
the username path param and executed it directly, allowing classic
UNION/boolean-based SQL injection (API8:2019 Injection).
Switch to a parameterized query using SQLAlchemy's text() bound
parameter (:username) so the value is always passed as data, never
concatenated into the SQL statement.
Verified locally: UNION/boolean injection payloads against
GET /users/v1/{username} (e.g. "name1' OR '1'='1", UNION SELECT
dumping the admin row, and a bare trailing quote) all now resolve as
'User not found' with no SQL error, while legitimate lookups for
name1, name2, and admin still return the correct user JSON.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🏆 VAmPI — CTF Patch Score1 / 9 challenges patched
Commit: 🎉 Your result is on the leaderboard — see where you rank! 🏆 |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability
GET /users/v1/{username}built a raw SQL statement via f-string interpolation of theusernamepath parameter (models/user_model.py,User.get_user()) and executed it withdb.session.execute(text(user_query)), allowing classic UNION/boolean-based SQL injection.Fix
Use a parameterized query: build the SQL with a named bind placeholder (
:username) via SQLAlchemy'stext()and pass the untrusted value as a parameter dict, so it is always treated as data and never concatenated into the SQL string.Testing
Ran the app locally (
vulnerable=1) and confirmed:GET /users/v1/{username}(name1' OR '1'='1, a UNION SELECT attempting to dump the admin row, and a bare trailing single quote) all now return{"status": "fail", "message": "User not found"}with no SQL error / no data leak.name1,name2, andadminall return their correct{"username":..., "email":...}JSON.🤖 Generated with Claude Code