Skip to contentSkip to conversation

cvsserver: Make req_Root more critical of its input data

PATCH New Frank Lichtenheld 3 participants 7 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cvsserver: Make req_Root more critical of its input data

The path submitted with the Root request has to be absolute (cvs does it this way and it may save us some sanity checks later)

If multiple roots are specified (e.g. because we use pserver authentication which will already include the root), ensure that they say all the same.

Probably neither is a security risk, and neither should ever be triggered by a sane client, but when validating input data, it's better to be save than sorry.

---
 git-cvsserver.perl              |   11 +++++++++++
 t/t9400-git-cvsserver-server.sh |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)
git-cvsserver.perl +11 -0
index 2b4825a..d41b29f 100755
@@ -167,6 +167,17 @@ sub req_Root
     my ( $cmd, $data ) = @_;
     $log->debug("req_Root : $data");
 
+    unless ($data =~ m#^/#) {
+	print "error 1 Root must be an absolute pathname\n";
+	return 0;
+    }
+
+    if ($state->{CVSROOT}
+	&& ($state->{CVSROOT} ne $data)) {
+	print "error 1 Conflicting roots specified\n";
+	return 0;
+    }
+
     $state->{CVSROOT} = $data;
 
     $ENV{GIT_DIR} = $state->{CVSROOT} . "/";
t/t9400-git-cvsserver-server.sh +34 -0
index e9ef315..41dcf64 100755
@@ -110,6 +110,40 @@ test_expect_success 'pserver authentication failure (login/non-anonymous user)'
    tail -n1 log | grep -q "^I HATE YOU$"'
 
 
+# misuse pserver authentication for testing of req_Root
+
+cat >request-relative  <<EOF
+BEGIN AUTH REQUEST
+gitcvs.git
+anonymous
+
+END AUTH REQUEST
+EOF
+
+cat >request-conflict  <<EOF
+BEGIN AUTH REQUEST
+$SERVERDIR
+anonymous
+
+END AUTH REQUEST
+Root $WORKDIR
+EOF
+
+test_expect_success 'req_Root failure (relative pathname)' \
+  'if cat request-relative | git-cvsserver pserver >log 2>&1
+   then
+       echo unexpected success
+       false
+   else
+       true
+   fi &&
+   tail log | grep -q "^error 1 Root must be an absolute pathname$"'
+
+test_expect_success 'req_Root failure (conflicting roots)' \
+  'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
+   tail log | grep -q "^error 1 Conflicting roots specified$"'
+
+
 #--------------
 # CONFIG TESTS
 #--------------
Signature · 1 line
1.5.2.1
#1 lore raw

PATCH 1/1 cvsserver: Add some useful commandline options

Make git-cvsserver understand some options inspired by git-daemon, namely --base-path, --export-all, --strict-paths.

Also allow the caller to specify a whitelist of allowed directories, again similar to git-daemon.

While already adding option parsing also support the common --help and --version options.

Rationale:

While the gitcvs.enabled configuration option already offers means to limit git-cvsserver access to a repository, there are some use cases where other methods of access control prove to be more useful.

E.g. if setting up a pserver for a collection of public repositories one might want limit the exported repositories to exactly the directory this collection is located whithout having to worry about other repositories that might lie around with the configuration variable set (never trust your users ;)

---
 Documentation/git-cvsserver.txt |   42 ++++++++++++++++++++
 git-cvsserver.perl              |   79 ++++++++++++++++++++++++++++++++++++---
 t/t9400-git-cvsserver-server.sh |   28 ++++++++++++++
 3 files changed, 143 insertions(+), 6 deletions(-)

--interpolated-path can't be supported because the information isn't available in CVS protocoll.

--user-path could be supported, I just hadn't motivation/time enough to do that.

The documentation part of the patch could probably use some improvement still.

Documentation/git-cvsserver.txt +42 -0
index e5005f0..6d1e311 100644
@@ -7,10 +7,52 @@ git-cvsserver - A CVS server emulator for git
 
 SYNOPSIS
 --------
+
+SSH:
+
 [verse]
 export CVS_SERVER=git-cvsserver
 'cvs' -d :ext:user@server/path/repo.git co <HEAD_name>
 
