from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse, HttpResponseNotFound


def handle_ping(request, repo):
    return HttpResponse()


def handle_issues(request, repo):
    return HttpResponse()


def handle_issue_comment(request, repo):
    return HttpResponse()


def dispatch(request, repo, hook):
    github_event = request.META.get('HTTP_X_GITHUB_EVENT')
    if not github_event:
        return HttpResponseNotFound('No X-GitHub-Event!')
    if github_event == 'ping':
        return handle_ping(request, repo)
    elif github_event == 'issue_comment':
        return handle_issue_comment(request, repo)
    elif github_event == 'issues':
        return handle_issues(request, repo)
    else:
        return HttpResponseNotFound('Unknown event!')


@csrf_exempt
def all_issues(request, full_repo_name):
    return dispatch(request, repo=full_repo_name, hook='all_issues')

@@ -1,20 +1,47 @@
+import hashlib%0Aimport hmac%0A
 from django.views.de
@@ -132,16 +132,39 @@
 otFound%0A
+from web import jucybot
 %0A%0Adef ha
@@ -344,24 +344,355 @@
 esponse()%0A%0A%0A
+def verify_signature(request, repo):%0A    signature = request.META.get('HTTP_X_HUB_SIGNATURE')%0A    if not signature:%0A        return False%0A    repo_secret = jucybot.getSecretForRepo(repo)%0A    h = hmac.new(repo_secret, request.body, digestmod=hashlib.sha1)%0A    reference = 'sha1=%25s' %25 h.hexdigest()%0A    return reference == signature%0A%0A
 def dispatch
@@ -856,16 +856,130 @@
 vent!')%0A
+    if not verify_signature(request, repo):%0A        return HttpResponseNotFound('X-Hub-Signature did not verify')%0A
     if g

Check HMAC digests in webhook notifications before handling them.