Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path traversal issue on static files #157

Merged
merged 1 commit into from
Dec 27, 2024
Merged

Conversation

Maeeen
Copy link
Contributor

@Maeeen Maeeen commented Dec 27, 2024

I discovered that there is a path traversal vulnerability with static files. Here is a repository that showcases the issue.

In StaticUtil (StaticEndpoints.scala), the ctx.remainingPathSegments is not properly sanitized and is priorly decoded in Main.scala. Therefore, if a static endpoint has a remaining path segment having / (e.g. if a client sends a static/..%2F/hi.txt), filter will fail to filter the .. and the path static/../hi.txt will be returned to get returned to the client, which should be prohibited.

Before this commit, it is possible to do path traversals with static files. In `StaticUtil` (`StaticEndpoints.scala`), the `ctx.remainingPathSegments` is not properly sanitized and is priorly decoded in `Main.scala`. Therefore, if a static endpoint has a remaining path segment having `/` (e.g. if a client sends a `static/..%2F/hi.txt`), `filter` will fail to filter and the path `static/../hi.txt` will be returned, which should be prohibited.
@lihaoyi
Copy link
Member

lihaoyi commented Dec 27, 2024

The issue looks valid but the fix looks subtle and non-obvious. Could you add a unit test in cask/test/src/test/cask to minimize the problem and validate the fix is working?

@lihaoyi lihaoyi merged commit c776ef9 into com-lihaoyi:master Dec 27, 2024
4 of 5 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.

2 participants