Skip to main content
diff options
authorDavid Ostrovsky2019-05-16 11:06:57 -0400
committerDavid Ostrovsky2019-06-05 15:50:15 -0400
commit8cd07cb8157eec75099cb93c25d6daa9d5e6e0bc (patch)
tree179c5dbb64367a36431aac80f73e6258170b5554 /org.eclipse.jgit.http.server/src/org
parent692524d2bd7bccccecbebe624e427d7a3587cb5f (diff)
Repository: Add getIdentifier() method to avoid instanceof operator
This change is needed to implement permission aware ref database in Gerrit: [1], that is a pre-requisite to re-enable Git v2 protocol in Gerrit: [2]. Background: Last year Git v2 protocol was enabled in Gerrit. The fact, that JGit layer was not calling ref advertise filter for Git v2 protocol, introduced security vulnerability. The lesson learned from this security incident: Gerrit should not rely on ref advertise filter being called by JGit to implement crictical security checks. Instead, the idea is to use the same approach as currently used by Google's internal code on that didn't suffer from this vulnerability: provide a custom repository to JGit. The repository provides a RefDatabase that is permission-aware and will only ever return refs that the user has access to. However, due to hard coded instanceof operator usages in JGit code base, some tests in Gerrit are failing with: [1] in place. This change addresses this problem. [1] [2] Change-Id: I67c0f53ca33b149442e7ee3e51910d19e3f348d5 Signed-off-by: David Ostrovsky <> Signed-off-by: Matthias Sohn <>
Diffstat (limited to 'org.eclipse.jgit.http.server/src/org')
1 files changed, 4 insertions, 6 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/
index b6d73b5591..256279bfed 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/
@@ -64,7 +64,6 @@ import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@@ -276,12 +275,11 @@ public final class ServletUtils {
static String identify(Repository git) {
- if (git instanceof DfsRepository) {
- return ((DfsRepository) git).getDescription().getRepositoryName();
- } else if (git.getDirectory() != null) {
- return git.getDirectory().getPath();
+ String identifier = git.getIdentifier();
+ if (identifier == null) {
+ return "unknown";
- return "unknown";
+ return identifier;
private ServletUtils() {

Back to the top