Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HMAC verification #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"depends": [
"Bailador",
"Config",
"Digest::HMAC",
"Digest::SHA",
"IRC::Client"
],
"provides": {
Expand Down
11 changes: 11 additions & 0 deletions lib/IRC/Client/Plugin/Github.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use v6.c;

use Bailador;
use Config;
use Digest::HMAC;
use Digest::SHA;
use IRC::Client;
use IRC::Client::Plugin::Github::WebhookEvents::IssueComment;
use IRC::Client::Plugin::Github::WebhookEvents::Issues;
Expand Down Expand Up @@ -33,6 +35,15 @@ class IRC::Client::Plugin::Github does IRC::Client::Plugin

my %json = from-json(request.body);

# Check signature
if ($!config.has("github.webhook.secret") && request.headers<X_HUB_SIGNATURE>:exists) {
my Str $hmac = "sha1=" ~ hmac-hex($!config.get("github.webhook.secret"), request.body, &sha1);

if ($hmac ne request.headers<X_HUB_SIGNATURE>) {
return "";
}
}

# Make sure there are channels configured to notify
my Str $repo-config-key = "github.webhook.repos.{%json<repository><full_name>.subst("/", "-")}.channels";
my Str @channels = $!config.get($repo-config-key) || $!config.get("github.webhook.channels", []).unique;
Expand Down
5 changes: 5 additions & 0 deletions readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ message-style = "privmsg"
# repository's configuration key, this array will be used instead.
channels = ["#scriptkitties"]

# A secret shared between the bot and the Github webhook. If set, HMAC
# verification will be employed. Messages failing this verification will be
# dropped.
secret = ""

# If set to true, it will notify for every repository that POSTs a payload to
# the Bailador instance. Note this could be abused to spam through the bot.
# When false, every repository should be properly defined if you want to see
Expand Down