> 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/ru/web/path-traversal/validating-the-start-of-the-path-directory-traversal.md).

# Проверка начала обхода путей в каталоге

### Обход путей к файлу, проверка начала пути

Приложение передаёт полный путь к файлу через параметр запроса и проверяет только, что этот путь **начинается** соответствует ожидаемой папке. Этой проверки недостаточно: добавив после разрешённого префикса, можно получить доступ к произвольным файлам.

#### **Анализ**

Параметр filename напрямую включает абсолютный путь, например:

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

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

Если попробовать классический обход:

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

приложение блокирует его.

Но если мы укажем **ожидаемый путь**, за которым следуют `../` последовательности для выхода за пределы, проверка не обнаруживает обход:

Поскольку путь начинается корректно с `/var/www/images/`, проверка проходит, но итоговое разрешение на самом деле указывает на `/etc/passwd`.

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

<figure><img src="/files/133ef5dc2637c95387f4df73ed7ad0246e2423fa" 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/ru/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.
