โ† All posts
ENGINEERING September 29, 2026 ยท 4 min read

Filtering the answer is not filtering the question

SR
Sentrinel Team
Product & engineering

Sentrinel has a SQL console: a text box where you can ask your telemetry anything the dashboards did not anticipate. On a multi-tenant service, a text box that runs SQL is the most dangerous feature you can ship, and ours had a hole in the one place that mattered. We found it in an audit of our own, and it is closed. This post is how it worked, why it failed, and what replaced it.

How it was scoped

The console let you query a fixed list of tables and refused everything else โ€” no system catalogs, no users, no sessions. To keep one tenant out of another's rows, it wrapped your statement and filtered the output:

SELECT * FROM (<your query>) AS q WHERE app_id IN (<your apps>)

It even insisted your query select app_id, so the filter had something to check.

Why that is not a scope

An output column is whatever the query says it is. SELECT '<one of my app ids>' AS app_id, โ€ฆ produces a column called app_id holding a value the filter accepts โ€” on every row, whichever tenant the row actually came from. The filter was checking a label the query wrote.

And the table check read the names after FROM and JOIN. A table joined with a comma โ€” FROM request_logs, users โ€” has neither in front of it.

The general lesson is older than this bug: a check on the output of a computation is a check on whatever the computation chose to output. If the thing you want to restrict is what the query can read, restrict what it can read.

Scoping the input

The console now narrows the tables themselves before your statement ever sees them. Every table it can name is shadowed by a common table expression of the same name โ€” holding only the selected app's rows:

WITH
  request_logs AS (SELECT * FROM <db>.request_logs WHERE org_id = โ€ฆ AND app_id = โ€ฆ),
  app_logs     AS (SELECT * FROM <db>.app_logs     WHERE org_id = โ€ฆ AND app_id = โ€ฆ),
  โ€ฆ
SELECT * FROM (<your query>) AS console_query LIMIT โ€ฆ

A CTE wins over a table of the same name in name resolution, at every nesting level. A comma join, a subquery in the select list, a CTE of your own that reads request_logs โ€” all of them read the shadow, because the name resolves to it before it resolves to the table. Faking app_id no longer matters: there is nothing else in the rows to fake it over. And because the scope is on the input, you no longer have to select app_id at all.

What is left is making sure a statement cannot name a table some other way:

And it runs with its hands tied

Scoping decides what a query can read. The limits decide how much damage an honest mistake can do:

A console query can be slow, and it can be wrong. It can no longer be large enough to hurt anyone else's dashboards, and it can no longer see anyone else's data.

How we know

The tests do what an attacker would. A second tenant writes rows; then the console is asked, as the first tenant, to fake app_id, to count through a subquery, to join the second tenant's tables with a comma, to use qualified names and SQL-running functions. Every one of those comes back with the first tenant's rows or a refusal โ€” never the second's.

If you find something we missed, please tell us. A text box that runs SQL deserves more than one set of eyes.