Skip to content

Commit 87a03f3

Browse files
committed
[SECURITY-810] require POST for repo browser check
See https://jenkins.io/doc/developer/security/form-validation/ for stapler security guidelines. I assume the repo URL check is "state changing" because it opens an external URL. Therefore, the request requires POST instead of GET.
1 parent 228b4ba commit 87a03f3

File tree

12 files changed

+18
-6
lines changed

12 files changed

+18
-6
lines changed

src/main/java/hudson/plugins/git/browser/AssemblaWeb.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import jenkins.model.Jenkins;
1313
import net.sf.json.JSONObject;
1414
import org.kohsuke.stapler.DataBoundConstructor;
15+
import org.kohsuke.stapler.interceptor.RequirePOST;
1516
import org.kohsuke.stapler.QueryParameter;
1617
import org.kohsuke.stapler.StaplerRequest;
1718

@@ -96,6 +97,7 @@ public AssemblaWeb newInstance(StaplerRequest req, @Nonnull JSONObject jsonObjec
9697
return req.bindJSON(AssemblaWeb.class, jsonObject);
9798
}
9899

100+
@RequirePOST
99101
public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String url)
100102
throws IOException, ServletException {
101103
if (url == null) // nothing entered yet

src/main/java/hudson/plugins/git/browser/FisheyeGitRepositoryBrowser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import hudson.util.FormValidation.URLCheck;
1313
import net.sf.json.JSONObject;
1414
import org.kohsuke.stapler.DataBoundConstructor;
15+
import org.kohsuke.stapler.interceptor.RequirePOST;
1516
import org.kohsuke.stapler.QueryParameter;
1617
import org.kohsuke.stapler.StaplerRequest;
1718

@@ -87,6 +88,7 @@ public FisheyeGitRepositoryBrowser newInstance(StaplerRequest req, @Nonnull JSON
8788
* @throws IOException on input or output error
8889
* @throws ServletException on servlet error
8990
*/
91+
@RequirePOST
9092
@SuppressFBWarnings(value="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification="Jenkins.getInstance() is not null")
9193
public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String value) throws IOException,
9294
ServletException {

src/main/java/hudson/plugins/git/browser/GitBlitRepositoryBrowser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import jenkins.model.Jenkins;
1212
import net.sf.json.JSONObject;
1313
import org.kohsuke.stapler.DataBoundConstructor;
14+
import org.kohsuke.stapler.interceptor.RequirePOST;
1415
import org.kohsuke.stapler.QueryParameter;
1516
import org.kohsuke.stapler.StaplerRequest;
1617

@@ -79,6 +80,7 @@ public GitBlitRepositoryBrowser newInstance(StaplerRequest req, @Nonnull JSONObj
7980
return req.bindJSON(GitBlitRepositoryBrowser.class, jsonObject);
8081
}
8182

83+
@RequirePOST
8284
public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String url)
8385
throws IOException, ServletException {
8486
if (url == null) // nothing entered yet

src/main/java/hudson/plugins/git/browser/Gitiles.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.sf.json.JSONObject;
2020

2121
import org.kohsuke.stapler.DataBoundConstructor;
22+
import org.kohsuke.stapler.interceptor.RequirePOST;
2223
import org.kohsuke.stapler.QueryParameter;
2324
import org.kohsuke.stapler.StaplerRequest;
2425

@@ -68,6 +69,7 @@ public Gitiles newInstance(StaplerRequest req, @Nonnull JSONObject jsonObject) t
6869
return req.bindJSON(Gitiles.class, jsonObject);
6970
}
7071

72+
@RequirePOST
7173
public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String url) throws IOException, ServletException {
7274
if (url == null) // nothing entered yet
7375
return FormValidation.ok();

src/main/java/hudson/plugins/git/browser/TFS2013GitRepositoryBrowser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.jgit.transport.RemoteConfig;
1515
import org.kohsuke.stapler.AncestorInPath;
1616
import org.kohsuke.stapler.DataBoundConstructor;
17+
import org.kohsuke.stapler.interceptor.RequirePOST;
1718
import org.kohsuke.stapler.QueryParameter;
1819
import org.kohsuke.stapler.StaplerRequest;
1920

@@ -108,6 +109,7 @@ public TFS2013GitRepositoryBrowser newInstance(StaplerRequest req, @Nonnull JSON
108109
* @throws IOException on input or output error
109110
* @throws ServletException on servlet error
110111
*/
112+
@RequirePOST
111113
public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String value, @AncestorInPath AbstractProject project) throws IOException,
112114
ServletException {
113115

src/main/java/hudson/plugins/git/browser/ViewGitWeb.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import jenkins.model.Jenkins;
1313
import net.sf.json.JSONObject;
1414
import org.kohsuke.stapler.DataBoundConstructor;
15+
import org.kohsuke.stapler.interceptor.RequirePOST;
1516
import org.kohsuke.stapler.QueryParameter;
1617
import org.kohsuke.stapler.StaplerRequest;
1718

@@ -87,6 +88,7 @@ public ViewGitWeb newInstance(StaplerRequest req, @Nonnull JSONObject jsonObject
8788
return req.bindJSON(ViewGitWeb.class, jsonObject);
8889
}
8990

91+
@RequirePOST
9092
public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String url) throws IOException, ServletException {
9193
if (url == null) // nothing entered yet
9294
return FormValidation.ok();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33
<f:entry field="repoUrl" title="${%Assembla Git URL}">
4-
<f:textbox/>
4+
<f:textbox checkMethod="post" />
55
</f:entry>
66
</j:jelly>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33
<f:entry field="repoUrl" title="${%URL}">
4-
<f:textbox/>
4+
<f:textbox checkMethod="post" />
55
</f:entry>
66
</j:jelly>

src/main/resources/hudson/plugins/git/browser/GitBlitRepositoryBrowser/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33
<f:entry field="repoUrl" title="${%GitBlit root url}">
4-
<f:textbox/>
4+
<f:textbox checkMethod="post" />
55
</f:entry>
66
<f:entry field="projectName" title="${%Project name in GitBlit}">
77
<f:textbox/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33
<f:entry field="repoUrl" title="${%URL}">
4-
<f:textbox/>
4+
<f:textbox checkMethod="post" />
55
</f:entry>
66
</j:jelly>

0 commit comments

Comments
 (0)