Skip to content

Commit a1e0cc7

Browse files
authored
Don't leak the token in the error message (#317)
Should fix the issue at rocq-prover/rocq#19680 (comment)
2 parents 7e8b31f + 52cd5dc commit a1e0cc7

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/git_utils.ml

+13-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ let gitlab_repo ~bot_info ~gitlab_domain ~gitlab_full_name =
1111
|> Result.map ~f:(fun token ->
1212
f "https://oauth2:%s@%s/%s.git" token gitlab_domain gitlab_full_name )
1313

14-
let report_status command report code =
15-
Error (f {|Command "%s" %s %d\n|} command report code)
14+
let report_status ?(mask = []) command report code =
15+
Error
16+
(List.fold_left
17+
~init:(f {|Command "%s" %s %d%s|} command report code "\n")
18+
~f:(fun acc m -> Str.global_replace (Str.regexp_string m) "XXXXX" acc)
19+
mask)
1620

1721
let gitlab_ref ~bot_info ~(issue : issue) ~github_mapping ~gitlab_mapping =
1822
let default_gitlab_domain = "gitlab.com" in
@@ -82,19 +86,19 @@ let gitlab_ref ~bot_info ~(issue : issue) ~github_mapping ~gitlab_mapping =
8286

8387
let ( |&& ) command1 command2 = command1 ^ " && " ^ command2
8488

85-
let execute_cmd command =
89+
let execute_cmd ?(mask = []) command =
8690
Lwt_io.printf "Executing command: %s\n" command
8791
>>= fun () ->
8892
Lwt_unix.system command
8993
>|= fun status ->
9094
match status with
9195
| Unix.WEXITED code ->
9296
if Int.equal code 0 then Ok ()
93-
else report_status command "exited with status" code
97+
else report_status ~mask command "exited with status" code
9498
| Unix.WSIGNALED signal ->
95-
report_status command "was killed by signal number" signal
99+
report_status ~mask command "was killed by signal number" signal
96100
| Unix.WSTOPPED signal ->
97-
report_status command "was stopped by signal number" signal
101+
report_status ~mask command "was stopped by signal number" signal
98102

99103
let git_fetch ?(force = true) remote_ref local_branch_name =
100104
f "git fetch --quiet -fu %s %s%s:%s" remote_ref.repo_url
@@ -166,7 +170,7 @@ let git_coq_bug_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
166170
; coq_version
167171
; ocaml_version
168172
; minimizer_extra_arguments |> String.concat ~sep:" " ]
169-
|> execute_cmd
173+
|> execute_cmd ~mask:[bot_info.github_pat]
170174

171175
let git_run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
172176
~docker_image ~target ~opam_switch ~failing_urls ~passing_urls ~base ~head
@@ -192,14 +196,14 @@ let git_run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
192196
@
193197
match bug_file_name with Some bug_file_name -> [bug_file_name] | None -> [] )
194198
|> Stdlib.Filename.quote_command "./run_ci_minimization.sh"
195-
|> execute_cmd
199+
|> execute_cmd ~mask:[bot_info.github_pat]
196200

197201
let init_git_bare_repository ~bot_info =
198202
let* () = Lwt_io.printl "Initializing repository..." in
199203
"git init --bare"
200204
|&& f {|git config user.email "%s"|} bot_info.email
201205
|&& f {|git config user.name "%s"|} bot_info.github_name
202-
|> execute_cmd
206+
|> execute_cmd ~mask:[bot_info.github_pat]
203207
>>= function
204208
| Ok _ ->
205209
Lwt_io.printl "Bare repository initialized."

src/git_utils.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ val gitlab_ref :
1313

1414
val ( |&& ) : string -> string -> string
1515

16-
val execute_cmd : string -> (unit, string) result Lwt.t
16+
val execute_cmd : ?mask:string list -> string -> (unit, string) result Lwt.t
1717

1818
val git_fetch :
1919
?force:bool -> Bot_components.GitHub_types.remote_ref_info -> string -> string

0 commit comments

Comments
 (0)