forked from magnayn/Hudson-GIT-plugin
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-34350] Fix POST to /git/notifyCommit with CSRF protection on
Inspired by jenkinsci/github-plugin@5c2a041
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,32 @@ | ||
package hudson.plugins.git; | ||
|
||
import hudson.Extension; | ||
import hudson.security.csrf.CrumbExclusion; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Make POST to /git/notifyCommit work with CSRF protection on. | ||
*/ | ||
@Extension | ||
public class GitStatusCrumbExclusion extends CrumbExclusion { | ||
|
||
@Override | ||
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) | ||
throws IOException, ServletException { | ||
String pathInfo = req.getPathInfo(); | ||
if (pathInfo != null && pathInfo.equals(getExclusionPath())) { | ||
chain.doFilter(req, resp); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public String getExclusionPath() { | ||
return "/git/notifyCommit"; | ||
} | ||
} |