Gitweb URL escapes in query string

346 Views Asked by At

My gitweb installation works so far, but all generated links that include a querystring, e.g.

host/gitweb?p=somepath&a=summary

are somehow malformed. First, the ampersand is replaced by a semicolon. When inspecting the html, the link looks like

host/gitweb?p=somepath;a=summary

When klicking the link, the browser escapes the ';' to '%3b', so the url sent to the server looks like

host/gitweb?p=somepath%3ba=summary

The gitweb.cgi does not parse this and displays a 404 error page. When I replace the '%3b' with a ';' or a '&', everything works fine.

How can this be fixed on the server-side?

So far, I have tried to find the line producing the ';' in the urls, which is line 1457

$href .= "?" . join(';', @result) if scalar @result;

replacing the ';' by '&' gives me a malformed xhtml in the browser. Replacing it by '&' forces the browser again to escape the ';' which produces broken urls again.

The issue is kind of hidden (I can view the repositories), if I set the option

$feature{'pathinfo'}{'default'} = [1];

in the gitweb.conf file, but unfortunately, folders containing multiple repositories cannot be displayed, since the respective link uses some query-parameters.

2

There are 2 best solutions below

1
Shaka Flex On

You do not encoded or decoded the query string as a hole. The param name and value must be encoded and decoded individually and the delimiters of the query string i.e..

= ; &

never get URL encoded or decoded.

You can check the server environment variable $ENV{REQUEST_URI} to see if the server did receive the information encoded like you said. If the browser is sending it then that is the problem and there is nothing you can do in your Perl code to fix that. Because it will just cause more problems down the road in your Perl code.

1
quantenquatsch On

I somehow solved the problem using a rewrite rule in apache:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^a=project_list%3bpf=(.*)$
RewriteRule (.*) $1?a=project_list;pf=%1 [QSA]

It only works for the project list with a specified path with the pathinfo feature enabled. A holistic approach would be to search for all possible query parameters and to replace them all.

However, this solution is not satisfying, since it does not fix the actual problem of the weird url escaping of gitweb.