Merge remote-tracking branch 'origin/jetty-8'
Conflicts: jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java tests/test-webapps/test-jetty-webapp/src/main/config/webapps.demo/test.xml
This commit is contained in:
commit
d2ff475834
|
@ -43,6 +43,11 @@ public class DumpServlet extends HttpServlet
|
|||
response.getWriter().println("servletPath=" + request.getServletPath());
|
||||
response.getWriter().println("pathInfo=" + request.getPathInfo());
|
||||
response.getWriter().println("session=" + request.getSession(true).getId());
|
||||
|
||||
String r=request.getParameter("resource");
|
||||
if (r!=null)
|
||||
response.getWriter().println("resource("+r+")=" + getServletContext().getResource(r));
|
||||
|
||||
response.getWriter().println("</pre>");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1590,23 +1590,46 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
path = URIUtil.canonicalPath(path);
|
||||
Resource resource = _baseResource.addPath(path);
|
||||
|
||||
System.err.println();
|
||||
System.err.println("resource="+resource);
|
||||
try
|
||||
{
|
||||
System.err.println("path="+path);
|
||||
System.err.println("resource="+resource);
|
||||
System.err.println("resource.getURI()="+resource.getURI());
|
||||
System.err.println("resource.getURL()="+resource.getURL());
|
||||
System.err.println("resource.getAlias()="+resource.getAlias());
|
||||
System.err.println("resource.getFile() ="+resource.getFile());
|
||||
System.err.println("resource.getFile().getCanonicalPath()="+resource.getFile().getCanonicalPath());
|
||||
System.err.println("resource.getFile().getAbsolutePath() ="+resource.getFile().getAbsolutePath());
|
||||
System.err.println("resource.exists() ="+resource.exists());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Is the resource aliased?
|
||||
if (resource.getAlias() != null)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Aliased resource: " + resource + "~=" + resource.getAlias());
|
||||
|
||||
System.err.println("ALIAS="+resource.getAlias());
|
||||
// alias checks
|
||||
for (Iterator<AliasCheck> i=_aliasChecks.iterator();i.hasNext();)
|
||||
{
|
||||
AliasCheck check = i.next();
|
||||
System.err.println("check="+check);
|
||||
if (check.check(path,resource))
|
||||
{
|
||||
System.err.println("OK???");
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Aliased resource: " + resource + " approved by " + check);
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
System.err.println("NULL ALIAS");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -2587,8 +2610,13 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
* Eg. a symbolic link from /foobar.html to /somewhere/wibble.html would be
|
||||
* approved because both the resource and alias end with ".html".
|
||||
*/
|
||||
@Deprecated
|
||||
public static class ApproveSameSuffixAliases implements AliasCheck
|
||||
{
|
||||
{
|
||||
LOG.warn("ApproveSameSuffixAlias is not safe for production");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(String path, Resource resource)
|
||||
{
|
||||
|
@ -2606,8 +2634,13 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
* Eg. a symbolic link from /dirA/foobar.html to /dirB/foobar.html would be
|
||||
* approved because both the resource and alias end with "/foobar.html".
|
||||
*/
|
||||
@Deprecated
|
||||
public static class ApprovePathPrefixAliases implements AliasCheck
|
||||
{
|
||||
{
|
||||
LOG.warn("ApprovePathPrefixAliases is not safe for production");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(String path, Resource resource)
|
||||
{
|
||||
|
@ -2618,6 +2651,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
return resource.toString().endsWith(suffix);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Approve Aliases of a non existent directory.
|
||||
* If a directory "/foobar/" does not exist, then the resource is
|
||||
|
@ -2628,11 +2662,17 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
@Override
|
||||
public boolean check(String path, Resource resource)
|
||||
{
|
||||
int slash = path.lastIndexOf('/');
|
||||
if (slash<0 || resource.exists())
|
||||
if (resource.exists())
|
||||
return false;
|
||||
String suffix=path.substring(slash);
|
||||
return resource.getAlias().toString().endsWith(suffix);
|
||||
|
||||
String a=resource.getAlias().toString();
|
||||
String r=resource.getURL().toString();
|
||||
|
||||
if (a.length()>r.length())
|
||||
return a.startsWith(r) && a.length()==r.length()+1 && a.endsWith("/");
|
||||
else
|
||||
return r.startsWith(a) && r.length()==a.length()+1 && r.endsWith("/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package org.eclipse.jetty.server.handler;
|
||||
|
||||
public class ContextHandlerGetResourceTest
|
||||
{
|
||||
|
||||
}
|
|
@ -46,7 +46,6 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* insensitivity). By default this is turned on, or it can be controlled
|
||||
* by calling the static method @see FileResource#setCheckAliases(boolean)
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class FileResource extends Resource
|
||||
{
|
||||
|
@ -169,7 +168,7 @@ public class FileResource extends Resource
|
|||
return this;
|
||||
|
||||
path=URIUtil.encodePath(path);
|
||||
|
||||
// The encoded path should be a suffix of the resource (give or take a directory / )
|
||||
URI uri;
|
||||
try
|
||||
{
|
||||
|
|
|
@ -29,18 +29,6 @@ detected.
|
|||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||
<Set name="overrideDescriptor"><Property name="jetty.webapps" default="."/>/test.d/override-web.xml</Set>
|
||||
|
||||
<!-- Allow directory symbolic links -->
|
||||
<Call name="addAliasCheck">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.handler.ContextHandler$ApprovePathPrefixAliases"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
<!-- Allow file symbolic links -->
|
||||
<Call name="addAliasCheck">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.handler.ContextHandler$ApproveSameSuffixAliases"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<!-- virtual hosts
|
||||
<Set name="virtualHosts">
|
||||
|
|
Loading…
Reference in New Issue