# [PATCH] gitweb: escape link body in format_ref_marker

4 messages from 2016-07-29 to 2016-08-02. Participants: Andreas Brauchli, Jakub Narębski, Junio C Hamano.
Thread: https://gitlist.dev/t/42961

## Andreas Brauchli, 2016-07-29 14:49

Subject: [PATCH] gitweb: escape link body in format_ref_marker
Message-ID: <CABnoAVcUbmvZbu7ZiEUWtq_2P6RQLVnJx1a-PiLW-r8uWQ+5vw@mail.gmail.com>
URL: https://gitlist.dev/e/CABnoAVcUbmvZbu7ZiEUWtq_2P6RQLVnJx1a-PiLW-r8uWQ%2B5vw%40mail.gmail.com

```
Fix a case where an html link can be generated from unescaped input
resulting in invalid strict xhtml or potentially injected code.

An overview of a repo with a tag "1.0.0&0.0.1" would previously result
in an unescaped amperstand in the link body.

Signed-off-by: Andreas Brauchli <a.brauchli@elementarea.net>
---
 gitweb/gitweb.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2fddf75..33d701d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2090,7 +2090,7 @@ sub format_ref_marker {
                                -href => href(
                                        action=>$dest_action,
                                        hash=>$dest
-                               )}, $name);
+                               )}, esc_html($name));

                        $markers .= " <span
class=\"".esc_attr($class)."\" title=\"".esc_attr($ref)."\">" .
                                $link . "</span>";
-- 
2.7.4

```

## Jakub Narębski, 2016-07-30 17:46

Subject: Re: [PATCH] gitweb: escape link body in format_ref_marker
Message-ID: <51785fbd-6858-c9b2-7f59-eaf7bd3ea394@gmail.com>
URL: https://gitlist.dev/e/51785fbd-6858-c9b2-7f59-eaf7bd3ea394%40gmail.com
In-Reply-To: <CABnoAVcUbmvZbu7ZiEUWtq_2P6RQLVnJx1a-PiLW-r8uWQ+5vw@mail.gmail.com>

```
W dniu 29.07.2016 o 16:49, Andreas Brauchli pisze:
> Fix a case where an html link can be generated from unescaped input
> resulting in invalid strict xhtml or potentially injected code.
> 
> An overview of a repo with a tag "1.0.0&0.0.1" would previously result
> in an unescaped amperstand in the link body.

s/amperstand/ampersand/
        ^---------------- [ spurious 't' ]

Unescaped ampersand would cause trouble if gitweb output is in XHTML
mode, as some web browsers are strict about validating XML, and do not
display anything (note: this detail is unnecessary in the commit
message).

I guess that "1.0.0&0.0.1" tags are something encountered in real
repositories, while "1<b>2" would be just something evil...

> 
> Signed-off-by: Andreas Brauchli <a.brauchli@elementarea.net>

Good catch!

Acked-by: Jakub Narębski <jnareb@gmail.com>

> ---
>  gitweb/gitweb.perl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 2fddf75..33d701d 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -2090,7 +2090,7 @@ sub format_ref_marker {
>                                 -href => href(
>                                         action=>$dest_action,
>                                         hash=>$dest
> -                               )}, $name);
> +                               )}, esc_html($name));
> 
>                         $markers .= " <span
> class=\"".esc_attr($class)."\" title=\"".esc_attr($ref)."\">" .
>                                 $link . "</span>";
> 


```

## Junio C Hamano, 2016-08-01 19:54

Subject: Re: [PATCH] gitweb: escape link body in format_ref_marker
Message-ID: <xmqq37mojme2.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq37mojme2.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <51785fbd-6858-c9b2-7f59-eaf7bd3ea394@gmail.com>

```
Jakub Narębski <jnareb@gmail.com> writes:

> Good catch!
>
> Acked-by: Jakub Narębski <jnareb@gmail.com>

Sigh; the contents may be good but the patch is unusable as-is
because of heavy whitespace damage.

I'll fix it up.  Thanks, both.

>> ---
>>  gitweb/gitweb.perl | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index 2fddf75..33d701d 100755
>> --- a/gitweb/gitweb.perl
>> +++ b/gitweb/gitweb.perl
>> @@ -2090,7 +2090,7 @@ sub format_ref_marker {
>>                                 -href => href(
>>                                         action=>$dest_action,
>>                                         hash=>$dest
>> -                               )}, $name);
>> +                               )}, esc_html($name));
>> 
>>                         $markers .= " <span
>> class=\"".esc_attr($class)."\" title=\"".esc_attr($ref)."\">" .
>>                                 $link . "</span>";
>> 

```

## Andreas Brauchli, 2016-08-02 10:25

Subject: Re: [PATCH] gitweb: escape link body in format_ref_marker
Message-ID: <CABnoAVemROJ7YN22gthqoCcDa8JsAJuQ9v+oD+-vw7ocyfHAeg@mail.gmail.com>
URL: https://gitlist.dev/e/CABnoAVemROJ7YN22gthqoCcDa8JsAJuQ9v%2BoD%2B-vw7ocyfHAeg%40mail.gmail.com
In-Reply-To: <xmqq37mojme2.fsf@gitster.mtv.corp.google.com>

```
On Mon, Aug 1, 2016 at 9:54 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Jakub Narębski <jnareb@gmail.com> writes:
>
>> Good catch!
>>
>> Acked-by: Jakub Narębski <jnareb@gmail.com>
>
> Sigh; the contents may be good but the patch is unusable as-is
> because of heavy whitespace damage.
>
> I'll fix it up.  Thanks, both.
My apologies for that, it seems that gmail doesn't do tabs.
I resubmitted the PR as #283 on GitHub along with Jakub's Ack and
fixed the typo he pointed out in the commit message

https://github.com/git/git/pull/283

Kind regards
andreas

>
>>> ---
>>>  gitweb/gitweb.perl | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>>> index 2fddf75..33d701d 100755
>>> --- a/gitweb/gitweb.perl
>>> +++ b/gitweb/gitweb.perl
>>> @@ -2090,7 +2090,7 @@ sub format_ref_marker {
>>>                                 -href => href(
>>>                                         action=>$dest_action,
>>>                                         hash=>$dest
>>> -                               )}, $name);
>>> +                               )}, esc_html($name));
>>>
>>>                         $markers .= " <span
>>> class=\"".esc_attr($class)."\" title=\"".esc_attr($ref)."\">" .
>>>                                 $link . "</span>";
>>>

```
