Skip to content

MINOR: Modify logic to use parameterized queries - #24902

Merged
ayush-shah merged 3 commits into
mainfrom
fix-sql-inject
Dec 19, 2025
Merged

ayush-shah merged 3 commits into
mainfrom
fix-sql-inject

Conversation

@ayush-shah

Copy link
Copy Markdown
Member

This pull request improves the security of query construction in the ListFilter class by switching to parameterized SQL queries, which helps prevent SQL injection vulnerabilities. Additionally, it introduces a new test to verify that SQL injection attempts do not cause internal server errors and that valid queries still work as expected.

Security improvements to query construction:

  • Updated the query generation in ListFilter.java for both getEventSubscriptionAlertType() and getNotificationTemplateCondition() methods to use parameterized queries (e.g., :alertType, :notificationTemplate) instead of string interpolation, reducing the risk of SQL injection. [1] [2]

Testing for SQL injection prevention:

  • Added a new test test_sqlInjectionPrevention in EventSubscriptionResourceTest.java to simulate SQL injection attempts and verify that these do not result in internal server errors, while also confirming that valid parameters return expected results.

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.

Pull request overview

This pull request improves security by converting string interpolation to parameterized SQL queries in the ListFilter class for the alertType and notificationTemplate query parameters. The changes aim to prevent SQL injection vulnerabilities by using JDBI's named parameter binding (:alertType, :notificationTemplate) instead of direct string formatting. Additionally, a new test has been added to verify that SQL injection attempts do not cause internal server errors.

Key Changes

  • Replaced String.format() with parameterized query placeholders in two query-building methods
  • Added test coverage for SQL injection prevention scenarios
  • Both MySQL and PostgreSQL query paths have been updated consistently

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ListFilter.java Converted getEventSubscriptionAlertType() and getNotificationTemplateCondition() to use parameterized queries (:alertType and :notificationTemplate) instead of string interpolation for both MySQL and PostgreSQL
openmetadata-service/src/test/java/org/openmetadata/service/resources/events/EventSubscriptionResourceTest.java Added test_sqlInjectionPrevention() test with multiple SQL injection attack patterns and verification that valid parameters continue to work

@ayush-shah

Copy link
Copy Markdown
Member Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copilot AI commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

@ayush-shah I've opened a new pull request, #24903, to work on those changes. Once the pull request is ready, I'll request review from you.

* Initial plan

* fix: address PR review comments - use JSON_UNQUOTE for MySQL queries and improve test logic

Co-authored-by: ayush-shah <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: ayush-shah <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@ayush-shah
ayush-shah merged commit ea49233 into main Dec 19, 2025
@ayush-shah
ayush-shah deleted the fix-sql-inject branch December 19, 2025 15:05
@github-actions

Copy link
Copy Markdown
Contributor

Changes have been cherry-picked to the 1.11.4 branch.

github-actions Bot pushed a commit that referenced this pull request Dec 19, 2025

This branch was previously deployed

1 inactive deployment
test — 7d4d41fd Deployed Dec 19, 2025 by ayush-shah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants