[BUG] NoSQL Injection 1 only answers once per Tomcat run: the servlet closes the shared MongoClient

Open Beginner friendly
#992 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ismisepaul is already working on this.

Since Oct 25, 2026.

  • #1019 by @ismisepaul — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java, mongodb

Research direction

Read NoSqlInjection1.doPost and MongoDatabase.getMongoDbConnection to confirm that the client is shared while the cursor is request scoped. Remove the client close and add an integration test that submits twice and expects results both times; the cursor should still be closed. Check the existing integration test conventions first.

Written by the indexing model from the issue text.

Description

Bug Levels

Discovered during #958.

NoSqlInjection1.doPost gets its client from MongoDatabase.getMongoDbConnection(applicationRoot, credential) and calls mongoClient.close() in its finally. Since the pooling work in #816, MongoDatabase caches one client per credential in credentialClients, so the servlet closes the shared client. Every later request fails with IllegalStateException: state should be: open and the player sees "An Error Occurred! You must be getting funky!" until Tomcat restarts.

Reproduced on dev (driver 3.12, MongoDB 4.1.13) and with driver 5.13 / MongoDB 8.0.

Fix: remove the close() on the shared client (the cursor close stays). The injection itself ($where built from user input) is untouched. Add an IT that submits twice and expects results both times.

🤖 Generated with Claude Code

Dominant language
Java
Stars
1.5k
Forks
519
Avg merge
1d 1h
Merged PRs (30d)
61

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OWASP/SecurityShepherd

All issues in OWASP/SecurityShepherd

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.