You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2007/08/16 18:54:42 UTC

svn commit: r566773 - /xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXSLT.java

Author: mullan
Date: Thu Aug 16 09:54:40 2007
New Revision: 566773

URL: http://svn.apache.org/viewvc?view=rev&rev=566773
Log:
Fixed 43145: XSLT Transforms are not executed securely

Modified:
    xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXSLT.java

Modified: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXSLT.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXSLT.java?view=diff&rev=566773&r1=566772&r2=566773
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXSLT.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXSLT.java Thu Aug 16 09:54:40 2007
@@ -1,6 +1,5 @@
-
 /*
- * Copyright  1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2007 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,6 +20,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.lang.reflect.Method;
 
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
@@ -58,6 +58,14 @@
    static final String defaultXSLTSpecNSprefix = "xslt";
    static final String XSLTSTYLESHEET          = "stylesheet";
 
+   // check for secure processing feature
+   private static Class xClass = null;
+   static {
+      try {
+         xClass = Class.forName("javax.xml.XMLConstants");
+      } catch (Exception e) {}
+   }
+
    /**
     * Method engineGetURI
     *
@@ -85,6 +93,10 @@
     protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream baos, Transform _transformObject)
     throws IOException,
            TransformationException {
+      if (xClass == null) {
+         Object exArgs[] = { "SECURE_PROCESSING_FEATURE not supported" };
+         throw new TransformationException("generic.EmptyMessage", exArgs);
+      }
       try {
          Element transformElement = _transformObject.getElement();        
 
@@ -99,6 +111,10 @@
          }
 
          TransformerFactory tFactory = TransformerFactory.newInstance();
+         Class c = tFactory.getClass();
+         Method m = c.getMethod("setFeature", new Class[] {String.class, boolean.class});
+         // Process XSLT stylesheets in a secure manner
+         m.invoke(tFactory, new Object[] {"http://javax.xml.XMLConstants/feature/secure-processing", Boolean.TRUE});
 
          /*
           * This transform requires an octet stream as input. If the actual
@@ -153,6 +169,18 @@
 
          throw new TransformationException("generic.EmptyMessage", exArgs, ex);
       } catch (TransformerException ex) {
+         Object exArgs[] = { ex.getMessage() };
+
+         throw new TransformationException("generic.EmptyMessage", exArgs, ex);
+      } catch (NoSuchMethodException ex) {
+         Object exArgs[] = { ex.getMessage() };
+
+         throw new TransformationException("generic.EmptyMessage", exArgs, ex);
+      } catch (IllegalAccessException ex) {
+         Object exArgs[] = { ex.getMessage() };
+
+         throw new TransformationException("generic.EmptyMessage", exArgs, ex);
+      } catch (java.lang.reflect.InvocationTargetException ex) {
          Object exArgs[] = { ex.getMessage() };
 
          throw new TransformationException("generic.EmptyMessage", exArgs, ex);