GHSA-FMR6-9J48-XRQP
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') and Missing Authentication for Critical Function in github.com/prest/prest
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-FMR6-9J48-XRQP divulgada · CVSS 8.1 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
### Summary
The `/_PLUGIN/{file}/{func}` endpoint loads a Go shared object (`.so`) file from disk using an attacker-controlled URL path segment with no containment check against the configured plugin directory. The route is also not individually authenticated — it is only covered by a global JWT middleware that is disabled by default (`jwt.default = false`). On a default configuration, an unauthenticated remote attacker can cause the server to load and execute any Go plugin reachable via path traversal from `PluginPath`.
### Details
In `plugins/plugins.go`, `loadFunc()`:
libPath := filepath.Join(plg.cfg.PluginPath, fmt.Sprintf("%s.so", fileName))
...
p, err = plugin.Open(libPath)`fileName` is taken directly from the `{file}` mux route variable with no validation and no containment check before being joined onto `PluginPath` and passed to `plugin.Open`. `filepath.Join` normalizes `..` segments syntactically but does not prevent the resulting path from resolving outside `PluginPath`.
The route is registered in `router/router.go` with a bare handler and no auth wrapper:
router.HandleFunc("/_PLUGIN/{file}/{func}", plg.Handler())Compare this to the codebase's own script-loading feature (`adapters/postgres/script_runner.go`), which correctly guards against this exact class of bug with an explicit two-stage containment check (`withinBase` + symlink-safe `resolvedWithinBase`). No equivalent check exists for plugin loading.
The only nominal protection is the global JWT middleware (`middlewares/config.go`), gated on `cfg.EnableDefaultJWT`, which defaults to `false` (`config/config.go`, `v.SetDefault("jwt.default", false)`; confirmed in the shipped `samples/prest.sample.toml`). So on a default or typical deployment, this endpoint is reachable without any authentication.
### PoC
Tested locally against commit `9070bda7e9ab6b6484e04a0983b8afd61c8315e6` (v2.4.2) by invoking `plugins.New(cfg).Handler()` directly — the same handler `router.go` wires to `/_PLUGIN/{file}/{func}` — with `cfg.PluginPath` set to a legitimate plugin directory and request vars pointing outside it via traversal.
1. Build a plugin outside `PluginPath`:
// /tmp/sample.go
package main
var HTTPVars map[string]string
var URLQuery map[string][]string
func GETsomeFunctionHandler() (string, int) {
return `{"pwned":true}`, 200
}go build -buildmode=plugin -o /tmp/sample.so /tmp/sample.go2. Test harness simulating the route:
package main
import (
"fmt"
"net/http/httptest"
"github.com/gorilla/mux"
"github.com/prest/prest/v2/config"
"github.com/prest/prest/v2/plugins"
)
func main() {
cfg := &config.Prest{
PluginPath: "/var/lib/prest/plugins", // the *intended* plugin directory
}
plg := plugins.New(cfg)
handler := plg.Handler()
req := httptest.NewRequest("GET", "/_PLUGIN/read/func", nil)
vars := map[string]string{
"file": "../../../../tmp/sample", // traverses OUT of PluginPath
"func": "someFunction",
}
req = mux.SetURLVars(req, vars)
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
fmt.Printf("Response Status Code: %d\n", rec.Code)
fmt.Printf("Response Body: %s\n", rec.Body.String())
}3. Run:
go run test_server.goResult:
Response Status Code: 200
Response Body: {"pwned":true}
The plugin at `/tmp/sample.so` — entirely outside the configured `PluginPath` (`/var/lib/prest/plugins`) — was loaded and its exported handler executed, with no authentication check applied, confirming the traversal is fully exploitable to arbitrary code execution when a plugin file is reachable via the traversal path.
Note on remote exploitability: this PoC demonstrates that the traversal-and-load primitive itself is fully exploitable given a `.so` file already present on disk somewhere reachable via traversal. We searched the full `prest` codebase for any file-write or upload endpoint that would let a remote, unauthenticated attacker place such a file, and found none — the only file-write in the codebase is a startup-time self-test write to the already-configured cache/queries directory (`config/config.go`, `ensureDir()`), not reachable via any HTTP endpoint. So on a stock `prest` deployment with no other vulnerabilities, this is not by itself a complete remote exploit chain. It becomes full unauthenticated remote code execution in any environment where an attacker can place a file on disk by any other means (a separate upload vulnerability, a writable shared volume, shared hosting, a compromised CI/deploy pipeline, etc.), or where local/adjacent filesystem access is otherwise available.
### Impact
Type: Path Traversal (CWE-22) leading to Arbitrary Code Execution (CWE-94) when combined with any file-placement primitive.
Who is impacted: Any `prest` deployment where:
- `jwt.default` is not explicitly enabled (the shipped default), and
- the `/_PLUGIN` route is reachable (it is registered unconditionally on non-Windows)
is exposed to unauthenticated attackers being able to trigger loading of any `.so` file reachable via traversal from `PluginPath` — including legitimately-deployed plugins, which may themselves be undesirable to invoke with attacker-chosen HTTP vars/query params, and, where a file-placement vector exists elsewhere, full remote code execution.
### Suggested fix
1. Validate `{file}` against a strict allow-list charset (no path separators), consistent with `ident.IsValid()` used elsewhere in the codebase.
2. Add the same containment check used in `script_runner.go` (`withinBase` + symlink-safe `resolvedWithinBase`) before `plugin.Open` in `loadFunc()`.
3. Require authentication on `/_PLUGIN` independent of the global `jwt.default` toggle, since plugin loading is an inherent code-execution primitive and shouldn't rely on a default-off global switch.
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-fmr6-9j48-xrqpLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
