Potential fix for code scanning alert no. 3944: Database query built from user-controlled sources#18941
Merged
timvaillancourt merged 1 commit intomainfrom Nov 24, 2025
Merged
Conversation
…from user-controlled sources Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Contributor
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
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18941 +/- ##
=======================================
Coverage 69.77% 69.78%
=======================================
Files 1608 1608
Lines 214865 214867 +2
=======================================
+ Hits 149922 149938 +16
+ Misses 64943 64929 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mattlord
approved these changes
Nov 24, 2025
arthurschreiber
approved these changes
Nov 24, 2025
5 tasks
5 tasks
timvaillancourt
added a commit
to timvaillancourt/vitess
that referenced
this pull request
Nov 30, 2025
…from user-controlled sources (vitessio#18941) Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
timvaillancourt
added a commit
to timvaillancourt/vitess
that referenced
this pull request
Nov 30, 2025
…from user-controlled sources (vitessio#18941) Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
siddharth16396
pushed a commit
to siddharth16396/postpone-complete
that referenced
this pull request
Dec 3, 2025
…from user-controlled sources (vitessio#18941) Signed-off-by: siddharth16396 <siddharth16396@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/vitessio/vitess/security/code-scanning/3944
The best way to fix this problem is to ensure that user-controlled data is never directly executed as a query string without full validation and/or query parameterization.
sqlparameter from the HTTP request is parsed for syntax/statement type, but is then immediately provided as the query to the database.sqlparser.VExplainStmt) (instead of trusting and forwarding the original string from the user), so that any malicious content or injected payloads are dropped. This is known as canonicalization and is a strong defense if parameterization is unavailable.VExplainendpoint (inapi.goandvtsql.go) to only execute the reconstructed, canonicalized query. Do not use the original user input directly.VExplaincall chain, so only requires modification inapi.goandvtsql.go.sqlparser.String(stmt)(after verifying type).Files/regions:
go/vt/vtadmin/api.goat the VExplain endpoint: after parsing and typechecking, reconstruct the query from AST before passing toc.DB.VExplain.go/vt/vtadmin/vtsql/vtsql.go: Ensure that the query string passed toQueryContextis the canonicalized version.Suggested fixes powered by Copilot Autofix. Review carefully before merging.