llamaCVEVulnerability Intelligence
/
Advisory · GitHub · npm · knowns

GHSA-FPXV-C555-RHM3

Arbitrary File Read via POST /api/templates/preview templateFile

Parche disponible
Descargar PNG JSON
CVSS 3.1
7.5
Alta
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche el mismo día de la divulgación
Exposición96 dDesde la divulgación, 16 ago 2026, 5:52 a. m.
Detección94 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaSeguir
Remediar en la ventana regular de mantenimiento
Estimación de Llama con el árbol SSVC de CISA a partir de vector CVSS 3.1 y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, automatizable e impacto técnico parcial. Hay versiones corregidas disponibles.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada +1
Explotación
Remediación
Parche 0.30.0
Monitoreo
Detectada +1
16 ago 26
19 nov 26
21 nov 26
16 ago 26
9 sept 26
3 oct 26
28 oct 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-FPXV-C555-RHM3 divulgada · CVSS 7.5 (GitHub)
Remediación Parche 0.30.0 knowns · 0 d desde divulgación
Divulgación Modificada Última actualización del registro
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Overview

Verified. A critical Arbitrary File Read vulnerability exists in the Knowns template preview endpoint. The `POST /api/templates/preview` handler accepts a user-controlled `templateFile` parameter and concatenates it with the template directory path using `filepath.Join()` without any path containment validation.

Because `filepath.Join` natively resolves `../` sequences and absolute paths are implicitly accepted, an attacker can escape the template directory sandbox and read arbitrary files on the host filesystem, including sensitive system files (`/etc/passwd`), application configuration, environment variables, and private keys. The file content is returned verbatim in the API response. This endpoint is accessible without authentication in the default deployment.

Affected paths

| File Path | Role | Vulnerability & Execution Impact |
| :--- | :--- | :--- |
| `internal/server/routes/templates.go` | Vulnerable Sink | Arbitrary File Read via Path Traversal (CWE-22): The `preview()` handler calls `filepath.Join(tmpl.Path, templateFile)` and passes the result directly to `os.ReadFile()` without validating that the resolved path remains within `tmpl.Path`. |

Root Cause

Missing Path Containment Validation

In `internal/server/routes/templates.go`, the `preview()` function handles the `/api/templates/preview` endpoint:

func (tr *TemplateRoutes) preview(w http.ResponseWriter, r *http.Request) {
    var req previewTemplateRequest
    if err := decodeJSON(r, &req); err != nil {
        respondError(w, http.StatusBadRequest, "invalid request body: "+err.Error())
        return
    }

    tmpl, err := tr.getStore().Templates.Get(req.Name)
    if err != nil {
        respondError(w, http.StatusNotFound, "template not found: "+err.Error())
        return
    }

    templateFile := req.TemplateFile  // Attacker-controlled input
    if templateFile == "" {
        templateFile = "main.hbs"
    }

    hbsPath := filepath.Join(tmpl.Path, templateFile)  // Path traversal resolved here
    hbsContent, err := os.ReadFile(hbsPath)  // VULNERABLE: No containment check
    if err != nil {
        respondError(w, http.StatusNotFound, "template file not found: "+templateFile)
        return
    }

    rendered := string(hbsContent)
    // ... variable substitution ...

    respondJSON(w, http.StatusOK, map[string]interface{}{
        "files": []previewFileResult{
            {Path: destPath, Content: rendered},  // File content leaked in response
        },
    })
}

Critical Flaws:
- `templateFile` is taken directly from the JSON request body with no sanitization
- `filepath.Join` resolves `../` sequences natively (e.g., `../../../../etc/passwd`)
- Absolute paths are implicitly accepted (e.g., `/etc/shadow`)
- No post-Join containment check (e.g., `strings.HasPrefix(hbsPath, tmpl.Path)`) is performed
- File content is returned verbatim in the HTTP response

Compounding Factor - Unauthenticated Access

Due to the previously identified Auth Bypass vulnerability (`AuthManager.Middleware` is a no-op when `!am.HasPassword()`), the `/api/templates/preview` endpoint is fully accessible without credentials when the server is started without a password.

Attack Vector

| Phase | Request / Action | Effect |
| :--- | :--- | :--- |
| 1. Recon | `GET /api/templates` | Attacker enumerates valid template names (e.g., `go-feature`, `react-starter`). |
| 2. Path Traversal | `POST /api/templates/preview` with `templateFile=../../../../../../etc/passwd` | Server resolves path to `/etc/passwd` via `filepath.Join`. |
| 3. File Read | `os.ReadFile("/etc/passwd")` executes | File content is read from disk. |
| 4. Data Exfiltration | Response contains `files[0].content` with full file contents | Attacker receives the entire file in the JSON response. |

High-Value Targets:
- `/etc/passwd`, `/etc/shadow` - User enumeration and password hash theft
- `~/.ssh/id_rsa`, `~/.ssh/authorized_keys` - SSH private key theft and persistence
- `.env`, `config.json` - Environment variables and secrets
- `/proc/self/environ` - Process environment variables (may contain API keys, tokens)
- Application source code and database files

Analysis

Classic Path Traversal in File Read Primitive

This is a textbook Path Traversal (CWE-22) vulnerability. The code trusts user input to construct a file path and passes it directly to `os.ReadFile()` without validation. The use of `filepath.Join` does not provide security; it merely normalizes the path, resolving `../` sequences and collapsing redundant separators.

hbsPath := filepath.Join(tmpl.Path, templateFile)

If `tmpl.Path` is `/home/user/.knowns/templates/go-feature` and `templateFile` is `../../../../../../etc/passwd`, the result is:

/home/user/.knowns/templates/go-feature/../../../../../../etc/passwd
→ /etc/passwd

The code then reads this file and returns its contents in the response:

hbsContent, err := os.ReadFile(hbsPath)
// ...
rendered := string(hbsContent)
// ...
respondJSON(w, http.StatusOK, map[string]interface{}{
    "files": []previewFileResult{
        {Path: destPath, Content: rendered},  // Full file content leaked
    },
})
Lack of Defense-in-Depth

The handler implements zero security controls:
- No input validation (rejecting `..`, `/`, `\`)
- No path canonicalization followed by prefix checking
- No use of secure path libraries (e.g., Go's `fs.ValidPath`)
- No rate limiting or anomaly detection for suspicious paths

Fix

*Patch is available right now at New Release https://github.com/knowns-dev/knowns/releases.*

Vector CVSS 3.1

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:L
BajaAlta
PrivilegiosPR:N
NingunoBajosAltos
InteracciónUI:N
NingunaRequerida
AlcanceS:U
CambiadoSin cambio
ConfidencialidadC:H
AltoBajoNinguno
IntegridadI:N
AltoBajoNinguno
DisponibilidadA:N
AltoBajoNinguno
Score de explotaciónQué tan fácil y probable es que la exploten
10.0/ 10Muy alto
Vector 10.0 (muy fácil) · sin evidencia de explotación.
Versiones

Rangos afectados

Afectada Corregida Última
knowns≤ 0.29.1
0.29.1
0.35.0
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
npmknowns
Corregida 0.30.0 0 d 0.35.0 no afectada
Versiones corregidas0.30.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/knowns-dev/knowns/security/advisories/GHSA-fpxv-c555-rhm3

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.