]> git.ipfire.org Git - thirdparty/git.git/commit - daemon.c
daemon: sanitize incoming virtual hostname
authorJeff King <peff@peff.net>
Tue, 17 Feb 2015 19:09:24 +0000 (14:09 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Feb 2015 21:15:30 +0000 (13:15 -0800)
commitb48537305229d1a4f25633f71941ee52d2582017
treeddabe33825474779b662a1bf43eb85b24d830013
parent5248f2dd4fe763ef9d1267f50481deee36ee57c1
daemon: sanitize incoming virtual hostname

We use the daemon_avoid_alias function to make sure that the
pathname the user gives us is sane. However, after applying
that check, we might then interpolate the path using a
string given by the server admin, but which may contain more
untrusted data from the client. We should be sure to
sanitize this data, as well.

We cannot use daemon_avoid_alias here, as it is more strict
than we need in requiring a leading '/'. At the same time,
we can be much more strict here. We are interpreting a
hostname, which should not contain slashes or excessive runs
of dots, as those things are not allowed in DNS names.

Note that in addition to cleansing the hostname field, we
must check the "canonical hostname" (%CH) as well as the
port (%P), which we take as a raw string.  For the canonical
hostname, this comes from an actual DNS lookup on the
accessed IP, which makes it a much less likely vector for
problems. But it does not hurt to sanitize it in the same
way. Unfortunately we cannot test this case easily, as it
would involve a custom hostname lookup.

We do not need to check %IP, as it comes straight from
inet_ntop, so must have a sane form.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
daemon.c
t/t5570-git-daemon.sh