Skip to content

Commit

Permalink
Fix path traversal issue on static files (#157)
Browse files Browse the repository at this point in the history
I discovered that there is a path traversal vulnerability with static
files. Here is a
[repository](https://github.com/Maeeen/cask-static-path-traversal-issue)
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.
  • Loading branch information
Maeeen authored Dec 27, 2024
1 parent 8b598f7 commit c776ef9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cask/src/cask/endpoints/StaticEndpoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cask.model.Request
object StaticUtil{
def makePathAndContentType(t: String, ctx: Request) = {
val leadingSlash = if (t.startsWith("/")) "/" else ""
val path = leadingSlash + (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments)
val path = leadingSlash + (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments.flatMap(cask.internal.Util.splitPath))
.filter(s => s != "." && s != "..")
.mkString("/")
val contentType = java.nio.file.Files.probeContentType(java.nio.file.Paths.get(path))
Expand Down

0 comments on commit c776ef9

Please sign in to comment.