logo

Database

Go Query String Sql Injection

Description

Detects SQL injection vulnerabilities in Go applications using the database/sql package. The detector identifies database query operations where unsanitized user input could be directly concatenated or interpolated into SQL statements, potentially allowing malicious SQL code execution.

Weakness:

297 - SQL injection - Code

Category: Unexpected Injection

Detection Strategy

    Verifies that the database/sql package is imported in the source code

    Identifies database query method calls (like .Query(), .QueryRow(), .Exec())

    Examines the first argument of these query methods for unsafe input

    Checks if the query string contains unsanitized user-controlled data

    Reports a vulnerability if the query parameter is constructed using unsafe string operations with user input

Vulnerable code example

package main

import (
    "database/sql"
    "fmt"
    "net/http"
)
...

✅ Secure code example

package main

import (
    "database/sql"
    "net/http"
)

func secureHandler(w http.ResponseWriter, r *http.Request) {...