Anatomy of an Incident: SQL Injection Through a “Safe” Filter
An optional filter parameter walked straight past the allowlist that guarded the main query. Here’s how I led the response, and what the postmortem changed.
- An external researcher reported a SQL injection in a multi-tenant analytics API. The main query field was safe; an optional filter parameter next to it was not.
- That parameter was concatenated into database object names, so it slipped past the allowlist that guarded the main query and could read files from inside the container, including a Kubernetes service-account token.
- I led the response: reproduced it, measured the blast radius, shipped a hotfix, and verified the fix with before-and-after tests. This is the playbook I followed and the lessons that outlived the bug.
The report
The incident started the way the good ones do: a clear report from an external researcher, not an alert at 3am. The claim was a SQL injection in an endpoint that runs analytical queries, backed by DuckDB.
That was surprising, because this endpoint had been security-reviewed before. The query field users send is parsed and checked against an allowlist: dangerous functions and statements are rejected before anything runs. On paper, SQL injection was handled.
The report was about a different field. Alongside the query, the request accepts an optional partition filter, a performance hint that narrows which slices of data to scan. Nobody thought of it as attacker-controlled SQL. It turned out to be exactly that.
Why a “safe” endpoint wasn’t
The allowlist only ever saw the query field. The partition filter took a different path: its value was pasted directly into the name of a database object the server generates for each query, roughly CREATE SCHEMA ..._<your value>_cache. No allowlist, no parameter binding, just string concatenation.
So a semicolon in that value ended the generated statement, and anything after it ran as a brand-new statement the validator never inspected.
To turn that into data theft, the researcher used an error as an oracle. DuckDB can read a file into a string; cast that string to a number and it fails with a conversion error that quotes the value it couldn’t convert. Point it at a sensitive file and the error message hands you the contents. In the worst case that reached the container’s Kubernetes service-account token, the credential a pod uses to talk to the cluster.
How I ran the response
A good report is a starting point, not a verdict. My job as incident lead was to turn it into facts the team could act on, and then to close it out. Five phases:
1. Triage. Confirm it’s real and set severity before debating fixes. Unauthenticated-adjacent SQL injection that can read a cluster credential is as bad as it gets, so this was a P0 from the first read. I opened the incident, pulled in the owning team, and wrote the first status update in plain language: what we knew, what we didn’t, and what we were doing next.
2. Reproduce. A finding you can’t reproduce is an argument; a finding you can reproduce is a fact. I rebuilt the exploit end to end in a safe environment and automated it, so anyone could run the same request and see the same result. That script became the shared source of truth and, later, the test for the fix.
3. Contain. The right first fix is the smallest one that stops the bleeding. We didn’t redesign anything under pressure. The hotfix did two things: it removed the dangerous parameter so that path stopped accepting input at all, and it disabled the database’s file-access abilities (external file reads and loading extra extensions) so that even if something slipped through, there was nothing sensitive to reach. One change removes the door; the other empties the room behind it.
4. Verify. This is the step people skip, and the one I care about most. A hotfix isn’t done because it merged; it’s done because you proved it works. I ran the exploit before the fix (to capture the exact failure), then after, and checked three things: the attack is now rejected, legitimate queries still work, and the file-read trick returns nothing even if someone forces the old path. Before-and-after evidence, not a thumbs-up in a channel.
5. Postmortem. Then the part that stops it happening again.
What the postmortem changed
The bug was a missing bind parameter. The lesson was about how we review, and that’s what I wrote up:
We also made the containment permanent: locking down the database’s file access became the default everywhere, not a reaction. Defense in depth meant the scariest part of the chain, reading a real secret, was dead even if the injection ever came back.
The takeaway
Two things travel from this to any team. For builders: the moment user input becomes part of a name, a path, or any string your code assembles into a command, it’s injection surface, even when the obvious field is locked down. Bind parameters, or don’t let user values near generated SQL.
For responders: your value in an incident isn’t knowing the answer first. It’s turning a report into something reproducible, shipping the smallest fix that stops it, proving the fix works, and writing the lesson down so the next person inherits it. That loop is the same whether the trigger is a researcher’s email or a pager at 3am.
This is based on an incident I helped lead under an authorized disclosure process. It was fixed before publication. Product names, endpoints, internal systems and specifics have been generalized, and no real secrets or exploit payloads are shown.