Skip to content

fix: JDBC Resource Leaks in SQL Injection Challenges - #932

Open
LucaBonamino wants to merge 3 commits into
OWASP:devfrom
LucaBonamino:dev#931
Open

LucaBonamino wants to merge 3 commits into
OWASP:devfrom
LucaBonamino:dev#931

Conversation

@LucaBonamino

Copy link
Copy Markdown

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

  • Use Java's try-with-resources to ensure JDBC resources are properly closed.
  • Ensure database connections are returned to the HikariCP pools, even when
    SQL queries fail or exceptions occur.
  • Preserve the existing SQL queries and the intentionally vulnerable behavior
    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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

@ismisepaul ismisepaul changed the title Fix JDBC Resource Leaks in SQL Injection Challenges fix: JDBC Resource Leaks in SQL Injection Challenges Oct 25, 2026
@ismisepaul

Copy link
Copy Markdown
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!

This branch has not been deployed

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

Labels

Projects

Status: Next Release Backlog

Development

Successfully merging this pull request may close these issues.

[BUG] SQL Injection Challenges 1,2,3,4 and 5 Stop Working After Several Queries

4 participants