Skip to content

Escape LIKE wildcards in operation-audit search so terms with % or _ match literally - #4192

Closed
zjncs wants to merge 1 commit into
apache:rocketmq-studiofrom
zjncs:fix/audit-search-like-escape
Closed

zjncs wants to merge 1 commit into
apache:rocketmq-studiofrom
zjncs:fix/audit-search-like-escape

Conversation

@zjncs

@zjncs zjncs commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Motivation

The operation-audit search box passes the raw term straight into LIKE clauses over operator, resource_name and detail (MybatisPlusAuditRepository.findPage and the shared applyFilters used by summarize/exportLogs). Because % and _ are SQL LIKE wildcards:

  • searching for an operator or topic name containing % (e.g. 100%) matches every row whose text merely ends with 100, and
  • _ matches any single character,

so the audit page and its summary cards can report wildly wrong results for these inputs.

Changes

  • Add a private escapeLike helper (same behaviour as the existing QueryHistoryService.escapeLike) and apply it to the search term in both findPage and applyFilters, so the page query, summarize aggregates and exportLogs all match the term literally.

Verification

MybatisPlusAuditRepositoryTest — two new tests:

  • findPageEscapesLikeWildcardsInTheSearchTermTest: searching 100%_ok binds %100\%\_ok% instead of the unescaped pattern.
  • summarizeEscapesLikeWildcardsInEveryAggregateQueryTest: every aggregate query built by summarize (result counts, distinct operators, both hotspot GROUP BYs, latest-at lookup) binds the escaped literal.

Before the fix both new tests fail; after it the class is green (11/11).

$ mvn -f server/pom.xml test -Dtest='MybatisPlusAuditRepositoryTest'
(before) Tests run: 11, Failures: 2, Errors: 0
(after)  Tests run: 11, Failures: 0, Errors: 0

…nd rows containing % or _

The audit search box feeds its raw term into LIKE clauses over operator /
resource_name / detail, so a search like '100%' silently matches every row
whose operator/name/detail ends with '100', and '_' matches any single
character. Escape the LIKE wildcards before building the wrapper, mirroring
the existing QueryHistoryService.escapeLike behaviour, in both the page
query and the summarize/export filter path.

Signed-off-by: zjncs <18910855655@163.com>
Copilot AI lite review requested due to automatic review settings September 9, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Fixes LIKE wildcard escaping in operation-audit search so that % and _ in user-typed search terms are matched literally rather than interpreted as SQL patterns. The escapeLike() helper correctly escapes backslash first, then the two wildcards — this ordering prevents double-escaping. Tests verify both the escaped parameter value and the query wrapper behavior.

Clean, focused fix. LGTM.


Automated review by github-manager-bot

@lizhimins

Copy link
Copy Markdown
Member

Closing as part of consolidating the LIKE-escape work. The escaping is needed, but this patch adds a private escapeLike copy in the audit repository (the third one across #4192 #4193 #4194), and the whole set relies on MySQL's implicit backslash escape character with no explicit ESCAPE clause — which is wrong on H2, where five tests in this suite run.

See #4236: we asked for the shared SqlLikeUtils version with an explicit ESCAPE clause, and that one should land first. Note also that #4191 moved findPage onto applyFilters, so the patch needs rebasing regardless.

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.

4 participants