Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant code example shows a vulnerability present in several versions of the Tomcat HTTP web server (fixed in version 6.0.20) , that allows untrusted web applications to override the default XML parser used by the system to process web.xml, context.xml, and tag library descriptor (TLD) files of other web applications deployed on the Tomcat instance. Consequently, untrusted web applications that install a parser could view and/or alter these files under certain circumstances.

Wiki Markup
The noncompliant code example shows the code associated with initialization of a new {{Digester}} instance in the {{org.apache.catalina.startup.ContextConfig}} class. "A {{Digester}} processes an XML input stream by matching a series of element nesting patterns to execute Rules that have been added prior to the start of parsing" \[[Tomcat 2009|AA. Bibliography#Tomcat 09]\].  The code to initialize the {{Digester}} follows:

...

The createWebDigester() method is responsible for creating the Digester. This method calls createWebXMLDigester(), which invokes the method DigesterFactory.newDigester(). Thie This method creates the new digester instance and sets a boolean flag useContextClassLoader to true.

...

The useContextClassLoader flag is used by Digester to decide which ClassLoader to use when loading new classes. When true, it uses the WebappClassLoader, which is untrusted , because it loads whatever classes are requested by various web applications.

...

The underlying problem is that the newInstance() method is being invoked on behalf of a web application's class loader, the WebappClassLoader, and it loads classes before Tomcat has loaded all the classes it needs. If a web application has loaded its own javax.xml.parsers.SAXParserFactory, then when Tomcat tries to access a SAXParserFactory, it will access the incorrect SaxParserFactory used by the web app , rather than the standard Java SAXParserFactory that it depends on.

...

In this compliant solution, Tomcat initializes the SAXParserFactory when it creates the Digester. This guarantees that the SAXParserFactory is constructed using the container's class loader , rather than the WebappClassLoader.

The webDigester is also marked final. This prevents any subclasses from assigning a new object reference to webDigester. (See OBJ10-J. Do not use public static non-final variables for more information.) It also prevents a race condition where another thread could access webDigester before it is fully initialized; see . (See OBJ11-J. Prevent access to partially initialized objects for more information.)

Code Block
bgColor#ccccff
protected static final Digester webDigester = init();

protected Digester init() {
  Digester digester = createWebDigester();
  digester.getParser(); // Does not use the context Classloader at initialization, so safe
  return digester;
}

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="dd7ff6fe0c6e1b93-dae1cb22-45734dcb-8b7f8d5a-1adc61fbd183bfb4d5ee6c60"><ac:plain-text-body><![CDATA[

[[CVE 2008

AA. Bibliography#CVE 08]]

[CVE-2009-0783

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-0783]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="aaa1e89116493340-61f5096e-46a74b1f-9d999232-82165e168a5b8770dc096327"><ac:plain-text-body><![CDATA[

[[Gong 2003

AA. Bibliography#Gong 03]]

Section 4.3.2, Class Loader Delegation Hierarchy

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bf8b65efdc3f6305-2e5cd0c5-46e54541-92e987d2-905bc890c9055b04dfc9fe05"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

Section 4.3.2, "The Class Object"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="04c43a33a612b94f-92158369-4a654194-a65e85d1-29ae7b7a79d080c542ddb3b5"><ac:plain-text-body><![CDATA[

[[Tomcat 2009

AA. Bibliography#Tomcat 09]]

[Bug ID 29936

https://issues.apache.org/bugzilla/show_bug.cgi?id=29936], API Class org.apache.tomcat.util.digester.Digester, [Security fix in v 6.0.20

http://tomcat.apache.org/security-6.html]

]]></ac:plain-text-body></ac:structured-macro>

...