Skip to content

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

Merged
ti-srebot merged 2 commits intopingcap:release-3.0from
ti-srebot:release-3.0-ae0057da714e
Feb 20, 2021
Merged

*: introduce new API ParseWithParams (#22499)#22549
ti-srebot merged 2 commits intopingcap:release-3.0from
ti-srebot:release-3.0-ae0057da714e

Conversation

@ti-srebot
Copy link
Contributor

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

cherry-pick #22499 to release-3.0
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/22549

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

git push git@github.com:ti-srebot/tidb.git pr/22549:release-3.0-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

@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.

@bb7133 bb7133 changed the title *: preventing SQL injection (#22499) *: introduce new API ParseWithParams (#22499) Jan 27, 2021
@wshwsh12 wshwsh12 removed their request for review February 5, 2021 08:37
Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox force-pushed the release-3.0-ae0057da714e branch from eab6549 to 54a0d46 Compare February 20, 2021 02:47
Signed-off-by: xhe <xw897002528@gmail.com>
@morgo
Copy link
Contributor

morgo commented Feb 20, 2021

LGTM

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

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

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 20, 2021
@bb7133
Copy link
Member

bb7133 commented Feb 20, 2021

/run-all-tests

@bb7133
Copy link
Member

bb7133 commented Feb 20, 2021

/merge

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

/run-all-tests

@ti-srebot ti-srebot merged commit d9a4917 into pingcap:release-3.0 Feb 20, 2021
@xhebox xhebox deleted the release-3.0-ae0057da714e branch February 20, 2021 04:24
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. type/3.0-cherry-pick

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants