You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2026/07/24 14:11:53 UTC

[PR] MWAR-471: normalize file permissions on dependencies copied to WEB-INF/lib [maven-war-plugin]

elharo opened a new pull request, #634:
URL: https://github.com/apache/maven-war-plugin/pull/634

   When building on Windows with WSL sharing a disk with the local repository, dependency jars copied to WEB-INF/lib may inherit executable permissions from the local repository.
   
   This normalizes file permissions on copied files to:
   - Not executable
   - Readable by everyone
   - Writable only by owner
   
   Fixes #539


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MWAR-471] normalize file permissions on dependencies copied to WEB-INF/lib [maven-war-plugin]

Posted by "ascheman (via GitHub)" <gi...@apache.org>.
ascheman commented on PR #634:
URL: https://github.com/apache/maven-war-plugin/pull/634#issuecomment-5085776961

   > PTAL
   
   @elharo No new commit landed (head still `e8f0732439`), so the `||` short-circuit is unchanged. The ask: pull the three `set*` calls out of the `if` and apply all three unconditionally, then log if any failed. Re-review as soon as it's in — thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MWAR-471] normalize file permissions on dependencies copied to WEB-INF/lib [maven-war-plugin]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo merged PR #634:
URL: https://github.com/apache/maven-war-plugin/pull/634


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MWAR-471] normalize file permissions on dependencies copied to WEB-INF/lib [maven-war-plugin]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #634:
URL: https://github.com/apache/maven-war-plugin/pull/634#discussion_r3646086747


##########
src/test/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTaskTest.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.war.packaging;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.war.util.WebappStructure;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.filtering.FilterWrapper;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class AbstractWarPackagingTaskTest {
+
+    @TempDir
+    File tempDir;
+
+    @Test
+    void testCopyFileRemovesExecutablePermissions() throws IOException {
+        File source = new File(tempDir, "source.jar");
+        assertTrue(source.createNewFile());
+        source.setExecutable(true, false);
+        source.setReadable(true, false);
+        source.setWritable(true, true);
+        assertTrue(source.canExecute());

Review Comment:
   This test assumes POSIX-style executable bits can be reliably set/cleared via java.io.File. On non-POSIX file systems (notably Windows), File#setExecutable/canExecute semantics differ and this can fail or become flaky. Consider guarding the test with a JUnit assumption that the underlying filesystem supports the "posix" attribute view.
   
   This issue also appears on line 69 of the same file.



##########
src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java:
##########
@@ -346,6 +346,10 @@ protected boolean copyFile(
                 FileUtils.copyFile(source.getCanonicalFile(), destination);
                 // preserve timestamp
                 destination.setLastModified(readAttributes.lastModifiedTime().toMillis());
+                // normalize permissions: remove executable bits for files copied to the webapp
+                destination.setExecutable(false, false);
+                destination.setReadable(true, false);
+                destination.setWritable(true, true);

Review Comment:
   The permission normalization calls ignore the boolean return values from File#setExecutable/#setReadable/#setWritable. On filesystems/OSes that don't support these operations, this will silently fail and the jar may remain executable. Consider checking the return values and logging (at debug) when normalization could not be applied, so the behavior is diagnosable in the environments this change targets.



##########
src/test/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTaskTest.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.war.packaging;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.war.util.WebappStructure;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.filtering.FilterWrapper;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class AbstractWarPackagingTaskTest {
+
+    @TempDir
+    File tempDir;
+
+    @Test
+    void testCopyFileRemovesExecutablePermissions() throws IOException {
+        File source = new File(tempDir, "source.jar");
+        assertTrue(source.createNewFile());
+        source.setExecutable(true, false);
+        source.setReadable(true, false);
+        source.setWritable(true, true);
+        assertTrue(source.canExecute());
+
+        File webappDir = new File(tempDir, "webapp");
+        File destination = new File(webappDir, "WEB-INF/lib/test.jar");
+
+        AbstractWarPackagingTask task = createTask();
+        task.copyFile(createContext(webappDir), source, destination, "WEB-INF/lib/test.jar", false);
+
+        assertTrue(destination.exists());
+        assertFalse(destination.canExecute(), "copied file should not be executable");
+    }

Review Comment:
   The PR description states copied dependencies should be normalized to: not executable, readable by everyone, and writable only by the owner. The tests currently only assert the executable bit; adding an assertion on the full POSIX permissions (e.g., 0644) would better cover the intended behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org