Skip to content

Commit c776ef9

Browse files
authored
Fix path traversal issue on static files (#157)
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.
1 parent 8b598f7 commit c776ef9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cask/src/cask/endpoints/StaticEndpoints.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import cask.model.Request
55
object StaticUtil{
66
def makePathAndContentType(t: String, ctx: Request) = {
77
val leadingSlash = if (t.startsWith("/")) "/" else ""
8-
val path = leadingSlash + (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments)
8+
val path = leadingSlash + (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments.flatMap(cask.internal.Util.splitPath))
99
.filter(s => s != "." && s != "..")
1010
.mkString("/")
1111
val contentType = java.nio.file.Files.probeContentType(java.nio.file.Paths.get(path))

0 commit comments

Comments
 (0)