Skip to content

Fix directory traversal attack#178

Merged
tomtaylor merged 3 commits intomainfrom
fix-directory-traversal-attack
Apr 22, 2026
Merged

Fix directory traversal attack#178
tomtaylor merged 3 commits intomainfrom
fix-directory-traversal-attack

Conversation

@tomtaylor
Copy link
Copy Markdown
Collaborator

If a caller-supplied document ID or path contains .. or . segments, it's possible to use this to traverse to a different path than intended. For example, a document ID of x/../../_all would cause the request to be sent to /{index}/_doc/x/../../_all, which is resolved to /_all.

Fix this in Snap.Request by validating the path before sending the request, and rejecting any paths that contain traversal segments or are not absolute with a Snap.InvalidPathError error tuple.

If a caller-supplied document ID or path contains `..` or `.` segments, it's
possible to use this to traverse to a different path than intended. For example,
a document ID of `x/../../_all` would cause the request to be sent to
`/{index}/_doc/x/../../_all`, which is resolved to `/_all`.

Fix this in `Snap.Request` by validating the path before sending the request,
and rejecting any paths that contain traversal segments or are not absolute with
`Snap.InvalidPathError`.
Some upstream proxies might decode path segments before forwarding requests to
Snap, which could allow directory-traversal attacks to bypass the existing
validation.

Handle this by decoding the path before validating it, so that encoded traversal
segments like `%2E%2E` or `%2F..%2F` are properly rejected.
@tomtaylor tomtaylor merged commit 3deb07f into main Apr 22, 2026
8 checks passed
@tomtaylor tomtaylor deleted the fix-directory-traversal-attack branch April 22, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant