File tree Expand file tree Collapse file tree 3 files changed +14
-11
lines changed Expand file tree Collapse file tree 3 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -220,9 +220,12 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
220
220
let process_github_notification (ctx : Context.t ) headers body =
221
221
try % lwt
222
222
let secrets = Context. get_secrets_exn ctx in
223
- match Github. parse_exn ~secret: secrets.gh_hook_token headers body with
223
+ match Github. parse_exn headers body with
224
224
| exception exn -> Exn_lwt. fail ~exn " failed to parse payload"
225
225
| payload ->
226
+ match Github. validate_signature ?signing_key:secrets.gh_hook_token ~headers body with
227
+ | Error e -> action_error e
228
+ | Ok () ->
226
229
( match % lwt refresh_repo_config ctx payload with
227
230
| Error e -> action_error e
228
231
| Ok () ->
Original file line number Diff line number Diff line change @@ -64,16 +64,16 @@ let is_valid_signature ~secret headers_sig body =
64
64
let (`Hex request_hash) = Hex. of_string request_hash in
65
65
String. equal headers_sig (sprintf " sha1=%s" request_hash)
66
66
67
+ let validate_signature ?signing_key ~headers body =
68
+ match signing_key with
69
+ | None -> Ok ()
70
+ | Some secret ->
71
+ match List.Assoc. find headers " x-hub-signature" ~equal: String. equal with
72
+ | None -> Error " unable to find header x-hub-signature"
73
+ | Some signature -> if is_valid_signature ~secret signature body then Ok () else Error " signatures don't match"
74
+
67
75
(* Parse a payload. The type of the payload is detected from the headers. *)
68
- let parse_exn ~secret headers body =
69
- begin
70
- match secret with
71
- | None -> ()
72
- | Some secret ->
73
- match List.Assoc. find headers " x-hub-signature" ~equal: String. equal with
74
- | None -> Exn. fail " unable to find header x-hub-signature"
75
- | Some req_sig -> if not @@ is_valid_signature ~secret req_sig body then failwith " request signature invalid"
76
- end ;
76
+ let parse_exn headers body =
77
77
match List.Assoc. find_exn headers " x-github-event" ~equal: String. equal with
78
78
| exception exn -> Exn. fail ~exn " unable to read x-github-event"
79
79
| "push" -> Push (commit_pushed_notification_of_string body)
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ let get_mock_payloads () =
22
22
let process ~(secrets : Config_t.secrets ) ~config (kind , path , state_path ) =
23
23
let headers = [ " x-github-event" , kind ] in
24
24
let make_test_context event =
25
- let repo = Github. repo_of_notification @@ Github. parse_exn ~secret: secrets.gh_token headers event in
25
+ let repo = Github. repo_of_notification @@ Github. parse_exn headers event in
26
26
let ctx = Context. make () in
27
27
ctx.secrets < - Some secrets;
28
28
ignore (State. find_or_add_repo ctx.state repo.url);
You can’t perform that action at this time.
0 commit comments