This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi-xmlbeans.git


The following commit(s) were added to refs/heads/trunk by this push:
     new cf1ef1e9 Contain FileResourceLoader reads to the resource directory 
(#102)
cf1ef1e9 is described below

commit cf1ef1e92023a91b61de14dd6bc9ca12e67f3f11
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Aug 31 17:01:55 2026 +0100

    Contain FileResourceLoader reads to the resource directory (#102)
    
    FileResourceLoader.getResourceAsStream builds new File(_directory,
    resourceName) and opens it with no containment check. The resource name
    for a compiled schema component is getBasePackage() + handle + ".xsb",
    and the handle is read verbatim from the .xsb index (SchemaTypePool.
    readHandlePool -> reader.readString()) with no validation. A handle of
    "../../../../etc/passwd" in an untrusted compiled type system loaded
    from a directory therefore resolves outside _directory, giving an
    arbitrary read of any .xsb-suffixed file (and SMB egress via a UNC path
    on Windows).
    
    Reject any resolved path whose canonical form is not inside the
    resource directory. Legitimate handles are single filename segments
    (NameUtil.upperCamelCase output, lowercased), so they always stay
    inside the directory and are unaffected. Zip/jar-backed loading already
    uses ZipFile.getEntry, a name lookup that cannot touch the filesystem,
    so it needs no change.
    
    Co-authored-by: Claude Fable 5 <[email protected]>
---
 .../xmlbeans/impl/schema/FileResourceLoader.java   | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/xmlbeans/impl/schema/FileResourceLoader.java 
b/src/main/java/org/apache/xmlbeans/impl/schema/FileResourceLoader.java
index 556f4c4c..65fe9a27 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/FileResourceLoader.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/FileResourceLoader.java
@@ -52,7 +52,15 @@ public class FileResourceLoader implements ResourceLoader
             }
             else
             {
-                return Files.newInputStream(new File(_directory, 
resourceName).toPath());
+                File file = new File(_directory, resourceName);
+                // A resource name is built from an attacker-controllable 
handle read out of a
+                // compiled .xsb; a handle containing "../" would otherwise 
let the resolved path
+                // escape the resource directory and read arbitrary 
.xsb-suffixed files on disk.
+                if (!isContainedIn(file, _directory))
+                {
+                    return null;
+                }
+                return Files.newInputStream(file.toPath());
             }
         }
         catch (IOException e)
@@ -61,6 +69,20 @@ public class FileResourceLoader implements ResourceLoader
         }
     }
 
+    private static boolean isContainedIn(File file, File directory)
+    {
+        try
+        {
+            String dirPath = directory.getCanonicalPath() + File.separator;
+            String filePath = file.getCanonicalPath();
+            return filePath.startsWith(dirPath);
+        }
+        catch (IOException e)
+        {
+            return false;
+        }
+    }
+
     public void close()
     {
         if (_zipfile != null)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to