Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit b8b6ab3

Browse files
author
clouless
committed
v.1.2.0 make it work with enabled CSRF Protection
1 parent 1a1ebb5 commit b8b6ab3

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Diff for: pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212
<groupId>io.codeclou.jenkins.github.webhook.notifier.plugin</groupId>
1313
<artifactId>github-webhook-notifier-plugin</artifactId>
14-
<version>1.1.2</version>
14+
<version>1.2.0</version>
1515
<packaging>hpi</packaging>
1616

1717
<name>github-webhook-notifier-plugin</name>

Diff for: src/main/java/io/codeclou/jenkins/githubwebhookbuildtriggerplugin/GithubWebhookBuildTriggerAction.java

+24-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import org.kohsuke.stapler.HttpResponse;
1818
import org.kohsuke.stapler.StaplerRequest;
1919
import org.kohsuke.stapler.interceptor.RequirePOST;
20-
20+
import hudson.security.csrf.CrumbExclusion;
21+
import javax.servlet.FilterChain;
2122
import javax.servlet.ServletException;
2223
import javax.servlet.http.HttpServletRequest;
24+
import javax.servlet.http.HttpServletResponse;
2325
import java.io.IOException;
2426
import java.io.StringWriter;
2527
import java.util.ArrayList;
@@ -28,9 +30,11 @@
2830
@Extension
2931
public class GithubWebhookBuildTriggerAction implements UnprotectedRootAction {
3032

33+
private static final String URL_NAME = "github-webhook-build-trigger";
34+
3135
@Override
3236
public String getUrlName() {
33-
return "github-webhook-build-trigger";
37+
return URL_NAME;
3438
}
3539

3640
@Override
@@ -40,7 +44,7 @@ public String getIconFileName() {
4044

4145
@Override
4246
public String getDisplayName() {
43-
return "github-webhook-build-trigger";
47+
return URL_NAME;
4448
}
4549

4650
/*
@@ -166,4 +170,21 @@ private String getTextEnvelopedInBanner(String text) {
166170
return banner.toString();
167171
}
168172

173+
@Extension
174+
public static class TriggerActionCrumbExclusion extends CrumbExclusion {
175+
176+
@Override
177+
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException {
178+
String pathInfo = req.getPathInfo();
179+
if (pathInfo != null && pathInfo.contains(getExclusionPath())) {
180+
chain.doFilter(req, resp);
181+
return true;
182+
}
183+
return false;
184+
}
185+
186+
public String getExclusionPath() {
187+
return "/" + URL_NAME + "/";
188+
}
189+
}
169190
}

0 commit comments

Comments
 (0)