Skip to content

Commit 680766e

Browse files
committed
cfg: add option to restrict handling of GH payloads to certain repo urls
1 parent b2fa5c0 commit 680766e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/action.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
216216
let signing_key = Context.gh_hook_token_of_secrets secrets repo.url in
217217
Github.validate_signature ?signing_key ~headers body
218218
in
219+
let repo_is_allowed secrets payload =
220+
let repo = Github.repo_of_notification payload in
221+
let allowed_repos = secrets.allowed_repos in
222+
List.is_empty allowed_repos || List.exists allowed_repos ~f:(String.equal repo.url)
223+
in
219224
try%lwt
220225
let secrets = Context.get_secrets_exn ctx in
221226
match Github.parse_exn headers body with
@@ -224,6 +229,9 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
224229
match validate_signature secrets payload with
225230
| Error e -> action_error e
226231
| Ok () ->
232+
match repo_is_allowed secrets payload with
233+
| false -> action_error "unsupported repository"
234+
| true ->
227235
( match%lwt refresh_repo_config ctx payload with
228236
| Error e -> action_error e
229237
| Ok () ->

lib/config.atd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type gh_repo_secrets = {
5050
type secrets = {
5151
(* repo-specific secrets; overrides global values if defined for a given repo *)
5252
~repo_secrets <ocaml default="Common.StringMap.empty"> : gh_repo_secrets map_as_object;
53+
(* whitelist of repository URLs to handle notifications for *)
54+
~allowed_repos <ocaml default="[]"> : string list;
5355
(* GitHub personal access token, if repo access requires it *)
5456
?gh_token : string nullable;
5557
(* GitHub webhook token to secure the webhook *)

0 commit comments

Comments
 (0)