GO-2026-7020: pREST _groupby function-expression SQL injection (incomplete fix of CVE-2025-58450)
pREST groupby function-expression SQL injection (incomplete fix of CVE-2025-58450) in github.com/prest/prest
Other sources
pREST (PostgreSQL REST) is an API that delivers an application on top of a Postgres database. Prior to 2.4.0, the vulnerable parameter is groupby, handled by GroupByClause in adapters/postgres/postgres.go. adapters/postgres/postgres.go uses the weaker isSafeSQLExpression check for this function-expression branch instead of the stricter single-field validator used for select. That check validates only the outer function name against a 13-function allowlist and permits nested subqueries, trailing UNION syntax, and inner pg functions. controllers/crud.go concatenates the GROUP BY expression while parameterizing only WHERE values, allowing attacker-controlled SQL structure into the clause. Default configuration permits unauthenticated access; a restricted installation may require a low-privilege table reader. UNION-based extraction requires compatible column counts and types and was not verified end to end, but a delay-producing function can cause denial of service without that alignment. This issue is fixed in 2.4.0.
— OSV
What the fix did and the gap ---------------------------- The v2.3.0 fix (commit e88dabb) routed the select field through a strict new gate, sanitizeSelectField (postgres.go:947/1003/2097). The sibling groupby path was left on the far weaker isSafeSQLExpression. adapters/postgres/postgres.go, GroupByClause (line 1946): a groupby field that contains balanced parens takes the raw-SQL-expression branch (around lines 1999-2006), gated only by isSafeSQLExpression (line 2001, defined at 2043). That gate validates only the OUTERMOST function name against a 13-entry allowlist and uses a character allowlist that permits spaces, single quotes and parens. It blocks ;, --, / , unbalanced parens and an outer pg prefix, but NOT a trailing UNION SELECT ..., a nested (SELECT ...) subquery, or an inner pg function. sanitizeSelectField (the CVE fix) rejects exactly those.
Input and attacker ------------------- GET /{database}/{schema}/{table}?select=id&groupby=upper((SELECT+1))+UNION+SELECT+currentuser. Sink trace: controllers/crud.go:131 calls GroupByClause unconditionally, concatenates it into sqlSelect (crud.go:133), executed at crud.go:176 with only the WHERE values parameterized. Reached after only a table read-permission check, passable unauthenticated in the default config (the same pipeline and attacker model as the anchor).
Verification level ------------------ EXECUTED with negative controls (agent-run go test ./adapters/postgres/, PASS): isSafeSQLExpression wrongly accepts four payloads and GroupByClause emits them raw (e.g. GROUP BY upper((SELECT 1)) UNION SELECT currentuser, and GROUP BY abs((SELECT 1 FROM pgsleep(3)))); negative controls with ; and -- are rejected; and sanitizeSelectField (the CVE fix) rejects the exact UNION payload the sibling gate accepts. I independently re-confirmed at HEAD that groupby is gated by isSafeSQLExpression (postgres.go:2001) while select uses sanitizeSelectField (postgres.go:947). NOT verified: end-to-end UNION exfiltration against a live Postgres (needs column/type alignment, Postgres-gated). The pgsleep DoS primitive is unconditional and needs no alignment; char-by-char blind extraction is constrained (commas are pre-split, and =/</> are blocked).
Suggested fix ------------- Route groupby through the same strict gate as select (sanitizeSelectField-style: reject nested subqueries, UNION, inner pg functions, and anything past a single allowlisted function call), or parameterize/whitelist the group-by columns.
Also checked and SOUND ---------------------- The other builders (WhereByRequest, OrderByRequest, JoinByRequest, CountByRequest, the jsonb/tsquery paths, ->>having, ident.IsValid) are sound; only the groupby non-having function branch is the weak sibling.
Advisory-source note -------------------- Five-source enumeration: CVE-2025-58450 (GHSA-p46v-f2x8-qp98, "Systemic SQL Injection", GO-2025-3941) and the newer GHSA-qvx3-q8vx-9q3c (which covers select, fixed v2.3.0). Neither mentions groupby / GROUP BY. The systemic advisory's own "nested queries can be performed" note supports the incomplete-fix framing. Not contested.
Dedup ----- Dedup gate clean: no prest/prest blocking verdict in COVERED-INDEX, DISCLOSURE-INDEX or SCOUT-EXCLUDE.
Tooling ------- AI assistance wsa used while investigating. The injection is executed-verified with negative controls (isSafeSQLExpression accepts four UNION/subquery/pgsleep payloads that GroupByClause emits raw, while ;/-- are rejected and the select gate rejects the same UNION payload), and I confirmed at HEAD that groupby uses the weak isSafeSQLExpression while select was hardened with sanitizeSelectField.
— OSV
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
go/github.com/prest/prest/v2to a version that resolves this vulnerability.Fixed in 2.4.0 - Upgrade
Upgrade
github.com/prest/prestto a version that resolves this vulnerability.Fixed in 2.4.0
Event History
Frequently Asked Questions
Which deployments are exposed to unauthenticated exploitation?
Default pREST configuration permits unauthenticated access, so an unauthenticated remote attacker can reach the vulnerable _groupby handling. Restricted installations may require the attacker to have a low-privilege table-reader account.
What input is required to exploit the issue?
An attacker needs to control the _groupby parameter and supply a function-expression that passes the outer-function allowlist. The vulnerable validation can permit nested subqueries, trailing UNION syntax, and inner pg_ functions.
What is the practical impact if data extraction is not possible?
A delay-producing function can be used to cause denial of service without needing UNION column-count or type alignment. UNION-based extraction requires compatible column counts and types and was not verified end to end.
What should operators do if they cannot patch immediately?
Restrict access so untrusted users cannot send requests to the API, and avoid granting low-privilege table-reader access to untrusted users. These measures reduce who can reach the vulnerable _groupby parameter.
How can I determine whether my instance is affected?
Instances running pREST versions prior to 2.4.0 are affected. The issue is fixed in version 2.4.0.