bug: parameterize login query to fix SQL injection (routes/login.ts) - #354
matthewguerra-cog wants to merge 1 commit into
Conversation
Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| return (req: Request, res: Response, next: NextFunction) => { | ||
| verifyPreLoginChallenges(req) // vuln-code-snippet hide-line | ||
| models.sequelize.query(`SELECT * FROM Users WHERE email = '${req.body.email || ''}' AND password = '${security.hash(req.body.password || '')}' AND deletedAt IS NULL`, { model: UserModel, plain: true }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge | ||
| models.sequelize.query('SELECT * FROM Users WHERE email = $1 AND password = $2 AND deletedAt IS NULL', { bind: [req.body.email || '', security.hash(req.body.password || '')], model: UserModel, plain: true }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge |
There was a problem hiding this comment.
🔴 Four login challenges lose exploits
Parameterizing sequelize.query rejects the payloads for Login Admin, Login Bender, Login Jim, and Ephemeral Accountant. Their documented SQL-injection path no longer works, leaving several training challenges unsolvable.
Learn more
This application deliberately exposes selected vulnerabilities as training features. The login handler is the sole exploit path for the three marked login challenges and for ephemeralAccountantChallenge. The parameterized query treats each attack string as an email value, so the query returns no user and verifyPostLoginChallenges never runs. The same change also makes the source shown by the Fix It exercises identical in principle to their correct prepared-statement answer.
Example: Posting jim@juice-sh.op'-- previously selected Jim without his password and solved Login Jim. It now searches for that literal email, returns 401, and leaves the challenge unsolved. The UNION payload that synthesizes the accountant user fails in the same way, with no alternative route to create that ephemeral identity.
Recommended fix: Preserve the intentional challenge behavior or redesign and migrate all four affected challenges together. If the vulnerability is removed, replace their exploit and detection paths, update challenge metadata and codefix assets, and change the five API assertions to validate the new supported solutions. Run the full API, E2E, and RSN suites after the migration.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Intentional. This PR exists specifically to remediate the CodeQL js/sql-injection finding (CWE-89, 8.8) on this line in this fork; losing the Login Admin/Bender/Jim and Ephemeral Accountant exploit paths is the expected consequence and is called out in the description. Challenge/test migration is out of scope here — the finding owner has accepted the training-challenge regression in favor of closing the vulnerability.
Description
Fixes CodeQL
js/sql-injection(CWE-89, severity 8.8) atroutes/login.ts:34. The login query interpolatedreq.body.emaildirectly into raw SQL, allowing e.g.' OR 1=1--to bypass authentication.Uses Sequelize bind parameters, matching the shape of the repo's own
loginAdminChallenge_4_correct.tscodefix. The// vuln-code-snippetmarkers are kept so the coding-challenge snippet extraction still works;npm run rsnpasses unchanged.Note: this intentionally breaks the
loginAdminChallenge/loginBenderChallenge/loginJimChallengeSQL-injection challenges — the 5 injection assertions intest/api/login.test.tsnow get401instead of200. All other login API tests (valid login, bad credentials, 2FA, login IP) pass.Verified:
eslint routes/login.ts,npm run rsn, server unit tests (42 passing),test/api/login.test.ts(11 passing / 5 expected challenge failures).Resolved or fixed issue: none
AI Tool Disclosure
DevinDevin (Cognition AI)Fix CodeQL js/sql-injection finding in routes/login.ts:34Affirmation
Devin-Org: engineering
Link to Devin session: https://app.devin.ai/sessions/1c69f0b8d6db4f899e9dc9cf65aba97f
Open in Devin Desktop: https://app.devin.ai/desktop/session/1c69f0b8d6db4f899e9dc9cf65aba97f?variant=devin
Requested by: @matthewguerra-cog