Skip to content

Commit 19a1a09

Browse files
committed
cfg: add option to restrict handling of GH payloads to certain repo urls
1 parent 4ad34de commit 19a1a09

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
@@ -237,6 +237,11 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
237237
let signing_key = Context.gh_hook_token_of_secrets secrets repo.url in
238238
Github.validate_signature ?signing_key ~headers body
239239
in
240+
let repo_is_allowed secrets payload =
241+
let repo = Github.repo_of_notification payload in
242+
let allowed_repos = secrets.allowed_repos in
243+
List.is_empty allowed_repos || List.exists allowed_repos ~f:(String.equal repo.url)
244+
in
240245
try%lwt
241246
let secrets = Context.get_secrets_exn ctx in
242247
match Github.parse_exn headers body with
@@ -245,6 +250,9 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
245250
match validate_signature secrets payload with
246251
| Error e -> action_error e
247252
| Ok () ->
253+
match repo_is_allowed secrets payload with
254+
| false -> action_error "unsupported repository"
255+
| true ->
248256
( match%lwt refresh_repo_config ctx payload with
249257
| Error e -> action_error e
250258
| Ok () ->

lib/config.atd

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

0 commit comments

Comments
 (0)