import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
-import com.gitblit.GitBlit;\r
+import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
\r
/**\r
* @see http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0450\r
* @author jpyeron\r
*/\r
- public static class CVE_2007_0450\r
- {\r
+ public static class CVE_2007_0450 {\r
/**\r
* This method will test for know issues in certain containers where %2F\r
* is blocked from use in URLs. It will emit a warning to the logger if\r
* the configuration of Tomcat causes the URL processing to fail on %2F.\r
*/\r
- public static void test()\r
- {\r
- if (GitBlit.getBoolean(Keys.web.mountParameters, true)\r
- && ((GitBlit.getChar(Keys.web.forwardSlashCharacter, '/')) == '/' || (GitBlit.getChar(\r
- Keys.web.forwardSlashCharacter, '/')) == '\\'))\r
- {\r
- try\r
- {\r
- if (GitBlit.isGO())\r
- ;\r
- else if (logCVE_2007_0450Tomcat())\r
- ;\r
- // else if (logCVE_2007_0450xxx());\r
- else\r
- {\r
- LOGGER.info("Unknown container, cannot check for CVE-2007-0450 aplicability");\r
- }\r
- }\r
- catch (Throwable t)\r
- {\r
- LOGGER.warn("Failure in checking for CVE-2007-0450 aplicability", t);\r
- }\r
+ public static void test(IStoredSettings settings) {\r
+ boolean mounted = settings.getBoolean(Keys.web.mountParameters, true);\r
+ char fsc = settings.getChar(Keys.web.forwardSlashCharacter, '/');\r
+ if (mounted && ((fsc == '/') || (fsc == '\\'))) {\r
+ logCVE_2007_0450Tomcat(settings);\r
}\r
-\r
}\r
\r
/**\r
* @return true if it recognizes Tomcat, false if it does not recognize\r
* Tomcat\r
*/\r
- private static boolean logCVE_2007_0450Tomcat()\r
- {\r
- try\r
- {\r
+ private static boolean logCVE_2007_0450Tomcat(IStoredSettings settings) {\r
+ try {\r
byte[] test = "http://server.domain:8080/context/servlet/param%2fparam".getBytes();\r
\r
// ByteChunk mb=new ByteChunk();\r
Object mb = cByteChunk.newInstance();\r
\r
// mb.setBytes(test, 0, test.length);\r
- Method mByteChunck_setBytes = cByteChunk.getMethod("setBytes", byte[].class, int.class, int.class);\r
- mByteChunck_setBytes.invoke(mb, test, 0, test.length);\r
+ Method setBytes = cByteChunk.getMethod("setBytes", byte[].class, int.class, int.class);\r
+ setBytes.invoke(mb, test, 0, test.length);\r
\r
// UDecoder ud=new UDecoder();\r
Class<?> cUDecoder = Class.forName("org.apache.tomcat.util.buf.UDecoder");\r
Object ud = cUDecoder.newInstance();\r
\r
// ud.convert(mb,false);\r
- Method mUDecoder_convert = cUDecoder.getMethod("convert", cByteChunk, boolean.class);\r
+ Method convert = cUDecoder.getMethod("convert", cByteChunk, boolean.class);\r
\r
- try\r
- {\r
- mUDecoder_convert.invoke(ud, mb, false);\r
- }\r
- catch (InvocationTargetException e)\r
- {\r
- if (e.getTargetException() != null && e.getTargetException() instanceof CharConversionException)\r
- {\r
+ try {\r
+ convert.invoke(ud, mb, false);\r
+ } catch (InvocationTargetException e) {\r
+ if (e.getTargetException() != null && e.getTargetException() instanceof CharConversionException) {\r
LOGGER.warn("You are using a Tomcat-based server and your current settings will prevent grouped repositories, forks, personal repositories, and tree navigation from working properly. Please review the FAQ for details about running Gitblit on Tomcat. http://gitblit.com/faq.html and http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0450");\r
+ LOGGER.warn("Overriding {} and setting to {}", Keys.web.forwardSlashCharacter, "!");\r
+ settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");\r
return true;\r
}\r
throw e;\r
}\r
- }\r
- catch (Throwable t)\r
- {\r
+ } catch (Throwable t) {\r
// The apache url decoder internals are different, this is not a\r
// Tomcat matching the failure pattern for CVE-2007-0450\r
if (t instanceof ClassNotFoundException || t instanceof NoSuchMethodException\r
- || t instanceof IllegalArgumentException)\r
+ || t instanceof IllegalArgumentException) {\r
return false;\r
+ }\r
LOGGER.debug("This is a tomcat, but the test operation failed somehow", t);\r
}\r
return true;\r