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@xxxxxxxxxxx> --- I knew I wrote this patch, but I couldn't find it in tree, or on the mailing list. So I'm sending/resending it. :-) .../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.422.g7298 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html