From 4006aed17e4ea05c03ee47cd799da8aa27b81e5d Mon Sep 17 00:00:00 2001 From: Steven Woods Date: Wed, 25 Oct 2023 14:38:50 +0100 Subject: [PATCH] CA-383987: Only include valid Hosts and Ports in tracing Host header Signed-off-by: Steven Woods --- ocaml/libs/tracing/tracing.ml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ocaml/libs/tracing/tracing.ml b/ocaml/libs/tracing/tracing.ml index ef976e95244..a897ab4a0c0 100644 --- a/ocaml/libs/tracing/tracing.ml +++ b/ocaml/libs/tracing/tracing.ml @@ -688,16 +688,26 @@ module Export = struct let export ~url json = try let body = json in - (*If host or port is None it will throw a more meaningful error later, so ignore here*) - let hostname = match Uri.host url with Some h -> h | None -> "" in - let port = match Uri.port url with Some p -> p | None -> 80 in let headers = Cohttp.Header.of_list - [ - ("Content-Type", "application/json") - ; ("Content-Length", string_of_int (String.length body)) - ; ("Host", hostname ^ ":" ^ string_of_int port) - ] + ([ + ("Content-Type", "application/json") + ; ("Content-Length", string_of_int (String.length body)) + ] + @ + match Uri.host url with + | None -> + [] + | Some h -> + let port = + match Uri.port url with + | Some p -> + ":" ^ string_of_int p + | None -> + "" + in + [("Host", h ^ port)] + ) in Open_uri.with_open_uri url (fun fd -> let request =