Skip to content

Commit 419e6e1

Browse files
committed
add option to restrict handling of GH payloads to certain repo urls
1 parent cc32884 commit 419e6e1

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
@@ -210,6 +210,11 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
210210
let signing_key = Context.gh_hook_token_of_secrets secrets repo.url in
211211
Github.validate_signature ?signing_key ~headers body
212212
in
213+
let repo_is_allowed secrets payload =
214+
let repo = Github.repo_of_notification payload in
215+
let allowed_repos = secrets.allowed_repos in
216+
List.is_empty allowed_repos || List.exists allowed_repos ~f:(String.equal repo.url)
217+
in
213218
try%lwt
214219
let secrets = Context.get_secrets_exn ctx in
215220
match Github.parse_exn headers body with
@@ -218,6 +223,9 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
218223
match validate_signature secrets payload with
219224
| Error e -> action_error e
220225
| Ok () ->
226+
match repo_is_allowed secrets payload with
227+
| false -> action_error "unsupported repository"
228+
| true ->
221229
( match%lwt refresh_repo_config ctx payload with
222230
| Error e -> action_error e
223231
| Ok () ->

lib/config.atd

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

0 commit comments

Comments
 (0)