Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vulnerabilities/sqlinjection/detect_sql_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
func detectSQLInjection(query string, userInput string, dialect int) int {
// Lowercase versions of query and user input
queryLowercase := strings.ToLower(query)
userInputLowercase := strings.ToLower(userInput)
userInputLowercase := strings.TrimSpace(strings.ToLower(userInput))

if shouldReturnEarly(queryLowercase, userInputLowercase) {
return sqlInjectionSafe
Expand Down
6 changes: 6 additions & 0 deletions vulnerabilities/sqlinjection/detect_sql_injection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func TestIsSQLInjection(t *testing.T) {
first_name,
last_name
FROM users WHERE email_lowercase = '' or 1=1 -- a',`, "' OR 1=1 -- a"},

// it detects injection when user input has trailing whitespace (trimmed by DB driver)
{
"INSERT INTO pets (name, owner) VALUES ('x', 'dummy'), ('injected', 'hacker'); --', 'owner')",
"x', 'dummy'), ('injected', 'hacker'); -- ",
},
}

for _, tt := range tests {
Expand Down
Loading