Skip to content

Commit

Permalink
[SECURITY-2567]
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Jun 21, 2022
1 parent bd18a63 commit 0fc4a19
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/org/jenkinsci/plugins/badge/StatusImage.java
Expand Up @@ -7,6 +7,9 @@

package org.jenkinsci.plugins.badge;

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

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

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

if (link != null) {
linkCode = "<svg onclick=\"window.open('" + link + "');\" style=\"cursor: pointer;\" xmlns";
try {
URL url = new URL(link);
final String protocol = url.getProtocol();
if (protocol.equals("http") || protocol.equals("https")) {
linkCode = "<svg onclick=\"window.open(&quot;" + link + "&quot;);\" style=\"cursor: pointer;\" xmlns";
} else {
LOGGER.log(Level.FINE, "Invalid link protocol: " + protocol);
}
} catch (MalformedURLException ex) {
LOGGER.log(Level.FINE, "Invalid link URL: " + link, ex);
}
}

try {
Expand Down

0 comments on commit 0fc4a19

Please sign in to comment.