Skip to content

Fix: path traversal in HttpServer default callback - #608

Merged
bsergean merged 1 commit into
masterfrom
fix/path-traversal-httpserver
Sep 10, 2026
Merged

Fix: path traversal in HttpServer default callback#608
bsergean merged 1 commit into
masterfrom
fix/path-traversal-httpserver

Conversation

@bsergean

Copy link
Copy Markdown
Collaborator

Summary

  • The default HttpServer callback built the filesystem path as "." + uri without sanitizing .. segments, letting a remote unauthenticated client read files outside the document root (e.g. GET /../secret.txt).
  • Added sanitizeUri() which resolves . and .. lexically, clamping any escape above the virtual root so the resulting path always stays within the document root.
  • clang-format applied; also fixed a few pre-existing long lines in response_head_file that were over the 100-column limit.

Affected entry points

  • IXHttpServer default connection callback (used by the httpd example and ws httpd command when no custom callback is installed).

Credit

Reported by Yeongtaek Yoo (GitHub: @yt010108).

Test plan

  • Start ws httpd from a directory that has a sibling directory with a secret file.
  • curl http://localhost:<port>/../secret.txt — should return 404, not the file contents.
  • curl http://localhost:<port>/index.html — should still serve normally.

🤖 Generated with Claude Code

The default HttpServer callback built the filesystem path as "." + uri
without sanitizing .. segments, allowing a remote unauthenticated client
to read files outside the document root with a request like
GET /../secret.txt.

Add sanitizeUri() which resolves . and .. lexically, clamping any
attempt to escape above the virtual root so the path stays within the
document root directory.

Reported by Yeongtaek Yoo (GitHub: @yt010108).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bsergean
bsergean merged commit 5da103b into master Sep 10, 2026
7 checks passed
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