SQL Injection via table names and field names. Case study.
Django's quote_name function wraps table and column names in double quotes without escaping them, so if an application passes user input as a table or field name, an attacker could inject SQL statements. The author notes that Django's other validation layers usually prevent this, making it a niche issue only when developers misuse the API.
renesd.blogspot.com
Published on renesd.blogspot.com
About a year ago I had to implement a system where the table name could be configured for an application. Why would you want to do that?
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
Likely the quote_name function simply wraps identifiers in double quotes without escaping embedded quotes or validating the input, and the underlying database driver does not support parameterised identifiers.
Impact
An attacker could inject arbitrary SQL if an application passes untrusted input as a table or field name, though Django's other validation layers often block this in practice.
What the attacker needed
Application passes user input as table or field name; Django's other validation layers are bypassed
The fix
The author recommends using prepared statements where possible, escaping identifiers correctly per the database engine, disabling multiple statements in the connection, validating input, and documenting dangerous calls.
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.
SQL injection is when an attacker sneaks database commands into input that a program trusts. Here, the problem is that table and column names cannot be safely passed as parameters in some databases, so developers must escape them manually. If they forget, an attacker who controls a table name could run extra SQL commands.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.