Repository navigation
Fix MySQL JSON query syntax and SQL injection test logic - #24903
Conversation
…and improve test logic Co-authored-by: ayush-shah <[email protected]>
|
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:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
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_EXTRACTcalls withJSON_UNQUOTEfor 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
- This method overrides Filter.addCondition; it is advisable to add an Override annotation.
protected String addCondition(List<String> conditions) {
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ListFilter.java:32
- This method overrides Filter.getCondition; it is advisable to add an Override annotation.
public String getCondition(String tableName) {
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:
JSON_EXTRACTwithJSON_UNQUOTEingetEventSubscriptionAlertType()andgetNotificationTemplateCondition()for MySQL queriesJSON_EXTRACTreturns quoted strings; direct comparison against parameterized values fails without unquotinggetServiceTypeCondition()(line 236)Test Logic Improvements:
test_sqlInjectionPrevention→test_parameterizedQueriesPreventSqlInjectionto match file conventionsassertSqlInjectionAttempt()helper method to eliminate duplicationType of change:
Checklist:
Fixes <issue-number>: <short explanation>💡 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.