fix: prevent SQL injection via driver.Valuer error messages#1369
Open
Yanhu007 wants to merge 1 commit into
Open
fix: prevent SQL injection via driver.Valuer error messages#1369Yanhu007 wants to merge 1 commit into
Yanhu007 wants to merge 1 commit into
Conversation
AppendError embeds error messages directly into the SQL query string
without any escaping. A malicious driver.Valuer can return an error
whose message closes the ?!() wrapper and injects arbitrary SQL.
Wrap the error message in single quotes and escape any single quotes
within the message to prevent SQL injection.
Before: ?!(error message here)
After: ?!('error message here')
Fixes uptrace#1307
bevzzz
requested changes
May 8, 2026
Comment on lines
+11
to
+13
| b = append(b, "?!('"...) | ||
| b = appendSanitizedError(b, err.Error()) | ||
| b = append(b, "')"...) |
Collaborator
There was a problem hiding this comment.
Suggested change
| b = append(b, "?!('"...) | |
| b = appendSanitizedError(b, err.Error()) | |
| b = append(b, "')"...) | |
| b = append(b, "?!("...) | |
| b = gen.Dialect().AppendString(b, err.Error()) | |
| b = append(b, ")"...) |
AppendError should probably accept a QueryGen as dependency and use it's AppendString method, which already handles escaping exhaustively.
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.
Security Fix
Fixes #1307
Problem
AppendErrorembeds error messages directly into the SQL query string without any escaping. Adriver.Valuerimplementation can return an error with a crafted message that closes the?!()wrapper and injects arbitrary SQL.Fix
Wrap the error message in single quotes and escape embedded single quotes within the message. This ensures the error message is always treated as a string literal, preventing SQL injection regardless of the error content.