Skip to content

Commit 0fc4a19

Browse files
committed
[SECURITY-2567]
1 parent bd18a63 commit 0fc4a19

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/java/org/jenkinsci/plugins/badge/StatusImage.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
package org.jenkinsci.plugins.badge;
99

10+
import java.net.MalformedURLException;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
1013
import org.apache.commons.io.IOUtils;
1114
import jenkins.model.Jenkins;
1215
import org.kohsuke.stapler.HttpResponse;
@@ -44,6 +47,7 @@
4447
* can change any time, we use ETag to skip the actual data transfer if possible.
4548
*/
4649
class StatusImage implements HttpResponse {
50+
public static final Logger LOGGER = Logger.getLogger(StatusImage.class.getName());
4751
private final byte[] payload;
4852
private static final String PLGIN_NAME = "embeddable-build-status";
4953

@@ -102,7 +106,7 @@ class StatusImage implements HttpResponse {
102106
if (animatedColorName != null) animatedColorName = StringEscapeUtils.escapeHtml(animatedColorName);
103107
if (colorName != null) colorName = StringEscapeUtils.escapeHtml(colorName);
104108
if (style != null) style = StringEscapeUtils.escapeHtml(style);
105-
if (link != null) link = StringEscapeUtils.escapeHtml(link);
109+
if (link != null) link = StringEscapeUtils.escapeHtml(StringEscapeUtils.escapeHtml(link)); // double-escape because concatenating into an attribute effectively removes one level of quoting
106110

107111
if (baseUrl != null) {
108112
etag = Jenkins.RESOURCE_PATH + '/' + subject + status + colorName + animatedColorName + style;
@@ -167,7 +171,17 @@ class StatusImage implements HttpResponse {
167171
}
168172

169173
if (link != null) {
170-
linkCode = "<svg onclick=\"window.open('" + link + "');\" style=\"cursor: pointer;\" xmlns";
174+
try {
175+
URL url = new URL(link);
176+
final String protocol = url.getProtocol();
177+
if (protocol.equals("http") || protocol.equals("https")) {
178+
linkCode = "<svg onclick=\"window.open(&quot;" + link + "&quot;);\" style=\"cursor: pointer;\" xmlns";
179+
} else {
180+
LOGGER.log(Level.FINE, "Invalid link protocol: " + protocol);
181+
}
182+
} catch (MalformedURLException ex) {
183+
LOGGER.log(Level.FINE, "Invalid link URL: " + link, ex);
184+
}
171185
}
172186

173187
try {

0 commit comments

Comments
 (0)