Skip to content

Commit

Permalink
Fix path traversal issue on static files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Maeeen committed Dec 27, 2024
1 parent 8b598f7 commit 68c2e4b
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 68c2e4b

Please sign in to comment.