-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always make sure to escape all strings #17649
Always make sure to escape all strings #17649
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Does this PR need to be tested by the benchmarking system? |
These are not in the hot path, so I don't think that really provides much value. |
2550c89
to
a74da36
Compare
Don't directly interpolate these strings. We don't know of any user controllable ways to do this, but it's still too risky to ever do this. We always need to escape all strings. Ideally we refactor this as well to use better statement binding in the future. Signed-off-by: Dirkjan Bussink <[email protected]>
a74da36
to
359128d
Compare
Are there no benchmarks covering vreplication performance? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17649 +/- ##
==========================================
- Coverage 67.75% 67.74% -0.02%
==========================================
Files 1586 1586
Lines 255726 255753 +27
==========================================
- Hits 173261 173252 -9
- Misses 82465 82501 +36 ☔ View full report in Codecov by Sentry. |
I don't know that, but these changes here affect the metadata tracking about |
Ah, OK. |
Signed-off-by: Dirkjan Bussink <[email protected]>
@@ -231,10 +231,15 @@ func (tr *Tracker) saveCurrentSchemaToDb(ctx context.Context, gtid, ddl string, | |||
} | |||
defer conn.Recycle() | |||
|
|||
// We serialize a blob here, encodeString is for strings only | |||
// and should not be used for binary data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found this with cleaning up the helpers, that here we were encoding a blob as a string which shouldn't be done.
This needs to be then quoted once everything is properly escaped to be inserted. Signed-off-by: Dirkjan Bussink <[email protected]>
Signed-off-by: Dirkjan Bussink <[email protected]>
@@ -627,9 +626,7 @@ func ReverseWorkflowName(workflow string) string { | |||
// this public, but it doesn't belong in package workflow. Maybe package sqltypes, | |||
// or maybe package sqlescape? | |||
func encodeString(in string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This identical func
is defined in several files, should we make a common helper or just use sqltypes.EncodeStringSQL(...)
directly? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can clean up these as well now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timvaillancourt (and also @mattlord since you asked me about this too) Given that I aim to back port this, I think this is better / safer in a separate change. Making this change is a lot of churn / changes across many files which makes the back port harder.
So currently thinking of doing this cleanup then in a follow up PR that we don't need to back port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍. Added one optional question/nit re: func encodeString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @dbussink !
Signed-off-by: Dirkjan Bussink <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Signed-off-by: Dirkjan Bussink <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Signed-off-by: Dirkjan Bussink <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Don't directly interpolate these strings. We don't know of any user controllable ways to do this, but it's still too risky to ever do this. We always need to escape all strings.
Ideally we refactor this as well to use better statement binding in the future.
Marked this also for backports out of an abundance of care. We don't know of any way this would be abused, but we don't want to take the risk here either.
Related Issue(s)
https://github.com/vitessio/vitess/security/code-scanning/1928
https://github.com/vitessio/vitess/security/code-scanning/369
Checklist