GHSA-FPXV-C555-RHM3
Arbitrary File Read via POST /api/templates/preview templateFile
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| 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 |
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/passwdThe 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.*
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmknowns |
Corregida | 0.30.0 | 0 d | 0.35.0 no afectada |
0.30.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/knowns-dev/knowns/security/advisories/GHSA-fpxv-c555-rhm3Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
