
Proof-of-concept and differential lab for CVE-2026-104129, demonstrating SQL injection through prest's _groupby parameter via nested subqueries and trailing UNION SELECT.
_groupby after an incomplete fix| CVE | CVE-2026-104129 |
| Component | prest — adapters/postgres/postgres.go::isSafeSQLExpression / GroupByClause |
| Affected | <= 1.5.5 (and the _groupby path in the v2.3.0-era code carrying the weak validator) |
| Fixed in | commit 084348fa (Fix: six SQL-injection-adjacent security gaps, GHSA-v9v2-98xq-627c) |
| CWE | CWE-89 (SQL Injection), CWE-693 (Protection Mechanism Failure) |
| Impact | The earlier advisory hardened _select with sanitizeSelectField() but left the sibling _groupby path on the weaker isSafeSQLExpression(). That gate validated only the outermost function name against an allowlist and permitted spaces, single quotes and balanced parentheses — so a nested (SELECT ...) subquery or a trailing UNION SELECT ... was accepted and concatenated into the raw GROUP BY clause. controllers/crud.go calls GroupByClause unconditionally and executes the resulting query with only WHERE values parameterized; the table read-permission check is passable unauthenticated in the default configuration |
| Vector | Unauthenticated GET /{db}/{schema}/{table}?_select=id&_groupby=... |
| Trigger | _groupby=upper((SELECT 1)) UNION SELECT current_user |
The vulnerable gate checked balance but not structure:
// postgres.go — pre-fix (excerpt, verbatim in the lab)
funcName := strings.ToLower(strings.TrimSpace(expr[:idx]))
if _, ok := allowedGroupByFunctions[funcName]; !ok { return false }
// ... character scan allows '(' and ')' across the WHOLE expression ...
balance := 0 // balanced parens == "safe", trailing UNION ignored
The fix validates the argument slice only and forbids nested parens:
// fixed (commit 084348fa, verbatim in the lab)
if !strings.HasSuffix(expr, ")") { return false }
args := expr[idx+1 : len(expr)-1]
if strings.ContainsAny(args, "()") { return false }
for _, ch := range args { /* strict character allowlist */ }
The _select injection fix introduced sanitizeSelectField() but did not
route the sibling _groupby parameter through it. GroupByClause still used
isSafeSQLExpression(), which determined safety from the outer function name,
a character allowlist that included parentheses, and a simple balance count.
An expression like upper((SELECT 1)) UNION SELECT current_user has an
allowlisted outer function and balanced parentheses, so it passed and was
appended as raw SQL; the trailing UNION SELECT and the nested subquery were
never inspected. The fix requires the expression to end at the outer closing
paren, rejects any parenthesis inside the argument slice, and applies the
character allowlist to the arguments only — closing both the subquery and
trailing-statement gaps.
| service | image | role |
|---|---|---|
pr-vuln | cve-2026-104129:vuln | validator from 084348fa^ (weak) |
pr-fixed | cve-2026-104129:fixed | validator from 084348fa (hardened) |
poc | cve-2026-104129-poc:local | stdlib-only Python driver |
The lab compiles the verbatim isSafeSQLExpression() and
allowedGroupByFunctions map from each commit with a stub SQL builder that
mirrors the raw clause concatenation in controllers/crud.go. Modes: inject
(trailing UNION), subquery (nested SELECT), normal (allowlisted call) and
comment (already-blocked control).
./run-lab.sh build # builds both sides (golang:1.24-alpine + python3 service)
./run-lab.sh up # cve104129lab network: pr-vuln / pr-fixed
./run-lab.sh sweep
./run-lab.sh down
poc/poc.py (stdlib only):
_groupby → weak outer-name
check → raw GROUP BY with UNION/subquery → data extraction.084348fa / strict argument-slice validation.A standalone full-chain exploit ships at exploit/exploit.py:
python3 exploit/exploit.py --host=pr-vuln
# exit 1 on confirmed injected GROUP BY, 0 on a safe target
_groupby value | pr-vuln (084348fa^) | pr-fixed (084348fa) |
|---|---|---|
upper((SELECT 1)) UNION SELECT current_user | accepted — raw SQL contains the UNION | rejected — plain query |
upper((SELECT secret FROM hidden)) | accepted — nested subquery in SQL | rejected |
upper(name) (control) | accepted | accepted |
upper(name); DROP TABLE users (control) | rejected | rejected |
Captured runs: evidence/check-*-run.txt, evidence/exploit-*-run.txt,
evidence/probe-*-run.txt, evidence/mitigation-*-run.txt,
evidence/exploit-standalone-run.txt, evidence/exploit-standalone-fixed-run.txt,
evidence/versions.txt, evidence/0day-sweep.txt.
cve104129lab
network; Go 1.24 toolchain in the lab images.The hardened validator requires the expression to end with ), bans parens
inside the argument slice, and applies the strict character allowlist only to
those arguments — both the trailing-statement and nested-subquery shapes are
rejected. Legitimate allowlisted expressions still build SQL on the fixed
build, and the previously blocked semicolon/comment payload stays blocked, so
the fix is neither over-broad nor a regression.
README.md this write-up
run-lab.sh environment driver (build / up / sweep / down)
Makefile convenience targets
poc/poc.py the PoC (check / exploit / probe / mitigation)
exploit/exploit.py standalone full-chain exploit
lab/main-vuln.go upstream weak validator + allowlist + stub builder
lab/main-fixed.go upstream hardened validator + allowlist + stub builder
lab/lab.Dockerfile builds both sides with Go 1.24
lab/service.py HTTP wrapper (POST /groupby), child-process isolation
evidence/ captured runs of every mode on both sides
TRACKING.md excluded (working record)