Looking for the vulnerability index of Invicti's legacy products?
SQL injection in the authentication header - Vulnerability Database

SQL injection in the authentication header

Description

SQL injection (SQLi) is a code injection vulnerability that occurs when an attacker manipulates SQL queries by inserting malicious input into application parameters. This vulnerability specifically affects the authentication header, where unsanitized user input is directly incorporated into SQL statements, allowing attackers to alter the intended query logic and gain unauthorized access to the database.

Remediation

Implement parameterized queries (also known as prepared statements) to prevent SQL injection attacks. Parameterized queries separate SQL code from user input by using placeholders, ensuring that user-supplied data is treated as data only and never as executable code.

Example using PHP PDO:

// Vulnerable code (DO NOT USE)
$username = $_SERVER['HTTP_AUTHORIZATION'];
$query = "SELECT * FROM users WHERE username = '" . $username . "'";
$result = mysqli_query($conn, $query);

// Secure code using prepared statements
$username = $_SERVER['HTTP_AUTHORIZATION'];
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch();
Additional security measures:
• Implement input validation to reject unexpected characters or patterns in authentication headers
• Apply the principle of least privilege to database accounts used by the application
• Use web application firewalls (WAF) as an additional defense layer
• Conduct regular security testing and code reviews to identify injection vulnerabilities
• Never concatenate user input directly into SQL queries under any circumstances