Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep the login page out of search indexes
| -rw-r--r-- | source/ui-shared.c | 9 | |
| -rwxr-xr-x | tests/t0505-auth.sh | 14 |
2 files changed, 20 insertions, 3 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index 5e4aec2..cb5e050 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1446,7 +1446,7 @@ static void print_docstart(void) { const struct object_id *pinned; struct string_list_item *item; - const char *desc; + const char *desc, *robots; char *host; if (ctx.cfg.embedded) { @@ -1485,9 +1485,12 @@ static void print_docstart(void) htmlf("<meta name='generator' content='cgit %s'>\n", cgit_version); else html("<meta name='generator' content='cgit'>\n"); - if (ctx.cfg.robots && *ctx.cfg.robots) { + // The login page answers in place of the page asked for, so it must + // not be indexed as that page. + robots = ctx.env.authenticated ? ctx.cfg.robots : "noindex, nofollow"; + if (robots && *robots) { html("<meta name='robots' content='"); - html_attr(ctx.cfg.robots); + html_attr(robots); html("'>\n"); } diff --git a/tests/t0505-auth.sh b/tests/t0505-auth.sh index f7096ca..e9349d4 100755 --- a/tests/t0505-auth.sh +++ b/tests/t0505-auth.sh @@ -102,4 +102,18 @@ test_expect_success 'the login page keeps the repository to itself' ' ! grep "Mallory" tmp ' +# The login page answers in place of whatever page was asked for, so it is +# kept out of a search index, whatever the site allows for its own pages. +test_expect_success 'the login page asks not to be indexed' ' + cgit_rc denyrc "url=authy/log/" >tmp && + grep "^Status: 200" tmp && + grep "<meta name=.robots. content=.noindex, nofollow.>" tmp && + { + echo "robots=" && + cat denyrc + } >norobotsrc && + cgit_rc norobotsrc "url=authy/log/" >tmp && + grep "<meta name=.robots. content=.noindex, nofollow.>" tmp +' + test_done |
