From 7f9ad99b8eb43d2102a383dbbaa8f0c0832bd423 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 16 Oct 2026 06:33:14 -1000 Subject: Answer 404 for any path below the about page The about page served every file beside the readme as a page of its own, through the about filter, and answered 200 for directories and missing files alike. Images it passed through came from the root of the default branch whatever the readme's own directory and ref. A readme on disk exposed its whole directory this way. --- source/cmd.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'source/cmd.c') diff --git a/source/cmd.c b/source/cmd.c index 49c1eb4..08de123 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -34,39 +34,28 @@ static void head_fn(void) static void about_fn(void) { - char *currenturl, *query, *redirect; - size_t path_info_len; + char *query, *summary; + // The page shows the readme alone, and the readme's links lead into + // the tree, so nothing lives below it. + if (ctx.qry.path) { + cgit_print_error_page(404, "Not Found", "Not found"); + return; + } if (!ctx.repo) { cgit_print_site_readme(); return; } - - // The about page resolves relative links against its own URL, so it - // only works with a trailing slash. The branch and the rest of the - // query travel along with either redirect. - path_info_len = ctx.env.path_info ? strlen(ctx.env.path_info) : 0; - if (!ctx.qry.path && - (!ctx.qry.url || !*ctx.qry.url || ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') && - (!path_info_len || ctx.env.path_info[path_info_len - 1] != '/')) { - currenturl = cgit_currenturl(); - query = cgit_currentquery(); - redirect = cgit_fmtalloc("%s/", currenturl); - cgit_redirect(redirect, query, true); - free(currenturl); - free(query); - free(redirect); - } else if (ctx.repo->readme.nr) { - cgit_print_repo_readme(ctx.qry.path); - } else { - currenturl = cgit_currenturl(); - query = cgit_currentquery(); - redirect = cgit_fmtalloc("%s../", currenturl); - cgit_redirect(redirect, query, false); - free(currenturl); - free(query); - free(redirect); + if (ctx.repo->readme.nr) { + cgit_print_repo_readme(); + return; } + // The branch and the rest of the query travel along to the summary. + query = cgit_currentquery(); + summary = cgit_repourl(ctx.repo->url); + cgit_redirect(summary, query, false); + free(query); + free(summary); } static void atom_fn(void) -- cgit