git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Permit a wider range of repository names in jgit daemon requests

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 5, 2009, 02:46 UTC
Message-ID
<20090105024622.GC20973@spearce.org>
In-Reply-To
<200901040048.01520.robin.rosenberg@dewire.com>

The earlier restriction was too narrow for some applications, for example repositories named "jgit.dev" and "jgit.test" are perfectly valid Git repositories and should still be able to be served by the daemon.

By blocking out only uses of ".." as a path component and Windows UNC paths (by blocking "\") we can reasonably prevent the client from escaping the base dirctories configured in the daemon.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
  Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
  > tisdag 23 december 2008 01:27:23 skrev Shawn O. Pearce:
  > > +	private static final Pattern SAFE_REPOSITORY_NAME = Pattern
  > > +			.compile("^[A-Za-z][A-Za-z0-9/_ -]+(\\.git)?$");
  > 
  > This restriction is too strict. Wouldn't any path not containing ".." be valid? In particular this did not work with my "EGIT.contrib" repo. I
  > have a lot of repos with names llike "name.purpose". Just adding
  > '.' to the character set isn't really enough.
  Yup.
  
 .../src/org/spearce/jgit/transport/Daemon.java     |   42 +++++++++----------
 1 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java b/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
index 646c88d..d39fd04 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
@@ -51,7 +51,6 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.regex.Pattern;
 
 import org.spearce.jgit.lib.Repository;
 
@@ -62,9 +61,6 @@
 
 	private static final int BACKLOG = 5;
 
-	private static final Pattern SAFE_REPOSITORY_NAME = Pattern
-			.compile("^[A-Za-z][A-Za-z0-9/_ -]+(\\.git)?$");
-
 	private InetSocketAddress myAddress;
 
 	private final DaemonService[] services;
@@ -292,24 +288,26 @@ synchronized (exports) {
 				return db;
 		}
 
-		if (SAFE_REPOSITORY_NAME.matcher(name).matches()) {
-			final File[] search;
-			synchronized (exportBase) {
-				search = exportBase.toArray(new File[exportBase.size()]);
-			}
-			for (final File f : search) {
-				db = openRepository(new File(f, name));
-				if (db != null)
-					return db;
-
-				db = openRepository(new File(f, name + ".git"));
-				if (db != null)
-					return db;
-
-				db = openRepository(new File(f, name + "/.git"));
-				if (db != null)
-					return db;
-			}
+		if (name.startsWith("../") || name.contains("/../")
+				|| name.contains("\\"))
+			return null;
+
+		final File[] search;
+		synchronized (exportBase) {
+			search = exportBase.toArray(new File[exportBase.size()]);
+		}
+		for (final File f : search) {
+			db = openRepository(new File(f, name));
+			if (db != null)
+				return db;
+
+			db = openRepository(new File(f, name + ".git"));
+			if (db != null)
+				return db;
+
+			db = openRepository(new File(f, name + "/.git"));
+			if (db != null)
+				return db;
 		}
 		return null;
 	}
-- 
1.6.1.94.g9388

-- 
Shawn.
Previous: Robin RosenbergNext: Robin Rosenberg
Message 16 of 17 in “Add receive-pack server side support”
  1. 00/13 Add receive-pack server side supportShawn O. Pearce, Dec 23, 2008
  2. 01/13 Fix invalid "double checked locking" in InflaterCacheShawn O. Pearce, Dec 23, 2008
  3. 02/13 Cleanup stupid release of the cached Inflater in IndexPackShawn O. Pearce, Dec 23, 2008
  4. 03/13 Cache an Inflater inside a WindowCursor and reuse it as much as possibleShawn O. Pearce, Dec 23, 2008
  5. 04/13 Make RefDatabase thread-safeShawn O. Pearce, Dec 23, 2008
  6. 05/13 Make PackFile thread-safeShawn O. Pearce, Dec 23, 2008
  7. 06/13 Make Repository thread-safeShawn O. Pearce, Dec 23, 2008
  8. 07/13 Don't open a PackFile multiple times on scanForPacksShawn O. Pearce, Dec 23, 2008
  9. 08/13 Expose RepositoryConfig.getBoolean so applications can use itShawn O. Pearce, Dec 23, 2008
  10. 09/13 Add AnyObjectId.copyTo(StringBuilder)Shawn O. Pearce, Dec 23, 2008
  11. 10/13 Add compare-and-swap semantics to RefUpdateShawn O. Pearce, Dec 23, 2008
  12. 11/13 Allow null new ObjectId during RefUpdate.deleteShawn O. Pearce, Dec 23, 2008
  13. 12/13 Implement the git-receive-pack process in JavaShawn O. Pearce, Dec 23, 2008
  14. 13/13 Add basic git daemon support to publish receive-packShawn O. Pearce, Dec 23, 2008
  15. Robin RosenbergJan 3, 2009
  16. Permit a wider range of repository names in jgit daemon requestsShawn O. Pearce, Jan 5, 2009
  17. Robin RosenbergJan 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.