Skip to content

Commit 228b4ba

Browse files
committed
[SECURITY-810] require ADMINISTER for repo browser check
I've confirmed with a test script in my jenkins-bugs-private directory that prior to this change, these 5 classes opened the external URL that was passed as an argument in a GET request and returned a message even if the user was not authenticated. I've confirmed with this change that they now behave the same as the FisheyeGitRepositoryBrowser referenced in SECURITY-810. If they receive a GET request from a user without ADMINISTER permission, they return "<div/>" and do not open the external URL.
1 parent 3591ae6 commit 228b4ba

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import hudson.util.FormValidation;
1010
import hudson.util.FormValidation.URLCheck;
1111
import hudson.scm.browsers.QueryBuilder;
12+
import jenkins.model.Jenkins;
1213
import net.sf.json.JSONObject;
1314
import org.kohsuke.stapler.DataBoundConstructor;
1415
import org.kohsuke.stapler.QueryParameter;
@@ -101,6 +102,10 @@ public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String u
101102
{
102103
return FormValidation.ok();
103104
}
105+
// Connect to URL and check content only if we have admin permission
106+
Jenkins jenkins = Jenkins.getInstance();
107+
if (jenkins == null || !jenkins.hasPermission(Jenkins.ADMINISTER))
108+
return FormValidation.ok();
104109
return new URLCheck() {
105110
protected FormValidation check() throws IOException, ServletException {
106111
String v = url;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import hudson.scm.RepositoryBrowser;
99
import hudson.util.FormValidation;
1010
import hudson.util.FormValidation.URLCheck;
11+
import jenkins.model.Jenkins;
1112
import net.sf.json.JSONObject;
1213
import org.kohsuke.stapler.DataBoundConstructor;
1314
import org.kohsuke.stapler.QueryParameter;
@@ -84,6 +85,10 @@ public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String u
8485
{
8586
return FormValidation.ok();
8687
}
88+
// Connect to URL and check content only if we have admin permission
89+
Jenkins jenkins = Jenkins.getInstance();
90+
if (jenkins == null || !jenkins.hasPermission(Jenkins.ADMINISTER))
91+
return FormValidation.ok();
8792
return new URLCheck() {
8893
protected FormValidation check() throws IOException, ServletException {
8994
String v = url;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import hudson.util.FormValidation;
99
import hudson.util.FormValidation.URLCheck;
1010

11+
import jenkins.model.Jenkins;
12+
1113
import java.io.IOException;
1214
import java.net.URL;
1315

@@ -69,6 +71,10 @@ public Gitiles newInstance(StaplerRequest req, @Nonnull JSONObject jsonObject) t
6971
public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String url) throws IOException, ServletException {
7072
if (url == null) // nothing entered yet
7173
return FormValidation.ok();
74+
// Connect to URL and check content only if we have admin permission
75+
Jenkins jenkins = Jenkins.getInstance();
76+
if (jenkins == null || !jenkins.hasPermission(Jenkins.ADMINISTER))
77+
return FormValidation.ok();
7278
return new URLCheck() {
7379
protected FormValidation check() throws IOException, ServletException {
7480
String v = url;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,16 @@ public TFS2013GitRepositoryBrowser newInstance(StaplerRequest req, @Nonnull JSON
110110
*/
111111
public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String value, @AncestorInPath AbstractProject project) throws IOException,
112112
ServletException {
113-
113+
114+
// Connect to URL and check content only if we have admin permission
115+
Jenkins jenkins = Jenkins.getInstance();
116+
if (jenkins == null || !jenkins.hasPermission(Hudson.ADMINISTER))
117+
return FormValidation.ok();
118+
114119
if (value == null) // nothing entered yet
115120
value = "origin";
116121

117-
if (!value.contains("/")) {
122+
if (!value.contains("/") && project != null) {
118123
GitSCM scm = (GitSCM) project.getScm();
119124
RemoteConfig remote = scm.getRepositoryByName(value);
120125
if (remote == null)
@@ -128,11 +133,6 @@ public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String val
128133
if (!URL_PATTERN.matcher(value).matches())
129134
return FormValidation.errorWithMarkup("The URL should end like <tt>.../_git/foobar/</tt>");
130135

131-
// Connect to URL and check content only if we have admin permission
132-
Jenkins jenkins = Jenkins.getInstance();
133-
if (jenkins != null && jenkins.hasPermission(Hudson.ADMINISTER))
134-
return FormValidation.ok();
135-
136136
final String finalValue = value;
137137
return new FormValidation.URLCheck() {
138138
@Override

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import hudson.scm.browsers.QueryBuilder;
1010
import hudson.util.FormValidation;
1111
import hudson.util.FormValidation.URLCheck;
12+
import jenkins.model.Jenkins;
1213
import net.sf.json.JSONObject;
1314
import org.kohsuke.stapler.DataBoundConstructor;
1415
import org.kohsuke.stapler.QueryParameter;
@@ -89,6 +90,10 @@ public ViewGitWeb newInstance(StaplerRequest req, @Nonnull JSONObject jsonObject
8990
public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) final String url) throws IOException, ServletException {
9091
if (url == null) // nothing entered yet
9192
return FormValidation.ok();
93+
// Connect to URL and check content only if we have admin permission
94+
Jenkins jenkins = Jenkins.getInstance();
95+
if (jenkins == null || !jenkins.hasPermission(Jenkins.ADMINISTER))
96+
return FormValidation.ok();
9297
return new URLCheck() {
9398
protected FormValidation check() throws IOException, ServletException {
9499
String v = url;

0 commit comments

Comments
 (0)