+pserver (/etc/inetd.conf):
+
+[verse]
+cvspserver stream tcp nowait nobody /usr/bin/git-cvsserver git-cvsserver pserver
+
+Usage:
+
+[verse]
+'git-cvsserver' [options] [pserver|server] [<directory> ...]
+
+OPTIONS
+-------
+
+All these options obviously only make sense if enforced by the server side.
+They have been implemented to resemble the gitlink:git-daemon[1] options as
+closely as possible.
+
+--base-path <path>::
+Prepend 'path' to requested CVSROOT
+
+--strict-paths::
+Don't allow recursing into subdirectories
+
+--export-all::
+Don't check for `gitcvs.enabled` in config
+
+--version, -V::
+Print version information and exit
+
+--help, -h, -H::
+Print usage information and exit
+
+<directory>::
+You can specify a list of allowed directories. If no directories
+are given, all are allowed. This is an additional restriction, gitcvs
+access still needs to be enabled by the `gitcvs.enabled` config option
+unless '--export-all' was given, too.
+
+
 DESCRIPTION
 -----------
 
git-cvsserver.perl +73 -6

107 lines not on this page · raw message

t/t9400-git-cvsserver-server.sh +28 -0
index 41dcf64..392f890 100755
@@ -143,6 +143,34 @@ test_expect_success 'req_Root failure (conflicting roots)' \
   'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
    tail log | grep -q "^error 1 Conflicting roots specified$"'
 
+test_expect_success 'req_Root (strict paths)' \
+  'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
+   tail -n1 log | grep -q "^I LOVE YOU$"'
+
+test_expect_failure 'req_Root failure (strict-paths)' \
+  'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1'
+
+test_expect_success 'req_Root (w/o strict-paths)' \
+  'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
+   tail -n1 log | grep -q "^I LOVE YOU$"'
+
+test_expect_failure 'req_Root failure (w/o strict-paths)' \
+  'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
+
+cat >request-base  <<EOF
+BEGIN AUTH REQUEST
+/gitcvs.git
+anonymous
+
+END AUTH REQUEST
+EOF
+
+test_expect_success 'req_Root (base-path)' \
+  'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
+   tail -n1 log | grep -q "^I LOVE YOU$"'
+
+test_expect_failure 'req_Root failure (base-path)' \
+  'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
 
 #--------------
 # CONFIG TESTS
Signature · 1 line
1.5.2.1
#2 lore raw

Re: [PATCH] cvsserver: Add some useful commandline options

Quoted 2 lines · Frank Lichtenheld

Make git-cvsserver understand some options inspired by git-daemon, namely --base-path, --export-all, --strict-paths.

Note that this patch doesn't actually implement --export-all ... Which I would have caught if I implemented a test for it, which I also didn't do...

Will send a fix somewhen in the next days.

Gruesse,

Signature · 2 lines
Frank Lichtenheld <[email protected]>
http://www.djpig.de/
#3 lore raw

PATCH 1/1 cvsserver: Let --base-path and pserver get along just fine

In reply to Frank Lichtenheld

Embarassing bug number one in my options patch.

Since the code for --base-path support rewrote the cvsroot value after comparing it with a possible existing value (i.e. from pserver authentication) the check always failed.

---
 git-cvsserver.perl              |   10 ++++++----
 t/t9400-git-cvsserver-server.sh |    1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

I can also squash these two fix-ups into the previous commit if preferred.

git-cvsserver.perl +6 -4
index 9fbd9db..f78afe8 100755
@@ -212,15 +212,17 @@ sub req_Root
 	return 0;
     }
 
+    my $cvsroot = $state->{'base-path'} || '';
+    $cvsroot =~ s#/+$##;
+    $cvsroot .= $data;
+
     if ($state->{CVSROOT}
-	&& ($state->{CVSROOT} ne $data)) {
+	&& ($state->{CVSROOT} ne $cvsroot)) {
 	print "error 1 Conflicting roots specified\n";
 	return 0;
     }
 
