/about redirected to /about/

Daniel Reichelt hacking at nachtgeist.net
Thu Aug 13 10:58:27 CEST 2015

Hi Jason,

> Please let me know if this poses any problems.

I'm afraid, it does here:

Requesting a document works, however a request to /cgit/$repo.git/about/ gets
301'd to /cgit/$repo.git/about/ until firefox throws up.

I added some debug printing to cmd.c:about_pre():
static void about_pre(void)
fprintf(stderr, "cmd url is: #%s#\n", ctx.qry.url);
fprintf(stderr, "cmd qryp is: #%s#\n", ctx.qry.path);
        if (ctx.repo && !ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/')
                cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true);

For requesting a document, say cryptsetup.md, it writes
[Thu Aug 13 10:44:25.121565 2015] [cgi:error] [pid 1192] [client ::1:60435]
AH01215: cmd url is: #wiki.git/about#
[Thu Aug 13 10:44:25.121672 2015] [cgi:error] [pid 1192] [client ::1:60435]
AH01215: cmd qryp is: #cryptsetup.md#

For requesting the document listing about/, it writes
==> /var/log/apache2/error-repositories-hacking.log <==
[Thu Aug 13 10:45:46.755487 2015] [cgi:error] [pid 7586] [client ::1:60522]
AH01215: cmd url is: #wiki.git/about#, referer: https://********
[Thu Aug 13 10:45:46.755567 2015] [cgi:error] [pid 7586] [client ::1:60522]
AH01215: cmd qryp is: #(null)#, referer: https://********

As you can see, there's no trailing slash at that point, even when contained in
the http request. So the check for the trailing slash in cmd.c:49 always
triggers the redirect.

Here's a trace of firefox' "Live HTTP headers" for a request to about/:


GET /repositories/cgit/wiki.git/about/ HTTP/1.1
Host: www.*****
User-Agent: Mozilla/5.0[...]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: https://www.*****/repositories/cgit/wiki.git/
Connection: keep-alive

HTTP/1.1 301 Moved
Date: Thu, 13 Aug 2015 08:47:41 GMT
Server: Apache
Location: /repositories/cgit/wiki.git/about/
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
Content-Length: 0
Keep-Alive: timeout=5, max=80
Connection: Keep-Alive

And here's the corresponding entry from apache2's access.log:
::1 - - [13/Aug/2015:10:47:41 +0200] "GET /repositories/cgit/wiki.git/about/
HTTP/1.1" 301 4611 "https://***/repositories/cgit/wiki.git/" "Mozilla/5.0[...]"

Hauler if you need additional info.


More information about the CGit mailing list