Skip to content

Commit

Permalink
fix(web-api): percent-decode before path-splitting (#560)
Browse files Browse the repository at this point in the history
This patches a path traversal vulnerability.
  • Loading branch information
tsani authored Aug 23, 2023
1 parent 7f2b6cf commit 1a0c2ef
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/server/learnocaml_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,11 @@ let launch () =
Learnocaml_store.Server.get () >>= fun config ->
let callback conn req body =
let uri = Request.uri req in
let path = Uri.path uri in
let path = Stringext.split ~on:'/' path in
let path =
Uri.path uri |>
Uri.pct_decode |> (* %-decoding must happen before `/`-splitting *)
Stringext.split ~on:'/'
in
let path =
let rec clean = function
| [] | [_] as l -> l
Expand All @@ -605,7 +608,6 @@ let launch () =
in
clean path
in
let path = List.map Uri.pct_decode path in
let query = Uri.query uri in
let args = List.map (fun (s, l) -> s, String.concat "," l) query in
let use_compression =
Expand Down

0 comments on commit 1a0c2ef

Please sign in to comment.