Skip to content

[release-nextgen-202609] syncer(dm): quote the validator WHERE identifiers - #13027

Open
ti-chi-bot[bot] wants to merge 2 commits into
pingcap:release-nextgen-202609from
ti-chi-bot:cherry-pick-13008-to-release-nextgen-202609
Open

ti-chi-bot[bot] wants to merge 2 commits into
pingcap:release-nextgen-202609from
ti-chi-bot:cherry-pick-13008-to-release-nextgen-202609

Conversation

@ti-chi-bot

@ti-chi-bot ti-chi-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This is an automated cherry-pick of #13008

/assign GMHDBJD

Issue Number: close #13007

What problem does this PR solve?

Cond.GetWhere (dm/syncer/validator_cond.go) builds the WHERE clause of the DM validator's verification query by pasting unique-index column names into the SQL text unquoted. Column names come from the upstream table schema, so a crafted name (e.g. a` in (1) -- ) injects SQL into SELECT COUNT(*) FROM <table> WHERE ....

What is changed and how it works?

Quote every identifier with backticks and double any embedded backtick. The single- and multi-column forms both go through the helper; expected WHERE strings in the tests are updated and a backtick-named primary-key column covers the escaping.

Check List

Tests

  • Unit test
  • go test ./dm/syncer/

Questions

Will it cause performance regression or break compatibility?

No behavior change for ordinary column names.

Release note

Fix SQL injection in the DM validator: unique-index column names are now quoted in the verification query.

Summary by CodeRabbit

  • Bug Fixes
    • Generated database filters now quote column names with backticks and escape embedded backticks, helping ensure names are handled correctly in queries.
    • Single-column and composite-column filters retain their existing matching behavior, parameter placeholders, and bound values.

Cond.GetWhere pasted unique-index column names into the verification
query unquoted. Column names come from the upstream table schema, so a
crafted name (e.g. `a` in (1) -- `) could inject SQL into the validator's
COUNT query. Quote every identifier with backticks, doubling any embedded
backtick, and cover the escaping with a test.
TestValidatorWorkerUsesVisibleColumns expected the unquoted WHERE clause;
the query now quotes the unique-index column name.
@ti-chi-bot ti-chi-bot Bot added the area/dm Issues or PRs related to DM. label Nov 26, 2026
@ti-chi-bot ti-chi-bot Bot added the lgtm label Nov 26, 2026
@ti-chi-bot ti-chi-bot Bot added do-not-merge/cherry-pick-not-approved release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Nov 26, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 26, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign gmhdbjd for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

Ask an organization administrator to verify that this bot has an active assigned CodeRabbit review seat. See the seat-assignment guide. After the seat is confirmed, request a review again.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eedfd2e9-6d88-4a5a-bdba-ac63961d27d6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ti-chi-bot ti-chi-bot Bot added the contribution This PR is from a community contributor. label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dm Issues or PRs related to DM. contribution This PR is from a community contributor. do-not-merge/cherry-pick-not-approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202609

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant