commit d4278f033868731068d1423ea050234901387f9d9a26d59c4d5c76895a5fab72 from: Stefan Sperling date: Mon Jul 20 11:37:57 2026 UTC restore gotwebd's ability to redirect with HTTP status codes This is needed to keep our tests passing because w3m does not work as required in our test scripts when the HTML body refresh redirect method is used. testing + ok jtt@ commit - 7e0628b4fbe442954b4e75dc0b7dde1f91d5f387ac86ba40bc120225d34932d9 commit + d4278f033868731068d1423ea050234901387f9d9a26d59c4d5c76895a5fab72 blob - 8824f9213bfb272ea5664994cb5709d50e94113bc23eedf4d6c3329c90818d2a blob + 665ce020a5e96ea761937ca13107d51932deda5d3d1c5d759f26b706b8d2445b --- gotsysd/gotsysd.conf.5 +++ gotsysd/gotsysd.conf.5 @@ -359,6 +359,48 @@ weblogin command via other means. .It Ic login hint port Ar number Sets the SSH port number displayed in login hints which are shown on the error page if authentication has failed. +.It Ic redirect_method Ar method +Set the +.Ar method +used by +.Xr gotwebd 8 +when redirecting clients to another page, such as from the login page +to the summary page. +.Pp +The available methods are: +.Bl -tag -width Ds +.It page_refresh +Send HTTP response status code 200 (success) and serve a +.Dv meta +tag in the HTML response body with the +.Dv http-equiv +attribute set to +.Dq refresh +and a new URL in the +.Dv url +attribute. +.Pp +This method is the default and provides good browser compatibility overall. +.pp +This method can get in the way of scripts trying to navigate through a +.Xr gotsh 1 +.Cm weblogin +link, which is usually desirable, but not always. +.It status_code +Send HTTP response status code 307 (redirect) with a target URL in HTTP +headers and with an empty response body. +.Pp +This method generally works as expected. +In some situations browsers fail to follow the redirect and display the +redirecting page instead. +For example, +.Xr gotsh 1 +.Cm weblogin +links have been known to fail loading the summary page if the redirecting +link is opened by an external application asking Mozilla Firefox to open +the login link, even though the redirect is followed as expected when +the login link is visited via the browser's address bar. +.El .It Ic user Ar name Set the .Ar user blob - 63765fdf80169fd36e5e5f8bddcb9d6ce50c40bdba8db1d4403a54276dbd482e blob + 5cc79791938726d4a4744617b44443ae1f117e6fd472e133fc95539764871ee9 --- gotsysd/gotsysd.h +++ gotsysd/gotsysd.h @@ -107,6 +107,11 @@ enum gotsysd_web_auth_config { GOTSYSD_WEB_AUTH_INSECURE = 0x0f7f7f00 }; +enum gotsysd_web_redirect_method { + GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH, + GOTSYSD_WEB_REDIRECT_METHOD_STATUS_CODE +}; + enum gotsysd_web_address_family { GOTSYSD_LISTEN_ADDR_UNIX = 0, GOTSYSD_LISTEN_ADDR_INET, @@ -168,6 +173,7 @@ struct gotsysd_web_config { char login_hint_user[MAX_IDENTIFIER_SIZE]; char login_hint_port[8]; + enum gotsysd_web_redirect_method redirect_method; enum gotsysd_web_auth_config auth_config; struct gotsysd_web_addresslist listen_addrs; struct gotsysd_web_serverlist servers; blob - 47e8149e1f629f7a94a65335545503d20982da0ffe9af240b7d57ef7f934a0e2 blob + 29f186d581971e23760620cfdabe086bd28686305d35123fa5f3ab57b31173bf --- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c +++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c @@ -1368,6 +1368,27 @@ write_gotwebd_conf(void) } + switch (webcfg.redirect_method) { + case GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH: + ret = dprintf(fd, "redirect_method page_refresh\n"); + if (ret == -1) + return got_error_from_errno2("dprintf", path); + if (ret != 29) { + return got_error_fmt(GOT_ERR_IO, "short write to %s", + path); + } + break; + case GOTSYSD_WEB_REDIRECT_METHOD_STATUS_CODE: + ret = dprintf(fd, "redirect_method status_code\n"); + if (ret == -1) + return got_error_from_errno2("dprintf", path); + if (ret != 28) { + return got_error_fmt(GOT_ERR_IO, "short write to %s", + path); + } + break; + } + switch (webcfg.auth_config) { case GOTSYSD_WEB_AUTH_UNSET: break; blob - 1840729815167cee388cf8d878cfca9e88ae239209c607eb8b5bed469a5e0889 blob + 2602f09c74aec036807a1f1d9d9032c66d9fa100aeef421a8ea58ee5ed5c1f34 --- gotsysd/parse.y +++ gotsysd/parse.y @@ -119,6 +119,7 @@ typedef struct { %token HTDOCS INSECURE PORT PREFORK SERVER NAME SOCKET WWW HINT SHOW_REPO_AGE %token ERROR LISTEN ON USER GOTD DIRECTORY REPOSITORY UID RANGE PERMIT %token DENY RO RW WEB GOTSYSD_LOGIN ENABLE DISABLE HIDE REPOSITORIES +%token REDIRECT_METHOD PAGE_REFRESH STATUS_CODE %token STRING %token NUMBER @@ -604,6 +605,14 @@ webopts1 : GOTSYSD_CONTROL SOCKET STRING { } gotsysd->web.auth_config = GOTSYSD_WEB_AUTH_INSECURE; } + | REDIRECT_METHOD PAGE_REFRESH { + gotsysd->web.redirect_method = + GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH; + } + | REDIRECT_METHOD STATUS_CODE { + gotsysd->web.redirect_method = + GOTSYSD_WEB_REDIRECT_METHOD_STATUS_CODE; + } ; webopts2 : webopts2 webopts1 nl @@ -781,10 +790,12 @@ lookup(char *s) { "login", GOTSYSD_LOGIN }, { "name", NAME }, { "on", ON }, + { "page_refresh", PAGE_REFRESH }, { "permit", PERMIT }, { "port", PORT }, { "prefork", PREFORK }, { "range", RANGE }, + { "redirect_method", REDIRECT_METHOD }, { "repositories", REPOSITORIES }, { "repository", REPOSITORY }, { "ro", RO }, @@ -792,6 +803,7 @@ lookup(char *s) { "server", SERVER }, { "show_repo_age", SHOW_REPO_AGE }, { "socket", SOCKET }, + { "status_code", STATUS_CODE }, { "uid", UID }, { "user", USER }, { "web", WEB }, blob - 26b70536e74a0d008e6fa8d7536140c5cff9a0d4a34b498693a4da18bb4dd8af blob + 168b2171ffb0ca52fa31c0a3c3242dbd78195e03bab389605a559fee2514a607 --- gotwebd/auth.c +++ gotwebd/auth.c @@ -291,6 +291,7 @@ do_login(struct request *c) char *token = NULL; const char *identifier = NULL; const time_t validity = 24 * 60 * 60; /* 1 day */ + struct gotweb_url url; struct gotwebd_repo *repo; int r; @@ -397,9 +398,19 @@ logged_in: goto err; } - if (gotweb_reply(c, 200, "text/html", NULL) == -1) - return; - gotweb_render_refresh_redirect(c->tp); + switch (srv->redirect_method) { + case GOTWEBD_REDIRECT_METHOD_UNSET: + case GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH: + if (gotweb_reply(c, 200, "text/html", NULL) == -1) + return; + gotweb_render_refresh_redirect(c->tp); + break; + case GOTWEBD_REDIRECT_METHOD_STATUS_CODE: + memset(&url, 0, sizeof(url)); + url.action = INDEX; + gotweb_reply(c, 307, "text/html", &url); + break; + } return; blob - 0eb76c0205979ce822876db213d9fd8c17e7abd3ff360f75e7361f2cd03c4df9 blob + 7551b93a0d85dd27c717c5776f714d5c64d67337d30838b128f19294f21b8e7f --- gotwebd/config.c +++ gotwebd/config.c @@ -58,6 +58,8 @@ config_init(struct gotwebd *env) strlcpy(env->htdocs_path, D_HTDOCS_PATH, sizeof(env->htdocs_path)); strlcpy(env->gotweb_url_root, "/", sizeof(env->gotweb_url_root)); + env->redirect_method = D_REDIRECT_METHOD; + env->prefork = GOTWEBD_NUMPROC; TAILQ_INIT(&env->servers); TAILQ_INIT(&env->sockets); blob - e773a2271e42e904099db29aca4ed0627c6084a5498ab20ef97188a45bee441b blob + 0a87481cb50a10ed9748985d09ed194a671a6026ffef432942b83c583a9690b6 --- gotwebd/gotwebd.conf.5 +++ gotwebd/gotwebd.conf.5 @@ -111,6 +111,48 @@ are served directly from .Xr httpd 8 . .Pp This setting can also be configured on a per-server basis. +.It Ic redirect_method Ar method +Set the +.Ar method +used by +.Xr gotwebd 8 +when redirecting clients to another page, such as from the login page +to the summary page. +.Pp +The available methods are: +.Bl -tag -width Ds +.It page_refresh +Send HTTP response status code 200 (success) and serve a +.Dv meta +tag in the HTML response body with the +.Dv http-equiv +attribute set to +.Dq refresh +and a new URL in the +.Dv url +attribute. +.Pp +This method is the default and provides good browser compatibility overall. +.pp +This method can get in the way of scripts trying to navigate through a +.Xr gotsh 1 +.Cm weblogin +link, which is usually desirable, but not always. +.It status_code +Send HTTP response status code 307 (redirect) with a target URL in HTTP +headers and with an empty response body. +.Pp +This method generally works as expected. +In some situations browsers fail to follow the redirect and display the +redirecting page instead. +For example, +.Xr gotsh 1 +.Cm weblogin +links have been known to fail loading the summary page if the redirecting +link is opened by an external application asking Mozilla Firefox to open +the login link, even though the redirect is followed as expected when +the login link is visited via the browser's address bar. +.El .It Ic repos_url_path Ar path Sets the URL path under which Git repositories will be displayed by .Xr gotwebd 8 . blob - baedf7154aaebcea7787e9cbb4ba372e01f7885f946c965e5a07b85cd88b3cd5 blob + 95317c0793464be5ce6e837738dda479416609d6250fed5afacf36425b883aa7 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -96,6 +96,7 @@ #define D_MAXSLCOMMDISP 10 #define D_MAXCOMMITDISP 25 #define D_MAXSLTAGDISP 3 +#define D_REDIRECT_METHOD GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH #define BUF 8192 @@ -137,6 +138,12 @@ struct got_blob_object; struct got_tree_entry; struct got_reflist_head; +enum gotwebd_redirect_method { + GOTWEBD_REDIRECT_METHOD_UNSET, + GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH, + GOTWEBD_REDIRECT_METHOD_STATUS_CODE, +}; + enum gotwebd_proc_type { GOTWEBD_PROC_PARENT, GOTWEBD_PROC_SOCKETS, @@ -463,6 +470,8 @@ struct server { enum gotwebd_auth_config auth_config; struct gotwebd_access_rule_list access_rules; + enum gotwebd_redirect_method redirect_method; + struct gotwebd_repolist repos; struct got_pathlist_head websites; }; @@ -547,6 +556,8 @@ struct gotwebd { char login_hint_user[MAX_IDENTIFIER_SIZE]; char login_hint_port[GOTWEBD_MAXPORT]; + + enum gotwebd_redirect_method redirect_method; }; /* blob - 9688d9e288f654ceeb75559a3266938ca90733666bae766c6e58a93964f64c33 blob + c8c047ca1f3587958b6505e3da87d3768b579f40f66a9148857ad48ca80abd3f --- gotwebd/parse.y +++ gotwebd/parse.y @@ -158,6 +158,7 @@ mediatype_ok(const char *s) %token WEBSITE PATH BRANCH REPOS_URL_PATH DESCRIPTION %token TYPES INCLUDE GOTWEBD_CONTROL %token SSH_HOSTKEY_ECDSA SSH_HOSTKEY_ED25519 SSH_HOSTKEY_RSA +%token REDIRECT_METHOD STATUS_CODE PAGE_REFRESH %token STRING %token NUMBER @@ -562,6 +563,14 @@ main : PREFORK NUMBER { free($2); } + | REDIRECT_METHOD STATUS_CODE { + gotwebd->redirect_method = + GOTWEBD_REDIRECT_METHOD_STATUS_CODE; + } + | REDIRECT_METHOD PAGE_REFRESH { + gotwebd->redirect_method = + GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH; + } ; server : SERVER STRING { @@ -1309,10 +1318,12 @@ lookup(char *s) { "max_commits_display", MAX_COMMITS_DISPLAY }, { "max_repos_display", MAX_REPOS_DISPLAY }, { "on", ON }, + { "page_refresh", PAGE_REFRESH }, { "path", PATH }, { "permit", PERMIT }, { "port", PORT }, { "prefork", PREFORK }, + { "redirect_method", REDIRECT_METHOD }, { "repos_path", REPOS_PATH }, { "repos_url_path", REPOS_URL_PATH }, { "repositories", REPOSITORIES }, @@ -1331,6 +1342,7 @@ lookup(char *s) { "ssh_hostkey_ecdsa", SSH_HOSTKEY_ECDSA}, { "ssh_hostkey_ed25519", SSH_HOSTKEY_ED25519}, { "ssh_hostkey_rsa", SSH_HOSTKEY_RSA}, + { "status_code", STATUS_CODE }, { "summary_commits_display", SUMMARY_COMMITS_DISPLAY }, { "summary_tags_display", SUMMARY_TAGS_DISPLAY }, { "types", TYPES }, @@ -1979,6 +1991,19 @@ parse_config(const char *filename, struct gotwebd *env return -1; } } + + /* + * The redirect method is not configurable on a per-server + * basis in gotwebd.conf so currently it will always be UNSET. + * + * And gotwebd child processes will not see fields that are + * set in our global env, unless we copy them across manually. + * For now, let this field ride along in per-server config. + * Maybe it will become configurable on a per-server basis + * eventually, in which case this code remains correct. + */ + if (srv->redirect_method == GOTWEBD_REDIRECT_METHOD_UNSET) + srv->redirect_method = env->redirect_method; } TAILQ_FOREACH(srv, &env->servers, entry) { @@ -2100,6 +2125,8 @@ conf_new_server(const char *name) TAILQ_INIT(&srv->repos); RB_INIT(&srv->websites); + srv->redirect_method = GOTWEBD_REDIRECT_METHOD_UNSET; + TAILQ_INSERT_TAIL(&gotwebd->servers, srv, entry); return srv; blob - 08a01601508057ed5a38b2da6fe49db5d1a49bf56a5be5ad7d6e5277d65a5392 blob + 00824b174c59b4eb0cbb7c0af3268eede16687bfe1a0bd51f9133f8e342bb40b --- lib/gotsys_imsg.c +++ lib/gotsys_imsg.c @@ -1018,6 +1018,7 @@ gotsysd_web_config_init(struct gotsysd_web_config *web TAILQ_INIT(&webcfg->listen_addrs); STAILQ_INIT(&webcfg->servers); webcfg->auth_config = GOTSYSD_WEB_AUTH_UNSET; + webcfg->redirect_method = GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH; } const struct got_error * blob - 6fd1cbe4540d20332ee16bcae92b69ee52ff0526e8214571736d227180c6e88e blob + 0aa2fe071737a49dbfe329c62750867b57620d176fd66e0ca17cce641f97ae25 --- regress/gotsysd/Makefile +++ regress/gotsysd/Makefile @@ -202,6 +202,7 @@ ${GOTSYSD_CONF}: @${UNPRIV} "printf '\tprefork 1\n' >> $@" @${UNPRIV} "printf '\tenable authentication insecure\n' >> $@" @${UNPRIV} "printf '\tlogin hint user \"${GOTSYSD_TEST_USER}\"\n' >> $@" + @${UNPRIV} "printf '\tredirect_method status_code\n' >> $@" @${UNPRIV} "printf '\tlisten on socket \\\"/var/www/run/gotweb.sock\\\"\n' >> $@" @${UNPRIV} "printf '\tlisten on 127.0.0.1 port 9000\n' >> $@" @${UNPRIV} "printf '\tlisten on ::1 port 9000\n' >> $@"