Skip to content
SQL injection Write-up Intermediate

A story of one not-a-bug SQL injection

The PHP-MySQLi-Database-Class library's where() method extracts an SQL operator from an array key without validation, allowing an attacker to inject arbitrary SQL when user input is passed as an array. This could let an attacker bypass conditions or extract data from the database.

jarlob.github.io

Published on jarlob.github.io

Recently I was auditing a website for security vulnerabilities. I found few good issues, but one part of the application looked solid - all interactions with database were done through PHP-MySQLi-Database-Class - a helper library that utilized parameterized statements.

The author, on jarlob.github.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The where() method treats an array key as an SQL operator and inserts it into the query without validation.

Impact

An attacker could inject arbitrary SQL into queries, potentially bypassing authentication or extracting data, though the text does not demonstrate a specific impact beyond the injection itself.

What the attacker needed

Application uses the library's where() with user input; user input is passed as an array

The fix

The vulnerability was fixed in version 2.9.3.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

This is about a helper library that many PHP developers use to talk to a database. Normally it uses 'prepared statements', a safe way to send queries where user input is kept separate from the SQL code. But if a developer passes an array as a value, the library takes the array's key and uses it as part of the SQL command without checking it, so an attacker can sneak in extra SQL.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.