|
7 | 7 |
|
8 | 8 | package org.jenkinsci.plugins.badge;
|
9 | 9 |
|
| 10 | +import java.net.MalformedURLException; |
| 11 | +import java.util.logging.Level; |
| 12 | +import java.util.logging.Logger; |
10 | 13 | import org.apache.commons.io.IOUtils;
|
11 | 14 | import jenkins.model.Jenkins;
|
12 | 15 | import org.kohsuke.stapler.HttpResponse;
|
|
44 | 47 | * can change any time, we use ETag to skip the actual data transfer if possible.
|
45 | 48 | */
|
46 | 49 | class StatusImage implements HttpResponse {
|
| 50 | + public static final Logger LOGGER = Logger.getLogger(StatusImage.class.getName()); |
47 | 51 | private final byte[] payload;
|
48 | 52 | private static final String PLGIN_NAME = "embeddable-build-status";
|
49 | 53 |
|
@@ -102,7 +106,7 @@ class StatusImage implements HttpResponse {
|
102 | 106 | if (animatedColorName != null) animatedColorName = StringEscapeUtils.escapeHtml(animatedColorName);
|
103 | 107 | if (colorName != null) colorName = StringEscapeUtils.escapeHtml(colorName);
|
104 | 108 | 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 |
106 | 110 |
|
107 | 111 | if (baseUrl != null) {
|
108 | 112 | etag = Jenkins.RESOURCE_PATH + '/' + subject + status + colorName + animatedColorName + style;
|
@@ -167,7 +171,17 @@ class StatusImage implements HttpResponse {
|
167 | 171 | }
|
168 | 172 |
|
169 | 173 | 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("" + link + "");\" 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 | + } |
171 | 185 | }
|
172 | 186 |
|
173 | 187 | try {
|
|
0 commit comments