Skip to content

fix: SQL query validator bypasses#156

Open
jxom wants to merge 1 commit intomainfrom
fix/query-validator-bypasses
Open

fix: SQL query validator bypasses#156
jxom wants to merge 1 commit intomainfrom
fix/query-validator-bypasses

Conversation

@jxom
Copy link
Copy Markdown
Member

@jxom jxom commented Mar 31, 2026

Fix three audit findings in the query validator:

1. GROUP BY GROUPING SETS Skips Function Allowlist

Expressions inside GROUPING SETS modifiers (and GROUP BY ALL modifiers) were not validated, allowing set_config() session poisoning via:

SELECT 1 FROM blocks GROUP BY ALL GROUPING SETS ((set_config('a','b',true)))

2. Aggregate Argument ORDER BY Skips Function Allowlist

Function calls inside ORDER BY within aggregate arguments were not validated:

SELECT string_agg(hash, ',' ORDER BY set_config('a','b',true)) FROM blocks

3. Ipad/rpad/repeat Memory Exhaustion DoS

lpad(), rpad(), and repeat() with large length arguments could allocate unbounded memory. Added a 100,000 cap on the length argument:

SELECT lpad('x', 999999999) FROM blocks  -- now rejected

All three bypasses now have unit tests verifying rejection and that normal usage still works.

Fix three audit findings in the query validator:

1. Critical: GROUP BY GROUPING SETS clause skipped function allowlist.
   Expressions inside GROUPING SETS modifiers (and GROUP BY ALL modifiers)
   were not validated, allowing set_config() session poisoning.

2. High: Aggregate argument ORDER BY clause skipped function allowlist.
   Function calls inside ORDER BY within aggregate args (e.g.
   string_agg(x, ',' ORDER BY set_config(...))) were not validated.

3. High: lpad/rpad/repeat with large length arguments allowed memory
   exhaustion DoS. Added validation capping length args at 100,000.

Amp-Thread-ID: https://ampcode.com/threads/T-019d458d-01b9-76ca-9fb1-ab93d421fa53
Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant