Issue Details (XML | Word | Printable)

Key: DERBY-2131
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: A B
Reporter: A B
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

External DTD files are accessed without a privileged block when Derby parses XML values that reference such DTDs.

Created: 29/Nov/06 11:08 PM   Updated: 11/Dec/06 05:01 PM
Return to search
Component/s: SQL
Affects Version/s: 10.2.1.6, 10.2.2.0, 10.3.1.4
Fix Version/s: 10.2.2.0, 10.3.1.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works d2131_10_2.patch 2006-12-05 05:07 PM A B 2 kB
Text File Licensed for inclusion in ASF works d2131_rewrite_v1.patch 2006-12-01 05:57 PM A B 3 kB
Text File Licensed for inclusion in ASF works d2131_rewrite_v2.patch 2006-12-01 07:01 PM A B 3 kB
Text File Licensed for inclusion in ASF works d2131_v1.patch 2006-11-29 11:10 PM A B 2 kB
Issue Links:
Blocker
 

Resolution Date: 06/Dec/06 12:18 AM


 Description  « Hide
The Derby XMLPARSE operator ultimately makes a call to an external JAXP parser (ex. Xerces or Crimson) to parse an XML value. If the XML value that is being parsed references an external DTD, then the JAXP parser will need to read the DTD file to complete parsing. However, the current code in SqlXmlUtil.java does not use a privileged block when it calls out to the JAXP parser. As a result, when a user who is running with a security manager tries to insert a document that references an external DTD, the call to XMLPARSE will fail with a security exception--even if the JAXP parser has the required "read" permissions.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
A B added a comment - 29/Nov/06 11:10 PM
Attaching a patch, d2131_v1.patch, that wraps the call to JAXP inside a priveleged block. I ran tests with some local (soon-to-be-posted) changes for DERBY-1758 to confirm that the patch solves the reported problem (i.e. that assignment of "read" permission to the JAXP parser allows successful execution of XMLPARSE). I also ran derbyall on Red Hat Linux using ibm142 with no failures. The "XMLSuite" JUnit suite also ran without error.

The patch doesn't include any tests; however, relevant test cases will be enabled as part of DERBY-1758 to verify the behavior.

I am very new to the notion of security managers and privileged blocks, so while this is a small patch, I would appreciate it if someone could review it to make sure that the changes make sense...

A B added a comment - 30/Nov/06 12:01 AM
Marking this issue as "blocking" DERBY-1758 since the latter cannot be resolved until the lang/XMLBindingTest is running under a security manager, and that cannot happen until this issue (DERBY-2131) is resolved.

A B added a comment - 01/Dec/06 12:22 AM
derbyall and suites.All both ran without errors and there were no objections to the posted patch, so I committed d2131_v1.patch with svn 481117.

A B added a comment - 01/Dec/06 12:23 AM
Reopening to set fix version.

Daniel John Debrunner added a comment - 01/Dec/06 12:51 AM
Finally got around to looking at the patch. It's generally correct, but you probably want to catch the PrivilegedExceptionAction and unwrap it. Then if there's an i/o error accessing the DTD it won't appear as a possible security exception to the user.

The other general rule with privileged blocks is to put as little code as possible into the priv block, I'm not sure what code requires the privilege block, but here's an example re-write.

       final InputSource is = new InputSource(new StringReader(xmlAsText));
        aList.add( java.security.AccessController.doPrivileged(
            new java.security.PrivilegedExceptionAction()
            {
                public Object run() throws Exception
                {
                    return dBuilder.parse(is);
                }
            }));


A B added a comment - 01/Dec/06 12:59 AM
Thanks for the suggestions, Dan. This is good to know. I'll work on a follow-up patch to make the changes you mention here and will post it tomorrow.

Re-opening the issue for now.

A B added a comment - 01/Dec/06 05:57 PM
Attaching a second patch, d2131_rewrite_v1.patch, that rewrites the privileged block (which has already been committed) to account for Dan's suggestions.

Regarding "you probably want to catch the PrivilegedExceptionAction and unwrap it. ". I did some quick looking at other places in the Derby code where PrivilegedExceptions are caught and it seems like unwrapping the exception is simply a matter of using the result of "PrivilegedException.getException()"--so in this case, we throw the result of "getException()" instead of throwing the PrivilegedException itself.

If this was too simple of an interpretation (ex. if the unwrapping needs to be more extensive or should be selective to i/o errors), please let me know and I can try again...

Daniel John Debrunner added a comment - 01/Dec/06 06:43 PM
DocumentBuilder.parse() is documented to throw these exceptions: SAXException, IOException but the run() method declares itself as throwing Exception. WOuld it not be better to have the specific errors?

A B added a comment - 01/Dec/06 07:01 PM
Another version of the "rewrite" patch that declares the correct exceptions on the privileged "run" method. Thank you for pointing that out, Dan.

A B added a comment - 04/Dec/06 07:36 PM
Committed d2131_rewrite_v2.patch with svn 482303.

A B added a comment - 05/Dec/06 05:07 PM
Attaching a patch to port this fix back to 10.2. I ran the old "xmlSuite" on 10.2 jars with this patch applied and they ran without problem. I'm running derbyall now just to be safe and will commit the patch to 10.2 if all goes well.

d2131_10_2.patch was created as follows:

svn merge -r 481116:481117 https://svn.apache.org/repos/asf/db/derby/code/trunk

svn merge -r 482302:482303 https://svn.apache.org/repos/asf/db/derby/code/truk

svn diff > d2131_10_2.patch


A B added a comment - 06/Dec/06 12:18 AM
derbyall ran cleanly with 10.2 jars after applying this patch. And the XML tests in suites.xmlSuite all ran cleanly, as well. So I committed d2131_10_2.patch with svn 482837.

A B added a comment - 11/Dec/06 05:01 PM
No further issues/comments after the changes were committed, so marking this as closed.