Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocity 931 update secure classlist #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,30 @@ public Method getMethod(Class clazz, String methodName, Object[] params)
*/
public boolean checkObjectExecutePermission(Class clazz, String methodName)
{
/**
* check for wait and notify
*/
/**
* check for wait and notify
*/
if (methodName != null &&
(methodName.equals("wait") || methodName.equals("notify")) )
{
return false;
}
{
return false;
}

/**
* Always allow the most common classes - Number, Boolean and String
*/
else if (Number.class.isAssignableFrom(clazz))
{
return true;
}
else if (Boolean.class.isAssignableFrom(clazz))
{
return true;
}
else if (String.class.isAssignableFrom(clazz))
{
return true;
}
/**
* Always allow the most common classes - Number, Boolean and String
*/
else if (Number.class.isAssignableFrom(clazz))
{
return true;
}
else if (Boolean.class.isAssignableFrom(clazz))
{
return true;
}
else if (String.class.isAssignableFrom(clazz))
{
return true;
}

/**
* Always allow Class.getName()
Expand All @@ -121,6 +121,15 @@ else if (Class.class.isAssignableFrom(clazz) &&
return true;
}

/**
* Always disallow ClassLoader, Thread and subclasses
*/
if (ClassLoader.class.isAssignableFrom(clazz) ||
Thread.class.isAssignableFrom(clazz))
{
return false;
}

/**
* check the classname (minus any array info)
* whether it matches disallowed classes or packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.HashSet;

Expand Down Expand Up @@ -138,9 +141,9 @@ private void doTestMethods(VelocityEngine ve, String[] templateStrings, boolean

private boolean doesStringEvaluate(VelocityEngine ve, Context c, String inputString) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException
{
// assume that an evaluation is bad if the input and result are the same (e.g. a bad reference)
// or the result is an empty string (e.g. bad #foreach)
Writer w = new StringWriter();
// assume that an evaluation is bad if the input and result are the same (e.g. a bad reference)
// or the result is an empty string (e.g. bad #foreach)
Writer w = new StringWriter();
ve.evaluate(c, w, "foo", inputString);
String result = w.toString();
return (result.length() > 0 ) && !result.equals(inputString);
Expand All @@ -163,14 +166,35 @@ public void setProperty(String val)
}


public Collection getCollection()
{
Collection c = new HashSet();
c.add("aaa");
c.add("bbb");
c.add("ccc");
return c;
}
public Collection getCollection()
{
Collection c = new HashSet();
c.add("aaa");
c.add("bbb");
c.add("ccc");
return c;
}

public ClassLoader getSampleClassLoader1()
{
return this.getClass().getClassLoader();
}

/**
* sample property which is a subclass of ClassLoader
* @return
*/
public ClassLoader getSampleClassLoader2()
arkanovicz marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
return new URLClassLoader(new URL[]{new URL("file://.")}, this.getClass().getClassLoader());
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ runtime.conversion.handler.class = org.apache.velocity.util.introspection.TypeCo
# accessed.
# ----------------------------------------------------------------------------

# Prohibit reflection
introspector.restrict.packages = java.lang.reflect

# The two most dangerous classes
# ClassLoader, Thread, and subclasses disabled by default in SecureIntrospectorImpl

introspector.restrict.classes = java.lang.Class
introspector.restrict.classes = java.lang.ClassLoader

# Restrict these for extra safety
# Restrict these system classes. Note that anything in this list is matched exactly.
# (Subclasses must be explicitly named to be included).

introspector.restrict.classes = java.lang.Class
introspector.restrict.classes = java.lang.Compiler
introspector.restrict.classes = java.lang.InheritableThreadLocal
introspector.restrict.classes = java.lang.Package
Expand All @@ -237,10 +237,16 @@ introspector.restrict.classes = java.lang.Runtime
introspector.restrict.classes = java.lang.RuntimePermission
introspector.restrict.classes = java.lang.SecurityManager
introspector.restrict.classes = java.lang.System
introspector.restrict.classes = java.lang.Thread
introspector.restrict.classes = java.lang.ThreadGroup
introspector.restrict.classes = java.lang.ThreadLocal

# Restrict instance managers for common servlet containers (Tomcat, JBoss, Jetty)

introspector.restrict.classes = org.apache.catalina.core.DefaultInstanceManager
introspector.restrict.classes = org.apache.tomcat.SimpleInstanceManager
introspector.restrict.classes = org.wildfly.extension.undertow.deployment.UndertowJSPInstanceManager
introspector.restrict.classes = org.eclipse.jetty.util.DecoratedObjectFactory

# ----------------------------------------------------------------------------
# SPACE GOBBLING
# ----------------------------------------------------------------------------
Expand Down