Repository navigation
fix: JDBC Resource Leaks in SQL Injection Challenges - #932
Open
LucaBonamino wants to merge 3 commits into
Open
LucaBonamino wants to merge 3 commits into
LucaBonamino wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The resource scopes cover normal and exceptional execution without changing challenge behavior, and no blocking issues were identified.
No open issues 🎉
What changed in this PR
This PR addresses #931 by fixing JDBC resource leaks in SQL injection challenges, preventing connection-pool exhaustion while preserving their intentionally vulnerable behavior.
Changes:
- Use try-with-resources to release connections and statements on successful and exceptional paths.
- Explicitly manage result sets in challenges 1, 3, and 4; challenge 5’s result set closes with its prepared statement.
- Preserve existing SQL queries and result handling.
| File | Description |
|---|---|
| src/main/java/servlets/module/challenge/SqlInjection5.java | Automatically close the coupon-query connection and prepared statement. |
| src/main/java/servlets/module/challenge/SqlInjection4.java | Automatically close JDBC resources for the login query. |
| src/main/java/servlets/module/challenge/SqlInjection3.java | Automatically close JDBC resources for the customer-name search. |
| src/main/java/servlets/module/challenge/SqlInjection1.java | Automatically close JDBC resources for the customer-ID search. |
Review effort: Balanced
Member
|
Thanks @LucaBonamino for the fix and the clear write-up. Before merging, a couple of things:
Once those are done, I'm happy to approve. Thanks! |
4 tasks
This branch has not been deployed
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.
This PR addresses the JDBC resource leaks reported in #931.
Several SQL Injection challenges do not properly release database connections, statements, and result sets. As a result, repeated requests can exhaust the HikariCP connection pools, causing subsequent queries to fail until Tomcat is restarted.
Changes
try-with-resourcesto ensure JDBC resources are properly closed.SQL queries fail or exceptions occur.
of the challenges.
The changes address resource management without altering the educational
purpose of the SQL Injection exercises.
Testing
After applying the fix and rebuilding the application, repeated valid and malformed SQL queries no longer exhausted the affected connection pools during local testing.
Related issue
Fixes #931