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

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-scm.git


The following commit(s) were added to refs/heads/master by this push:
     new 980029bc1 Stop the git URL password mask at the first slash
980029bc1 is described below

commit 980029bc11ff1ac297e488598eeb9c16c6abecaa
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 21 01:23:29 2026 +0100

    Stop the git URL password mask at the first slash
    
    The pattern ran from the first colon to the last @, so an @ in the path (a 
Jenkins workspace@2 directory) made it swallow part of the URL.
---
 .../maven/scm/provider/git/util/GitUtil.java       |   2 +-
 .../maven/scm/provider/git/util/GitUtilTest.java   | 104 +++++++++++++++++++++
 2 files changed, 105 insertions(+), 1 deletion(-)

diff --git 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
index 4b3eef69d..0b08478f1 100644
--- 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
+++ 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
@@ -44,7 +44,7 @@ public class GitUtil {
      */
     public static final String PASSWORD_PLACE_HOLDER_WITH_DELIMITERS = 
":********@";
 
-    private static final Pattern PASSWORD_IN_URL_PATTERN = 
Pattern.compile("^.*(:[^/].*@).*$");
+    private static final Pattern PASSWORD_IN_URL_PATTERN = 
Pattern.compile("^.*(:[^/]+@).*$");
 
     private static File settingsDirectory = DEFAULT_SETTINGS_DIRECTORY;
 
diff --git 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/util/GitUtilTest.java
 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/util/GitUtilTest.java
new file mode 100644
index 000000000..6e6550ffe
--- /dev/null
+++ 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/util/GitUtilTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.scm.provider.git.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class GitUtilTest {
+
+    @Test
+    void scpStyleUrlHasNoPassword() {
+        assertEquals("[email protected]:olamy/repo.git", 
GitUtil.maskPasswordInUrl("[email protected]:olamy/repo.git"));
+    }
+
+    @Test
+    void scpStyleUrlWithAtInPathIsUnchanged() {
+        assertEquals(
+                "[email protected]:olamy/workspace@2/repo.git",
+                
GitUtil.maskPasswordInUrl("[email protected]:olamy/workspace@2/repo.git"));
+    }
+
+    @Test
+    void sshUrlWithPortAndAtInPathIsUnchanged() {
+        assertEquals(
+                "ssh://[email protected]:2222/olamy/workspace@2/repo.git",
+                
GitUtil.maskPasswordInUrl("ssh://[email protected]:2222/olamy/workspace@2/repo.git"));
+    }
+
+    @Test
+    void passwordInAuthorityIsMasked() {
+        assertEquals(
+                "https://user:********@github.com/olamy/repo.git";,
+                
GitUtil.maskPasswordInUrl("https://user:[email protected]/olamy/repo.git";));
+    }
+
+    @Test
+    void passwordInAuthorityIsMaskedWhenPathContainsAt() {
+        assertEquals(
+                "https://user:********@github.com/olamy/workspace@2/repo.git";,
+                
GitUtil.maskPasswordInUrl("https://user:[email protected]/olamy/workspace@2/repo.git";));
+    }
+
+    @Test
+    void userNameContainingAtKeepsHostAndPort() {
+        assertEquals(
+                
"http://[email protected]:********@gitrepos.apache.org:8800/pmgt/trunk";,
+                
GitUtil.maskPasswordInUrl("http://[email protected]:[email protected]:8800/pmgt/trunk";));
+    }
+
+    @Test
+    void passwordInCommandLineIsMasked() {
+        assertEquals(
+                "git push https://user:********@foo.com/git/trunk 
refs/tags/my-tag-1",
+                GitUtil.maskPasswordInUrl("git push 
https://user:[email protected]/git/trunk refs/tags/my-tag-1"));
+    }
+
+    @Test
+    void testPasswordInScpStyleUrlIsMasked() {
+        assertEquals("user:********@host:path/repo.git", 
GitUtil.maskPasswordInUrl("user:password@host:path/repo.git"));
+        assertEquals("user:********@host:repo.git", 
GitUtil.maskPasswordInUrl("user:password@host:repo.git"));
+    }
+
+    @Test
+    void testScpStyleUrlWithoutPasswordIsNotChanged() {
+        assertEquals("[email protected]:repo.git", 
GitUtil.maskPasswordInUrl("[email protected]:repo.git"));
+        assertEquals("host:path/repo.git", 
GitUtil.maskPasswordInUrl("host:path/repo.git"));
+    }
+
+    @Test
+    void testPasswordInCommandLineIsMasked() {
+        assertEquals(
+                "git clone user:********@host:r.git dir",
+                GitUtil.maskPasswordInUrl("git clone user:secret@host:r.git 
dir"));
+        assertEquals(
+                "/bin/sh -c 'git' 'clone' 'user:********@host:path/r.git' 
'dir'",
+                GitUtil.maskPasswordInUrl("/bin/sh -c 'git' 'clone' 
'user:secret@host:path/r.git' 'dir'"));
+        assertEquals(
+                "/bin/sh -c 'git' 'push' 'https://user:********@host/x.git'",
+                GitUtil.maskPasswordInUrl("/bin/sh -c 'git' 'push' 
'https://user:pa'\"'\"'ss@host/x.git'"));
+    }
+
+    @Test
+    void testPasswordBeforePortIsMaskedNotThePath() {
+        assertEquals(
+                "https://user:********@host:8443/x@y";, 
GitUtil.maskPasswordInUrl("https://user:secret@host:8443/x@y";));
+    }
+}

Reply via email to