> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/web/path-traversal/validating-the-start-of-the-path-directory-traversal.md).

# Validación del inicio del recorrido de directorios de ruta

### Recorrido de rutas de archivos, validación del inicio de la ruta

La aplicación transmite toda la ruta del archivo mediante un parámetro de consulta y solo comprueba que esta ruta **empieza** coincida con la carpeta esperada. Esta validación es insuficiente: añadiendo después del prefijo permitido, es posible acceder a archivos arbitrarios.

#### **Análisis**

El parámetro filename incluye directamente una ruta absoluta, por ejemplo:

```bash
/var/www/images
```

<figure><img src="/files/ba5df1d8878ad387d3d3b7ffcbbbeedc90d67c78" alt=""><figcaption></figcaption></figure>

Si uno intenta un cruce clásico:

```bash
../../../../../etc/passwd
```

la aplicación lo bloquea.

Pero si proporcionamos **la ruta esperada**, seguida de `../` secuencias para salir, la validación no detecta la escapada:

Como la ruta empieza bien con `/var/www/images/`, la comprobación se cumple, pero la resolución final en realidad apunta a `/etc/passwd`.

```bash
/var/www/images/../../../../../etc/passwd
```

<figure><img src="/files/a126e984d846b6183061b610c9ff1ed3dc060ee2" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/es/web/path-traversal/validating-the-start-of-the-path-directory-traversal.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
