mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-03 15:15:54 +00:00
[FIXED SECURITY-131] Recode restOfPath before constructing URLs from it, so it cannot be used for directory traversal.
This commit is contained in:
1 parent
243a1ba389
commit
71a28615e3
2 files changed
+54
-10
No files matched your search
@@ -30,19 +30,18 @@ import hudson.model.Saveable;
|
||||
import hudson.model.listeners.ItemListener;
|
||||
import hudson.model.listeners.SaveableListener;
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import org.kohsuke.stapler.MetaClass;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Base class of Hudson plugin.
|
||||
@@ -204,12 +203,6 @@ public abstract class Plugin implements Saveable {
|
||||
if(path.length()==0)
|
||||
path = "/";
|
||||
|
||||
if(path.indexOf("..")!=-1 || path.length()<1) {
|
||||
// don't serve anything other than files in the sub directory.
|
||||
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
// Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot"
|
||||
// and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..."
|
||||
// to create unique URLs. Recognize that and set a long expiration header.
|
||||
@@ -219,7 +212,11 @@ public abstract class Plugin implements Saveable {
|
||||
long expires = staticLink ? TimeUnit2.DAYS.toMillis(365) : -1;
|
||||
|
||||
// use serveLocalizedFile to support automatic locale selection
|
||||
rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL,'.'+path),expires);
|
||||
try {
|
||||
rsp.serveLocalizedFile(req, wrapper.baseResourceURL.toURI().resolve(new URI(null, '.' + path, null)).toURL(), expires);
|
||||
} catch (URISyntaxException x) {
|
||||
throw new IOException(x);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user