Skip to content

*: introduce new API ParseWithParams (#22499)#22547

Merged
ti-srebot merged 3 commits intopingcap:release-5.0-rcfrom
ti-srebot:release-5.0-rc-ae0057da714e
Feb 2, 2021
Merged

*: introduce new API ParseWithParams (#22499)#22547
ti-srebot merged 3 commits intopingcap:release-5.0-rcfrom
ti-srebot:release-5.0-rc-ae0057da714e

Conversation

@ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Jan 27, 2021

cherry-pick #22499 to release-5.0-rc
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr https://github.com/pingcap/tidb/pull/22547

After apply modifications, you can push your change to this PR via:

git push git@github.com:ti-srebot/tidb.git pr/22547:release-5.0-rc-ae0057da714e

What problem does this PR solve?

Problem Summary: This PR adds a new API ParseWithParams to help process unsafe arguments than just fmt.Sprintf. Also a helper API ExecuteInternal that is using ParseWithParams and ExecuteStmt.

I did not use PrepareStmt since it is not possible to use placeholder like select * from t where c in ?. But we do have such requirement.

ExecuteInternal is redefined to use ParseWithParams and always use utf8 charset for safety. But it is still needed to modify cases like ExecuteInternal(fmt.Sprintf(...)).

ExecRestrictedSQL is too large, thus it is both annoying and duplicated to write a new RestrictedSQLExecutor based on ParseWithParams. From the git history, this is a very legacy API that is 4 or 5 years old. It should be removed/refactored in further works. So the current plan is, write like ExecRestrictedSQL(session.EscapeSQL(sql, args...)). And it will goes to the modified ExecuteInternal eventually to use utf8 charset to prevent attacks based on charsets.

Check List

Tests

  • Unit test
  • Integration test

Release note

  • No release note

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot ti-srebot requested a review from a team as a code owner January 27, 2021 03:05
@ti-srebot ti-srebot requested review from wshwsh12 and removed request for a team January 27, 2021 03:05
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@xhebox you're already a collaborator in bot's repo.

Signed-off-by: xhe <xw897002528@gmail.com>
@morgo
Copy link
Contributor

morgo commented Jan 27, 2021

LGTM

@ti-srebot
Copy link
Contributor Author

@morgo, Thanks for your review. The bot only counts LGTMs from Reviewers and higher roles, but you're still welcome to leave your comments. See the corresponding SIG page for more information. Related SIGs: execution(slack),sql-infra(slack).

@bb7133 bb7133 changed the title *: preventing SQL injection (#22499) *: introduce new API ParseWithParams (#22499) Jan 27, 2021
@morgo
Copy link
Contributor

morgo commented Feb 2, 2021

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 2, 2021
@bb7133
Copy link
Member

bb7133 commented Feb 2, 2021

LGTM

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 2, 2021
@bb7133
Copy link
Member

bb7133 commented Feb 2, 2021

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 2, 2021
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot merged commit 0f873db into pingcap:release-5.0-rc Feb 2, 2021
@xhebox xhebox deleted the release-5.0-rc-ae0057da714e branch February 4, 2021 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sig/execution SIG execution sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants