fix(cgi): match pages host via SERVER_NAME fallback
CGI servers are not required to set HTTP_HOST. Fall back to SERVER_NAME:SERVER_PORT, omitting 80 and 443, and document the pages host contract. Also omit the redundant Status header on 200 file responses. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
This commit is contained in:
1 parent
802572bae9
commit
a5bc30bfaa
2 files changed
+28
-7
No files matched your search
@@ -111,12 +111,14 @@ GOTEA_PAGES_ALLOW=/etc/gotea/pages.allow \
|
||||
./cgi/gotea-cgi
|
||||
```
|
||||
|
||||
`GOTEA_PAGES_HOST` must match `HTTP_HOST` exactly; other hosts get 404. Only
|
||||
allowlisted repositories are served, and the pages host never exposes the main
|
||||
UI. Keep private repositories out of the allowlist: the publisher has no
|
||||
visibility check. Optional publisher settings are `GOTEA_PAGES_BRANCH` (default
|
||||
`pages`), `GOTEA_PAGES_THEME`, `GOTEA_PAGES_SUBDIR`, and `GOTEA_PAGES_STRICT=1`
|
||||
to fail the push when publishing fails.
|
||||
`GOTEA_PAGES_HOST` must match `HTTP_HOST` exactly. Without `HTTP_HOST`, the CGI
|
||||
falls back to `SERVER_NAME:SERVER_PORT` (ports 80 and 443 are omitted). Other
|
||||
hosts get 404. Only allowlisted repositories are served, and the pages host
|
||||
never exposes the main UI. Keep private repositories out of the allowlist: the
|
||||
publisher has no visibility check. Optional publisher settings are
|
||||
`GOTEA_PAGES_BRANCH` (default `pages`), `GOTEA_PAGES_THEME`,
|
||||
`GOTEA_PAGES_SUBDIR`, and `GOTEA_PAGES_STRICT=1` to fail the push when
|
||||
publishing fails.
|
||||
|
||||
bb is vendored under `third_party/bb` (MIT, upstream commit in
|
||||
`third_party/bb/NOTICE`), so a checkout builds without an installed bb.
|
||||
|
||||
+20
-1
@@ -1862,6 +1862,24 @@ done:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
request_host(char *buf, size_t len)
|
||||
{
|
||||
const char *host = getenv("HTTP_HOST");
|
||||
const char *name, *port;
|
||||
|
||||
if (host != NULL && *host != '\0')
|
||||
return host;
|
||||
name = env_or("SERVER_NAME", "");
|
||||
port = getenv("SERVER_PORT");
|
||||
if (port != NULL && *port != '\0' && strcmp(port, "80") != 0 &&
|
||||
strcmp(port, "443") != 0 && strchr(name, ':') == NULL) {
|
||||
snprintf(buf, len, "%s:%s", name, port);
|
||||
return buf;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static int
|
||||
is_action(const char *s)
|
||||
{
|
||||
@@ -1907,6 +1925,7 @@ main(void)
|
||||
{
|
||||
const char *method, *decoded_env, *palette_file;
|
||||
const char *pages_host, *http_host;
|
||||
char hostbuf[PATHBUF];
|
||||
char *decoded = NULL, *repo_path = NULL, *repo_name = NULL;
|
||||
char *path = NULL;
|
||||
struct path p;
|
||||
@@ -1936,7 +1955,7 @@ main(void)
|
||||
|
||||
pages_host = getenv("GOTEA_PAGES_HOST");
|
||||
if (pages_host != NULL && *pages_host != '\0') {
|
||||
http_host = env_or("HTTP_HOST", env_or("SERVER_NAME", ""));
|
||||
http_host = request_host(hostbuf, sizeof(hostbuf));
|
||||
if (strcasecmp(http_host, pages_host) != 0) {
|
||||
b_init(&body);
|
||||
g_pages_mode = 1;
|
||||
|
||||
Reference in new issue
Block a user