[DT-3779] Handle invalid queries better#2966
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves resilience of ontology search by ensuring user-provided query strings that sanitize down to “no meaningful tokens” don’t reach PostgreSQL to_tsquery, and updates tests to cover additional invalid-input cases.
Changes:
- Filter out empty tokens in
sanitizeForTsQuery, preventing generation of invalid tsquery fragments. - Expand DAO tests to cover “no alphanumeric content” query inputs and make timestamps deterministic via a fixed
Instant. - Add targeted Sonar suppressions for known-safe test URL constants.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/org/broadinstitute/consent/http/service/ontology/OntologyDAO.java | Ensures tsquery sanitization cannot emit empty tokens, supporting early-return behavior for invalid queries. |
| src/test/java/org/broadinstitute/consent/http/db/OntologyDAOTest.java | Adds/adjusts tests for invalid query inputs and stabilizes time-dependent test data creation. |
|
fboulnois
approved these changes
Jul 8, 2026
fboulnois
left a comment
Contributor
There was a problem hiding this comment.
my guess is there are other invalid patterns that can be used, but this seems like a reasonable near-term fix 👍
kevinmarete
approved these changes
Jul 8, 2026
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.



Addresses
https://broadworkbench.atlassian.net/browse/DT-3779
Summary
This PR adds additional filtering to prevent invalid queries from reaching the database. New test cases are added and several pre-existing sonar warnings are also addressed.
Have you read CONTRIBUTING.md lately? If not, do that first.