You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2025/11/03 07:57:31 UTC

(jackrabbit-filevault) branch master updated: JCRVLT-825 Remove patch file support

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

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git


The following commit(s) were added to refs/heads/master by this push:
     new 4dd65c92 JCRVLT-825 Remove patch file support
4dd65c92 is described below

commit 4dd65c925b282991f8e0cebb280fb6cfa393e8a0
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Sep 11 11:17:15 2025 +0200

    JCRVLT-825 Remove patch file support
    
    Prevent writing to arbitrary locations in the filesystem when installing
    packages
---
 .../jackrabbit/vault/fs/io/ImportOptions.java      | 61 +++++++++-------------
 .../apache/jackrabbit/vault/fs/io/Importer.java    | 37 -------------
 2 files changed, 24 insertions(+), 74 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java
index 36fde847..4304f6ce 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java
@@ -31,22 +31,19 @@ import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener;
 import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
 import org.apache.jackrabbit.vault.packaging.DependencyHandling;
 import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Option that control the package import.
  */
 public class ImportOptions {
+    private static final Logger LOG = LoggerFactory.getLogger(ImportOptions.class);
 
     private Boolean strict;
 
     private ProgressTrackerListener listener;
 
-    private String patchParentPath = "/var/crxpatches/";
-
-    private File patchDirectory;
-
-    private boolean patchKeepInRepo = true;
-
     private boolean nonRecursive = false;
 
     private boolean dryRun;
@@ -89,9 +86,6 @@ public class ImportOptions {
         if (base != null) {
             strict = base.strict;
             listener = base.listener;
-            patchParentPath = base.patchParentPath;
-            patchDirectory = base.patchDirectory;
-            patchKeepInRepo = base.patchKeepInRepo;
             nonRecursive = base.nonRecursive;
             dryRun = base.dryRun;
             autoSaveThreshold = base.autoSaveThreshold;
@@ -116,9 +110,6 @@ public class ImportOptions {
         ImportOptions ret = new ImportOptions();
         ret.strict = strict;
         ret.listener = listener;
-        ret.patchParentPath = patchParentPath;
-        ret.patchDirectory = patchDirectory;
-        ret.patchKeepInRepo = patchKeepInRepo;
         ret.nonRecursive = nonRecursive;
         ret.dryRun = dryRun;
         ret.autoSaveThreshold = autoSaveThreshold;
@@ -204,25 +195,32 @@ public class ImportOptions {
     /**
      * Returns the patch parent path
      * @return the patch parent path
+     * @deprecated No longer evaluated as patch files are no longer supported for security reasons.
      */
+    @Deprecated(since = "4.2.0", forRemoval = true)
     public String getPatchParentPath() {
-        return patchParentPath;
+        return null;
     }
 
     /**
      * Sets the parent path of the patch node.
      * @param patchParentPath the path
+     * @deprecated No longer evaluated as patch files are no longer supported for security reasons.
      */
+    @Deprecated(since = "4.2.0", forRemoval = true)
     public void setPatchParentPath(String patchParentPath) {
-        this.patchParentPath = patchParentPath;
+        // noop
+        LOG.warn("Patch files are no longer supported for security reasons. Ignoring patch parent path {}", patchParentPath);
     }
 
     /**
      * Returns the patch directory
      * @return the patch directory
+     * @deprecated No longer evaluated as patch files are no longer supported for security reasons.
      */
+    @Deprecated(since = "4.2.0", forRemoval = true)
     public File getPatchDirectory() {
-        return patchDirectory;
+        return null;
     }
 
     /**
@@ -230,27 +228,33 @@ public class ImportOptions {
      * copied into this directory during extraction.
      * @param patchDirectory The directory
      * @throws IOException if an i/o error occurrs during obtaining the canonical file of this directory.
+     * @deprecated No longer evaluated as patch files are no longer supported for security reasons.
      */
+    @Deprecated(since = "4.2.0", forRemoval = true)
     public void setPatchDirectory(File patchDirectory) throws IOException {
-        this.patchDirectory = patchDirectory == null
-                ? null
-                : patchDirectory.getCanonicalFile();
+        LOG.warn("Patch files are no longer supported for security reasons. Ignoring patch directory {}", patchDirectory);
+        // noop
     }
 
     /**
      * Returns the 'patch-keep-in-repo' flag.
      * @return the 'patch-keep-in-repo' flag.
+     * @deprecated No longer evaluated as patch files are no longer supported for security reasons.
      */
+    @Deprecated(since = "4.2.0", forRemoval = true)
     public boolean isPatchKeepInRepo() {
-        return patchKeepInRepo;
+        return false;
     }
 
     /**
      * Sets the flag if patches should be kept in the repository after there were copied to the disk.
      * @param patchKeepInRepo the flag
+     * @deprecated No longer evaluated as patch files are no longer supported for security reasons.
      */
+    @Deprecated(since = "4.2.0", forRemoval = true)
     public void setPatchKeepInRepo(boolean patchKeepInRepo) {
-        this.patchKeepInRepo = patchKeepInRepo;
+        // noop
+        LOG.warn("Patch files are no longer supported for security reasons. Ignoring setPatchKeepInRepo({})", patchKeepInRepo);
     }
 
     /**
@@ -495,9 +499,6 @@ public class ImportOptions {
         result = prime * result + ((importMode == null) ? 0 : importMode.hashCode());
         result = prime * result + ((listener == null) ? 0 : listener.hashCode());
         result = prime * result + (nonRecursive ? 1231 : 1237);
-        result = prime * result + ((patchDirectory == null) ? 0 : patchDirectory.hashCode());
-        result = prime * result + (patchKeepInRepo ? 1231 : 1237);
-        result = prime * result + ((patchParentPath == null) ? 0 : patchParentPath.hashCode());
         result = prime * result + ((pathMapping == null) ? 0 : pathMapping.hashCode());
         result = prime * result + ((idConflictPolicy == null) ? 0 : idConflictPolicy.hashCode());
         result = prime * result + (strict ? 1231 : 1237);
@@ -549,18 +550,6 @@ public class ImportOptions {
             return false;
         if (nonRecursive != other.nonRecursive)
             return false;
-        if (patchDirectory == null) {
-            if (other.patchDirectory != null)
-                return false;
-        } else if (!patchDirectory.equals(other.patchDirectory))
-            return false;
-        if (patchKeepInRepo != other.patchKeepInRepo)
-            return false;
-        if (patchParentPath == null) {
-            if (other.patchParentPath != null)
-                return false;
-        } else if (!patchParentPath.equals(other.patchParentPath))
-            return false;
         if (pathMapping == null) {
             if (other.pathMapping != null)
                 return false;
@@ -581,8 +570,6 @@ public class ImportOptions {
     @Override
     public String toString() {
         return "ImportOptions [strict=" + strict + ", " + (listener != null ? "listener=" + listener + ", " : "")
-                + (patchParentPath != null ? "patchParentPath=" + patchParentPath + ", " : "")
-                + (patchDirectory != null ? "patchDirectory=" + patchDirectory + ", " : "") + "patchKeepInRepo=" + patchKeepInRepo
                 + ", nonRecursive=" + nonRecursive + ", dryRun=" + dryRun + ", autoSave=" + autoSaveThreshold + ", "
                 + (acHandling != null ? "acHandling=" + acHandling + ", " : "")
                 + (cugHandling != null ? "cugHandling=" + cugHandling + ", " : "")
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java
index 844e1aa2..1c2e8b5f 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java
@@ -17,11 +17,9 @@
 
 package org.apache.jackrabbit.vault.fs.io;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.OutputStream;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -36,7 +34,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Optional;
-import java.util.Properties;
 import java.util.Set;
 
 import javax.jcr.Node;
@@ -45,8 +42,6 @@ import javax.jcr.Session;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.version.Version;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.api.security.authorization.PrincipalSetPolicy;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
@@ -229,12 +224,6 @@ public class Importer {
      */
     private final FileArtifactHandler fileHandler = new FileArtifactHandler();
 
-    /**
-     * list of archive entries that are detected as lowlevel patches and need to be copied to the
-     * filesystem after import.
-     */
-    private final List<Archive.Entry> patches = new LinkedList<Archive.Entry>();
-
     private Map<String, TxInfo> intermediates = new LinkedHashMap<String, TxInfo>();
 
     private Archive archive;
@@ -564,7 +553,6 @@ public class Importer {
         restorePrincipalAcls(session, shouldStashPrincipalPoliciesForArchive(archive));
         checkinNodes(session);
         applyMemberships(session);
-        applyPatches();
         if (opts.isDryRun()) {
             if (hasErrors) {
                 track("Package import simulation finished. (with errors, check logs!)", "");
@@ -857,12 +845,6 @@ public class Importer {
                 if (file.getName().equals(Constants.DOT_CONTENT_XML)) {
                     continue;
                 }
-                if (opts.getPatchDirectory() != null && repoPath.startsWith(opts.getPatchParentPath())) {
-                    patches.add(file);
-                    if (!opts.isPatchKeepInRepo()) {
-                        continue;
-                    }
-                }
                 // todo: find better way to detect sub-packages
                 if (repoPath.startsWith(JcrPackageRegistry.DEFAULT_PACKAGE_ROOT_PATH_PREFIX) && (repoPath.endsWith(".jar") || repoPath.endsWith(".zip"))) {
                     subPackages.add(repoPath);
@@ -1261,25 +1243,6 @@ public class Importer {
         memberships.clear();
     }
 
-    private void applyPatches() {
-        for (Archive.Entry e: patches) {
-            String name = e.getName();
-            File target = new File(opts.getPatchDirectory(), name);
-            if (opts.isDryRun()) {
-                log.debug("Dry run: Would copy patch {} to {}", name, target.getPath());
-            } else {
-                log.debug("Copying patch {} to {}", name, target.getPath());
-                try (InputStream in = archive.getInputSource(e).getByteStream();
-                     OutputStream out = FileUtils.openOutputStream(target)) {
-                    IOUtils.copy(in, out);
-                } catch (IOException e1) {
-                    log.error("Error while copying patch.", e);
-                }
-            }
-            track("P", name);
-        }
-    }
-
     private static class TxInfo {
 
         private TxInfo parent;