• J
    daemon: sanitize incoming virtual hostname · b4853730
    Jeff King 提交于
    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: NJeff King <peff@peff.net>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    b4853730
daemon.c 31.1 KB