From 7149adb8be3ed1c8774bf9100848fc8589e3fd18 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sun, 28 Jan 2018 11:26:25 +0300 Subject: Add crumb exclusion for /bbprb-hook/ --- .../plugins/bbprb/BitbucketHookReceiver.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketHookReceiver.java b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketHookReceiver.java index 18b2688..3562a7e 100644 --- a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketHookReceiver.java +++ b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketHookReceiver.java @@ -3,6 +3,7 @@ package org.jenkinsci.plugins.bbprb; import hudson.Extension; import hudson.model.UnprotectedRootAction; import hudson.security.ACL; +import hudson.security.csrf.CrumbExclusion; import hudson.triggers.Trigger; import hudson.triggers.TriggerDescriptor; import java.io.IOException; @@ -12,6 +13,10 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import jenkins.model.Jenkins; import jenkins.model.ParameterizedJobMixIn.ParameterizedJob; import net.sf.json.JSONException; @@ -23,11 +28,24 @@ import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @Extension -public class BitbucketHookReceiver implements UnprotectedRootAction { +public class BitbucketHookReceiver + extends CrumbExclusion implements UnprotectedRootAction { private static final String BITBUCKET_HOOK_URL = "bbprb-hook"; private static final String BITBUCKET_UA = "Bitbucket-Webhooks/2.0"; + @Override + public boolean process(HttpServletRequest req, HttpServletResponse resp, + FilterChain chain) + throws IOException, ServletException { + String pathInfo = req.getPathInfo(); + if (pathInfo != null && pathInfo.startsWith("/" + BITBUCKET_HOOK_URL)) { + chain.doFilter(req, resp); + return true; + } + return false; + } + public void doIndex(StaplerRequest req, StaplerResponse resp) throws IOException { -- cgit v1.2.3