﻿# V5906\. OWASP\. Possible SQL injection\. Potentially tainted data is used to create an SQL command\.

The analyzer has detected that an SQL statement was created using unverified data obtained from an external source\. If this data is compromised, it may cause an SQL injection\.

Such vulnerabilities fall under [A5:2025 Injection](https://top10.owasp.org/2025/A05_2025-Injection/) in the OWASP Top 10 Application Security Risks 2025\.

The example:

```cpp
func ProcessUser(db *sql.DB, r *http.Request) {
  name := r.URL.Query().Get("name")
  query := fmt.Sprintf("SELECT id, name FROM users WHERE name = '%s'", name)
  rows, err := db.Query(query)
  ....
}
```

The value of the `name` variable obtained from the HTTP request is used when an SQL command is created\. Using external data without any verification is dangerous, as it exposes the system to attackers who can inject commands\.

For example, instead of entering the expected username, an attacker might enter a special query\. The database will then retrieve all users' data, which will be processed further\.

An example of a compromised query string for the query shown above:

```cpp
' OR '1'='1
```

To prevent such queries, pass `name` separately from the SQL query text:

```cpp
func ProcessUser(db *sql.DB, r *http.Request) {
  name := r.URL.Query().Get("name")
  query := "SELECT id, name FROM users WHERE name = ?"
  rows, err := db.Query(query, name)
  ....
}
```

In this case, `name` is passed as an argument to the `Query` method\. According to the [documentation](https://go.dev/doc/database/sql-injection), this approach is safe\.