-    $state->{CVSROOT} = $state->{'base-path'} || '';
-    $state->{CVSROOT} =~ s#/+$##;
-    $state->{CVSROOT} .= $data;
+    $state->{CVSROOT} = $cvsroot;
 
     $ENV{GIT_DIR} = $state->{CVSROOT} . "/";
 
t/t9400-git-cvsserver-server.sh +1 -0
index 392f890..9b69452 100755
@@ -163,6 +163,7 @@ BEGIN AUTH REQUEST
 anonymous
 
 END AUTH REQUEST
+Root /gitcvs.git
 EOF
 
 test_expect_success 'req_Root (base-path)' \
Signature · 1 line
1.5.2.1
#4 lore raw

PATCH 1/1 cvsserver: Actually implement --export-all

Embarrassing bug number two in my options patch.

Also enforce that --export-all is only ever used together with an explicit whitelist. Otherwise people might export every git repository on the whole system without realising.

---
 Documentation/git-cvsserver.txt |    3 ++-
 git-cvsserver.perl              |    8 +++++++-
 t/t9400-git-cvsserver-server.sh |   16 ++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
Documentation/git-cvsserver.txt +2 -1
index 6d1e311..60d0bcf 100644
@@ -38,7 +38,8 @@ Prepend 'path' to requested CVSROOT
 Don't allow recursing into subdirectories
 
 --export-all::
-Don't check for `gitcvs.enabled` in config
+Don't check for `gitcvs.enabled` in config. You also have to specify a list
+of allowed directories (see below) if you want to use this option.
 
 --version, -V::
 Print version information and exit
git-cvsserver.perl +7 -1
index f78afe8..5cbf27e 100755
@@ -130,6 +130,11 @@ if (@ARGV) {
 # everything else is a directory
 $state->{allowed_roots} = [ @ARGV ];
 
+# don't export the whole system unless the users requests it
+if ($state->{'export-all'} && !@{$state->{allowed_roots}}) {
+    die "--export-all can only be used together with an explicit whitelist\n";
+}
+
 # if we are called with a pserver argument,
 # deal with the authentication cat before entering the
 # main loop
@@ -276,7 +281,8 @@ sub req_Root
 
     my $enabled = ($cfg->{gitcvs}{$state->{method}}{enabled}
 		   || $cfg->{gitcvs}{enabled});
-    unless ($enabled && $enabled =~ /^\s*(1|true|yes)\s*$/i) {
+    unless ($state->{'export-all'} ||
+	    ($enabled && $enabled =~ /^\s*(1|true|yes)\s*$/i)) {
         print "E GITCVS emulation needs to be enabled on this repo\n";
         print "E the repo config file needs a [gitcvs] section added, and the parameter 'enabled' set to 1\n";
         print "E \n";
t/t9400-git-cvsserver-server.sh +16 -0
index 9b69452..b442b5d 100755
@@ -173,6 +173,22 @@ test_expect_success 'req_Root (base-path)' \
 test_expect_failure 'req_Root failure (base-path)' \
   'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
 
+GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
+
+test_expect_success 'req_Root (export-all)' \
+  'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
+   tail -n1 log | grep -q "^I LOVE YOU$"'
+
+test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
+  'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1
+   || false'
+
+test_expect_success 'req_Root (everything together)' \
+  'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
+   tail -n1 log | grep -q "^I LOVE YOU$"'
+
+GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
+
 #--------------
 # CONFIG TESTS
 #--------------
Signature · 1 line
1.5.2.1
#5 lore raw

Re: [PATCH] cvsserver: Actually implement --export-all

Frank Lichtenheld, Fri, Jun 15, 2007 03:01:53 +0200:

Review

Quoted 3 lines
(quoted diff) +3 -0
+test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
+  'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1
+   || false'

This does not work, at least for bash in current Ubuntu:

    GNU bash, version 3.2.13(1)-release

You have to put "||" on the previous line:

t/t9400-git-cvsserver-server.sh +2 -2
index b442b5d..0331770 100755
@@ -180,8 +180,8 @@ test_expect_success 'req_Root (export-all)' \
    tail -n1 log | grep -q "^I LOVE YOU$"'
 
 test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
-  'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1
-   || false'
+  'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 ||
+   false'
 
 test_expect_success 'req_Root (everything together)' \
   'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&