Skip to content

Commit 5c2a041

Browse files
committed
Adds a CrumbExclusion for the GitHub WebHook page
The GitHub webhook endpoint should not be protected by the CSRF protection built into Jenkins. This commit adds a CrumbExclusion filter so that the endpoint created by c.c.j.GitHubWebHook is not protected using the CSRF crumb protection scheme. Bumps Jenkins API version minimum amount required for CrumbExclusion.
1 parent 0604bac commit 5c2a041

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.jenkins-ci.plugins</groupId>
55
<artifactId>plugin</artifactId>
6-
<version>1.445</version>
6+
<version>1.448</version>
77
</parent>
88

99
<groupId>com.coravy.hudson.plugins.github</groupId>

src/main/java/com/cloudbees/jenkins/GitHubWebHook.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
@Extension
3838
public class GitHubWebHook implements UnprotectedRootAction {
3939
private static final Pattern REPOSITORY_NAME_PATTERN = Pattern.compile("https?://([^/]+)/([^/]+)/([^/]+)");
40+
public static final String URLNAME = "github-webhook";
4041

4142
public String getIconFileName() {
4243
return null;
@@ -47,7 +48,7 @@ public String getDisplayName() {
4748
}
4849

4950
public String getUrlName() {
50-
return "github-webhook";
51+
return URLNAME;
5152
}
5253

5354
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.cloudbees.jenkins;
2+
3+
import hudson.Extension;
4+
import hudson.security.csrf.CrumbExclusion;
5+
6+
import javax.servlet.FilterChain;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
import java.io.IOException;
12+
import java.util.logging.Logger;
13+
14+
@Extension
15+
public class GitHubWebHookCrumbExclusion extends CrumbExclusion {
16+
17+
private static final Logger LOGGER = Logger.getLogger("com.cloudbees.jenkins.GitHubWebHookCrumbExclusion");
18+
19+
@Override
20+
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException {
21+
String pathInfo = req.getPathInfo();
22+
if (pathInfo != null && pathInfo.equals(getExclusionPath())) {
23+
chain.doFilter(req, resp);
24+
return true;
25+
}
26+
return false;
27+
}
28+
29+
public String getExclusionPath() {
30+
return "/" + GitHubWebHook.URLNAME + "/";
31+
}
32+
}

0 commit comments

Comments
 (0)