Skip to content

Commit f7d087b

Browse files
authored
Merge pull request #5877 from last-genius/private/asultanov/uri-path
CP-50181: Percent decode all Uri paths before using them
2 parents bc7e730 + ba3f0e7 commit f7d087b

File tree

13 files changed

+24
-25
lines changed

13 files changed

+24
-25
lines changed

ocaml/libs/http-lib/http.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ module Url = struct
923923
in
924924
let data =
925925
{
926-
uri= (match Uri.path uri with "" -> "/" | path -> path)
926+
uri= (match Uri.path_unencoded uri with "" -> "/" | path -> path)
927927
; query_params= Uri.query uri |> List.map query
928928
}
929929
in
@@ -936,7 +936,7 @@ module Url = struct
936936
| Some "https" ->
937937
(scheme ~ssl:true, data)
938938
| Some "file" ->
939-
let scheme = File {path= Uri.path uri} in
939+
let scheme = File {path= Uri.path_unencoded uri} in
940940
(scheme, {data with uri= "/"})
941941
| _ ->
942942
failwith "unsupported URI scheme"

ocaml/libs/http-lib/http_svr.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ let request_of_bio_exn ~proxy_seen ~read_timeout ~total_timeout ~max_length bio
374374
(* Request-Line = Method SP Request-URI SP HTTP-Version CRLF *)
375375
let uri_t = Uri.of_string uri in
376376
if uri_t = Uri.empty then raise Http_parse_failure ;
377-
let uri = Uri.path uri_t |> Uri.pct_decode in
377+
let uri = Uri.path_unencoded uri_t in
378378
let query = Uri.query uri_t |> kvlist_flatten in
379379
let m = Http.method_t_of_string meth in
380380
let version =

ocaml/libs/open-uri/open_uri.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let with_open_uri ?verify_cert uri f =
7474
)
7575
)
7676
| Some "file" ->
77-
let filename = Uri.path_and_query uri in
77+
let filename = Uri.path_and_query uri |> Uri.pct_decode in
7878
let sockaddr = Unix.ADDR_UNIX filename in
7979
let s = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
8080
finally

ocaml/message-switch/switch/switch_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ let make_server config trace_config =
222222
let open Message_switch_core.Protocol in
223223
Cohttp_lwt.Body.to_string body >>= fun body ->
224224
let uri = Cohttp.Request.uri req in
225-
let path = Uri.path uri in
225+
let path = Uri.path_unencoded uri in
226226
match In.of_request body (Cohttp.Request.meth req) path with
227227
| None ->
228228
error "<- [unparsable request; path = %s; body = %s]" path

ocaml/nbd/src/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let handle_connection fd tls_role =
5959
>>= fun session_id -> f uri rpc session_id
6060
in
6161
let serve t uri rpc session_id =
62-
let path = Uri.path uri in
62+
let path = Uri.path_unencoded uri in
6363
(* note preceeding / *)
6464
let vdi_uuid =
6565
if path <> "" then String.sub path 1 (String.length path - 1) else path

ocaml/vhd-tool/src/impl.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,9 @@ let endpoint_of_string = function
787787
if he = [] then raise Not_found ;
788788
return (Sockaddr (List.hd he).Unix.ai_addr)
789789
| Some "unix", _ ->
790-
return (Sockaddr (Lwt_unix.ADDR_UNIX (Uri.path uri')))
790+
return (Sockaddr (Lwt_unix.ADDR_UNIX (Uri.path_unencoded uri')))
791791
| Some "file", _ ->
792-
return (File (Uri.path uri'))
792+
return (File (Uri.path_unencoded uri'))
793793
| Some "http", _ ->
794794
return (Http uri')
795795
| Some "https", _ ->

ocaml/xapi-guard/lib/server_interface.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ let serve_forever_lwt path callback =
7777
Lwt.return cleanup
7878

7979
let serve_forever_lwt_callback rpc_fn path _ req body =
80-
let uri = Cohttp.Request.uri req in
81-
match (Cohttp.Request.meth req, Uri.path uri) with
82-
| `POST, _ ->
80+
match Cohttp.Request.meth req with
81+
| `POST ->
8382
let* body = Cohttp_lwt.Body.to_string body in
8483
let* response =
8584
Xapi_guard.Dorpc.wrap_rpc err (fun () ->
@@ -91,7 +90,7 @@ let serve_forever_lwt_callback rpc_fn path _ req body =
9190
in
9291
let body = response |> Xmlrpc.string_of_response in
9392
Cohttp_lwt_unix.Server.respond_string ~status:`OK ~body ()
94-
| _, _ ->
93+
| _ ->
9594
let body =
9695
"Not allowed"
9796
|> Rpc.rpc_of_string
@@ -142,7 +141,7 @@ let serve_forever_lwt_callback_vtpm ~cache mutex (read, persist) vm_uuid _ req
142141
*)
143142
Lwt_mutex.with_lock mutex @@ fun () ->
144143
(* TODO: some logging *)
145-
match (Cohttp.Request.meth req, Uri.path uri) with
144+
match (Cohttp.Request.meth req, Uri.path_unencoded uri) with
146145
| `GET, path when path <> "/" ->
147146
let key = Tpm.key_of_swtpm path in
148147
let* body = read (vm_uuid, timestamp, key) in

ocaml/xapi-idl/lib/xcp_service.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ let http_handler call_of_string string_of_response process s =
501501
| `Invalid x ->
502502
debug "Failed to read HTTP request. Got: '%s'" x
503503
| `Ok req -> (
504-
match (Cohttp.Request.meth req, Uri.path (Cohttp.Request.uri req)) with
505-
| `POST, _ -> (
504+
match Cohttp.Request.meth req with
505+
| `POST -> (
506506
let headers = Cohttp.Request.headers req in
507507
match Cohttp.Header.get headers "content-length" with
508508
| None ->
@@ -535,7 +535,7 @@ let http_handler call_of_string string_of_response process s =
535535
(fun t -> Response.write_body t response_txt)
536536
response oc
537537
)
538-
| _, _ ->
538+
| _ ->
539539
let content_length = 0 in
540540
let headers =
541541
Cohttp.Header.of_list

ocaml/xapi-storage-script/examples/volume/org.xen.xcp.storage.plainlvm/common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ let vg_of_uri uri =
333333
let uri' = Uri.of_string uri in
334334
match Uri.scheme uri' with
335335
| Some "vg" ->
336-
let vg = Uri.path uri' in
336+
let vg = Uri.path_unencoded uri' in
337337
if vg <> "" && vg.[0] = '/' then
338338
String.sub vg 1 (String.length vg - 1)
339339
else

ocaml/xapi-storage-script/main.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ let bind ~volume_script_dir =
977977
let uri = Uri.of_string datasource in
978978
match Uri.scheme uri with
979979
| Some "xeno+shm" -> (
980-
let uid = Uri.path uri in
980+
let uid = Uri.path_unencoded uri in
981981
let uid =
982982
if String.length uid > 1 then
983983
String.sub uid ~pos:1 ~len:(String.length uid - 1)
@@ -1024,7 +1024,7 @@ let bind ~volume_script_dir =
10241024
let uri = Uri.of_string datasource in
10251025
match Uri.scheme uri with
10261026
| Some "xeno+shm" -> (
1027-
let uid = Uri.path uri in
1027+
let uid = Uri.path_unencoded uri in
10281028
let uid =
10291029
if String.length uid > 1 then
10301030
String.sub uid ~pos:1 ~len:(String.length uid - 1)

0 commit comments

Comments
 (0)