Snowflake SQL Injection via Compile-Time Constant Folding with SYSTEM$WAIT
A reporting endpoint was vulnerable to SQL injection, but the application caught execution-time database errors and returned an empty result, blocking standard error-based extraction. The author found that compilation-time errors were still returned to the client, and used the SYSTEM$WAIT function with constant folding to force Snowflake to include session metadata values in a compilation error message.
infosecwriteups.com
Published on infosecwriteups.com
You have confirmed SQL injection against a Snowflake backend. The injected expression executes.
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 application used string substitution to build SQL queries and its error handler only caught execution-time errors, letting compilation errors reach the client.
Impact
An attacker could extract session and connection metadata such as the current database, user, and role, but not table data, because constant folding only works on expressions resolvable without reading tables.
What the attacker needed
Access to the reporting endpoint; a valid session token
The fix
The application should use parameterised queries, validate request bodies, avoid returning any database errors to clients, and tag queries for attribution.
How it was found
- Send a request to the reporting endpoint with a filter_type value containing an unmatched single quote.
- Observe that the response contains a verbose SQL compilation error revealing the generated query structure.
- Inject SYSTEM$WAIT(CURRENT_DATABASE()) into filter_type to force a compilation error that includes the folded database name.
- Read the database name from the error message.
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 user input is inserted into a database query without proper handling, letting an attacker change the query's meaning. Normally attackers try to make the database produce an error that contains secret data, but here the application hid those errors. The author discovered that a different kind of error, produced before the query even runs, was not hidden, and used a built-in function to make that error reveal information.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.