Skip to content

Fix MySQL JSON query syntax and SQL injection test logic - #24903

Merged
ayush-shah merged 2 commits into
fix-sql-injectfrom
copilot/sub-pr-24902
Dec 18, 2025
Merged

ayush-shah merged 2 commits into
fix-sql-injectfrom
copilot/sub-pr-24902

Conversation

Copilot AI commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Addressed code review feedback on PR #24902 regarding MySQL query syntax inconsistencies and flawed test logic for SQL injection prevention.

MySQL JSON Query Fixes:

  • Wrapped JSON_EXTRACT with JSON_UNQUOTE in getEventSubscriptionAlertType() and getNotificationTemplateCondition() for MySQL queries
  • MySQL's JSON_EXTRACT returns quoted strings; direct comparison against parameterized values fails without unquoting
  • Aligns with existing pattern used in getServiceTypeCondition() (line 236)

Test Logic Improvements:

  • Renamed test_sqlInjectionPrevention → test_parameterizedQueriesPreventSqlInjection to match file conventions
  • Extracted assertSqlInjectionAttempt() helper method to eliminate duplication
  • Fixed assertion execution: previously, assertions only ran inside catch blocks; now they always execute
  • Verifies malicious input returns empty results (no data exposure) rather than just checking for absence of 500 errors
// Before: assertions never ran when no exception was thrown
try {
  listEntities(sqlInjectionAttempts, ADMIN_AUTH_HEADERS);
} catch (HttpResponseException e) {
  assertTrue(e.getStatusCode() != 500, "...");
}

// After: assertions always verify behavior
ResultList<EventSubscription> results = null;
try {
  results = listEntities(params, ADMIN_AUTH_HEADERS);
} catch (HttpResponseException e) {
  assertTrue(e.getStatusCode() != 500, "...");
  return;
}
assertNotNull(results, "...");
assertTrue(results.getData() == null || results.getData().isEmpty(), "...");

Type of change:

  • Bug fix

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI commented Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repository.apache.org
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenMetadata/OpenMetadata org.codehaus.plexus.classworlds.launcher.Launcher spotless:apply -pl openmetadata-service (dns block)
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenMetadata/OpenMetadata org.codehaus.plexus.classworlds.launcher.Launcher compile -pl openmetadata-service -am -DskipTests (dns block)
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenMetadata/OpenMetadata org.codehaus.plexus.classworlds.launcher.Launcher test-compile -pl openmetadata-service -Dtest=EventSubscriptionResourceTest -DfailIfNoTests=false (dns block)
  • s3.amazonaws.com
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenMetadata/OpenMetadata org.codehaus.plexus.classworlds.launcher.Launcher spotless:apply -pl openmetadata-service (dns block)
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenMetadata/OpenMetadata org.codehaus.plexus.classworlds.launcher.Launcher compile -pl openmetadata-service -am -DskipTests (dns block)
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenMetadata/OpenMetadata org.codehaus.plexus.classworlds.launcher.Launcher test-compile -pl openmetadata-service -Dtest=EventSubscriptionResourceTest -DfailIfNoTests=false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix logic to use parameterized queries for security Fix MySQL JSON query syntax and SQL injection test logic Dec 18, 2025
Copilot AI requested a review from ayush-shah December 18, 2025 15:15
@ayush-shah
ayush-shah marked this pull request as ready for review December 18, 2025 15:22
@ayush-shah
ayush-shah requested a review from a team as a code owner December 18, 2025 15:22
Copilot AI review requested due to automatic review settings December 18, 2025 15:22
@ayush-shah
ayush-shah merged commit 9bc4441 into fix-sql-inject Dec 18, 2025
@ayush-shah
ayush-shah deleted the copilot/sub-pr-24902 branch December 18, 2025 15:23

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 PR addresses MySQL JSON query syntax issues and improves SQL injection prevention test logic. The changes fix bugs where MySQL's JSON_EXTRACT returns quoted strings that fail direct comparison with parameterized values, and enhance test validation to ensure malicious inputs return empty results rather than just checking for absence of 500 errors.

Key Changes:

  • Wrapped MySQL JSON_EXTRACT calls with JSON_UNQUOTE for proper string comparison in two query methods
  • Refactored SQL injection test with extracted helper method and improved assertion logic
  • Renamed test method to match project naming conventions

Reviewed changes

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

File Description
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ListFilter.java Fixed MySQL JSON query syntax by adding JSON_UNQUOTE wrapper to getEventSubscriptionAlertType() and getNotificationTemplateCondition() methods
openmetadata-service/src/test/java/org/openmetadata/service/resources/events/EventSubscriptionResourceTest.java Improved SQL injection test with helper method, proper assertion execution, and better test naming

The changes in this PR are well-implemented and address the issues described. The MySQL JSON query fixes correctly align with the existing pattern used elsewhere in the codebase (line 236), and the test improvements ensure assertions always execute regardless of exception handling. The code follows Java best practices and maintains consistency with the project's testing conventions.

Comments suppressed due to low confidence (2)

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ListFilter.java:593

  protected String addCondition(List<String> conditions) {

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ListFilter.java:32

  public String getCondition(String tableName) {

This branch had an error being deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants