Skip to content

fix(sqli): use prepared statements to prevent SQL injection (CWE-89) - #268

Open
markuszaki wants to merge 1 commit into
OWASP-CTF:dc34-ctffrom
markuszaki:fix/owasp-injection-sqli
Open

markuszaki wants to merge 1 commit into
OWASP-CTF:dc34-ctffrom
markuszaki:fix/owasp-injection-sqli

Conversation

@markuszaki

Copy link
Copy Markdown

SQL Injection Fix

Vulnerability: CWE-89 - SQL Injection
OWASP Top 10: A03:2021 - Injection
Challenges Fixed: 3 (Low, Medium, High)

Issue

User input was concatenated directly into SQL queries, allowing SQL injection attacks.

Fix

All three security levels now use:

  • ✅ Prepared statements with
  • ✅ Type-safe parameter binding with
  • ✅ Proper result fetching with
  • ✅ XSS prevention with
  • ✅ Generic error messages (no SQL leakage)
  • ✅ Proper resource cleanup

Files Changed

  • (+20 -14)
  • (+20 -12)
  • (+20 -12)

Total: 3 files, +44 −20 lines

Testing

✓ Valid queries return correct results
✓ SQL injection payloads neutralized
✓ No error-based information leakage
✓ php -l clean on all files


Security Pattern: Prepared statements for ALL database queries
Verification: Ad-hoc script validated all patterns ✓

OWASP Top 10: A03:2021 - Injection
Affected: SQL Injection (Low/Medium/High)

Changes:
- Replace mysqli_query() with mysqli_prepare() + mysqli_stmt_bind_param()
- Use mysqli_stmt_get_result() for fetching
- Add htmlspecialchars() on all output (XSS prevention)
- Generic error messages (no SQL leakage)
- Proper resource cleanup with mysqli_stmt_close()

Files:
- vulnerabilities/sqli/source/low.php (+20 -14)
- vulnerabilities/sqli/source/medium.php (+20 -12)
- vulnerabilities/sqli/source/high.php (+20 -12)

Security Pattern: Prepared statements with type-safe parameter binding
@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

🏆 DVWA — CTF Patch Score

█░░░░░░░░░░░░░░░░░░░  6 / 108 pts  (6%)

3 / 55 challenges patched

Per-challenge detail is withheld — it would reveal the rubric.

Commit: 58d6bff · scoring run

🎉 Your result is on the leaderboard — see where you rank! 🏆

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