Skip to content

Commit

Permalink
Merge pull request #5214 from snwoods/private/stevenwo/CA-383987
Browse files Browse the repository at this point in the history
CA-383987: Only include valid Hosts and Ports in tracing Host header
  • Loading branch information
snwoods authored Oct 30, 2023
2 parents 50e4bc3 + 4006aed commit 67cb444
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ocaml/libs/tracing/tracing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 67cb444

Please sign in to comment.