Skip to content

Commit f581998

Browse files
[SECURITY-1723]
Co-authored-by: Daniel Beck <[email protected]>
1 parent 996a830 commit f581998

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hudson.plugins.git.browser;
22

33
import hudson.Extension;
4+
import hudson.Util;
45
import hudson.model.AbstractProject;
56
import hudson.model.Descriptor;
67
import hudson.plugins.git.GitChangeSet;
@@ -123,7 +124,7 @@ public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String val
123124
GitSCM scm = (GitSCM) project.getScm();
124125
RemoteConfig remote = scm.getRepositoryByName(value);
125126
if (remote == null)
126-
return FormValidation.errorWithMarkup("There is no remote with the name <code>" + value + "</code>");
127+
return FormValidation.errorWithMarkup("There is no remote with the name <code>" + Util.escape(value) + "</code>");
127128

128129
value = remote.getURIs().get(0).toString();
129130
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package hudson.plugins.git.browser;
2+
3+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
4+
import hudson.model.FreeStyleProject;
5+
import hudson.plugins.git.GitSCM;
6+
import hudson.plugins.git.SubmoduleConfig;
7+
import hudson.plugins.git.UserRemoteConfig;
8+
import hudson.plugins.git.extensions.GitSCMExtension;
9+
import org.jenkinsci.plugins.gitclient.JGitTool;
10+
import org.junit.Assert;
11+
import org.junit.Rule;
12+
import org.junit.Test;
13+
import org.jvnet.hudson.test.Issue;
14+
import org.jvnet.hudson.test.JenkinsRule;
15+
16+
import java.util.ArrayList;
17+
import java.util.Collections;
18+
import java.util.concurrent.atomic.AtomicBoolean;
19+
20+
public class TFS2013GitRepositoryBrowserXSSTest {
21+
22+
@Rule
23+
public final JenkinsRule rule = new JenkinsRule();
24+
25+
@Test
26+
@Issue("SECURITY-1723")
27+
public void testXSS() throws Exception {
28+
// setup scm
29+
GitSCM scm = new GitSCM(
30+
Collections.singletonList(new UserRemoteConfig("http://tfs/tfs/project/_git/repo", null, null, null)),
31+
new ArrayList<>(),
32+
false, Collections.<SubmoduleConfig>emptyList(),
33+
null, JGitTool.MAGIC_EXENAME,
34+
Collections.<GitSCMExtension>emptyList());
35+
scm.setBrowser(new TFS2013GitRepositoryBrowser("<img src=x onerror=alert(232)>"));
36+
37+
FreeStyleProject p = rule.createFreeStyleProject();
38+
p.setScm(scm);
39+
40+
AtomicBoolean xss = new AtomicBoolean(false);
41+
JenkinsRule.WebClient wc = rule.createWebClient();
42+
wc.setAlertHandler((page, s) -> {
43+
xss.set(true);
44+
});
45+
HtmlPage page = wc.getPage(p, "configure");
46+
Assert.assertFalse(xss.get());
47+
}
48+
}

0 commit comments

Comments
 (0)