SQL Injection is a critical vulnerability that can lead to data or system compromise. By
dynamically generating SQL query strings, user input may be able to influence the logic of
the SQL statement. This could lead to an adversary accessing information they should
not have access to, or in some circumstances, being able to execute OS functionality or code.
Replace all dynamically generated SQL queries with parameterized queries. In situations where
dynamic queries must be created, never use direct user input, but instead use a map or
dictionary of valid values and resolve them using a user supplied key.
For example, some database drivers do not allow parameterized queries for > or < comparison
operators. In these cases, do not use a user supplied > or < value, but rather have the
user
supply a gt or lt value. The alphabetical values are then used to look up the > and <
values to be used in the construction of the dynamic query. The same goes for other queries
where
column or table names are required but cannot be parameterized.
Example using parameterized queries with SqlCommand:
string userInput = "someUserInput";
string connectionString = ...;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
String sql = "SELECT name, value FROM table where name=@Name";
using (SqlCommand command = new SqlCommand(sql, connection))
{
command.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar);
command.Parameters["@Name"].Value = userInput;
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetString(1));
}
}
}
}
## medium Finding
**Scanner:** semgrep
**Severity:** medium
**Rule:** gitlab-csharp_injection_rule-SQLInjection
**CWE:** CWE-89
**CRA:** cra-ai-20 — Automatisierte Sicherheitstests (Annex I)
### Description
SQL Injection is a critical vulnerability that can lead to data or system compromise. By
dynamically generating SQL query strings, user input may be able to influence the logic of
the SQL statement. This could lead to an adversary accessing information they should
not have access to, or in some circumstances, being able to execute OS functionality or code.
Replace all dynamically generated SQL queries with parameterized queries. In situations where
dynamic queries must be created, never use direct user input, but instead use a map or
dictionary of valid values and resolve them using a user supplied key.
For example, some database drivers do not allow parameterized queries for `>` or `<` comparison
operators. In these cases, do not use a user supplied `>` or `<` value, but rather have the
user
supply a `gt` or `lt` value. The alphabetical values are then used to look up the `>` and `<`
values to be used in the construction of the dynamic query. The same goes for other queries
where
column or table names are required but cannot be parameterized.
Example using parameterized queries with `SqlCommand`:
```
string userInput = "someUserInput";
string connectionString = ...;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
String sql = "SELECT name, value FROM table where name=@Name";
using (SqlCommand command = new SqlCommand(sql, connection))
{
command.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar);
command.Parameters["@Name"].Value = userInput;
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetString(1));
}
}
}
}
```
For more information on SQL Injection see OWASP:
https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
### Location
**File:** `compliance-agent/rules/cra_semgrep_csharp.cs` (line 31)
### Code
```
var cmd3 = new SqlCommand(sql, conn);
```
### Remediation
None
---
*Fingerprint:* `37f9f897ff5b84caddc4ce64d9cfa409aed9cbe822a3dc3b165642b8b06a9df7`
*Generated by compliance-scanner*
[Open in Prüfwerk / In Prüfwerk öffnen](https://pruefwerk.breakpilot.com/findings?target=6ae9aa2160f5d8045fc570a7)
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
medium Finding
Scanner: semgrep
Severity: medium
Rule: gitlab-csharp_injection_rule-SQLInjection
CWE: CWE-89
CRA: cra-ai-20 — Automatisierte Sicherheitstests (Annex I)
Description
SQL Injection is a critical vulnerability that can lead to data or system compromise. By
dynamically generating SQL query strings, user input may be able to influence the logic of
the SQL statement. This could lead to an adversary accessing information they should
not have access to, or in some circumstances, being able to execute OS functionality or code.
Replace all dynamically generated SQL queries with parameterized queries. In situations where
dynamic queries must be created, never use direct user input, but instead use a map or
dictionary of valid values and resolve them using a user supplied key.
For example, some database drivers do not allow parameterized queries for
>or<comparisonoperators. In these cases, do not use a user supplied
>or<value, but rather have theuser
supply a
gtorltvalue. The alphabetical values are then used to look up the>and<values to be used in the construction of the dynamic query. The same goes for other queries
where
column or table names are required but cannot be parameterized.
Example using parameterized queries with
SqlCommand:For more information on SQL Injection see OWASP:
https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
Location
File:
compliance-agent/rules/cra_semgrep_csharp.cs(line 31)Code
Remediation
None
Fingerprint:
37f9f897ff5b84caddc4ce64d9cfa409aed9cbe822a3dc3b165642b8b06a9df7Generated by compliance-scanner
Open in Prüfwerk / In Prüfwerk öffnen
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.