455 Commits
Author SHA1 Message Date
Catherine e4e3a43825 [breaking-change] Refactor handling of project name.
Define a proper abstraction for project names and use it elsewhere in
the codebase.

The character `@` is formally reserved for PR previews from this point,
and any project names using it must be well-formed: contain no more
than a single `@` followed by a positive number.
2026-10-21 18:29:59 +02:00
Catherine caa2895f52 Check validity of URL rewrite rules for non-index projects.
In commit 600c8a7848, we have introduced
an unintentionally breaking change to how redirects are handled, thus
breaking every single-page application deployed to a non-index project.

This cannot be easily fixed due to Codeberg Pages already having a mix
of broken and fixed redirects in manifests without any way to tell them
apart, but we can at least emit a diagnostic for redirects that are
statically known to be broken at deploy time.

See also #273.
2026-10-20 22:28:23 +00:00
Catherine 375e7e15c8 Stabilize feature preview. 2026-10-17 21:27:00 +00:00
Catherine 90c98fbe71 Stabilize feature expiration. 2026-10-17 21:17:10 +00:00
Catherine 1f1c767f33 Stabilize feature absolute-headers. 2026-10-17 21:16:22 +00:00
Catherine 83476d0ad1 [breaking-change] Rename caddy listener to proxy and expose domains.
The listener is no longer only used for Caddy integration; it is now
a general purpose reverse proxy endpoint that can be used with e.g.
Traefik terminating TLS.

Fixes #260.
2026-10-17 22:41:19 +02:00
Catherine 600c8a7848 Fix handling of 2xx/4xx redirects within a project site.
Since the path of the target URL is absolute, we have to cut the project
name off before searching again for the manifest entry.

Fixes #272.
2026-10-17 20:32:18 +00:00
Catherine cdfca73ecf Use our fork of go-redirects.
This also fixes an issue with unparsing bare parameters (not that
this syntax is currently used anywhere).
2026-10-11 01:38:46 +00:00
Catherine a2bee712a2 Rename -repair-storage to -scrub-storage. 2026-10-10 00:36:48 +02:00
Catherine 64a6f249d1 Extend -repair-storage to check consistency of blobs.
This includes:
 * Verifying that the blobs' contents corresponds to their name/hash.
 * Verifying that blob references in manifests and audit records refer
   to blobs that exist and have matching hash.

The action differs by object type:
 * Blobs with mismatching content hash are removed.
 * Manifests referring to nonexistent or invalid blobs are replaced
   with placeholders.
 * Audit records with manifests referring to the same are detached.
   This preserves the audit log in more scenarios.

The check is conservative in that all "recent enough" manifests are
skipped. The repair process is functionally equivalent to a concurrent
GC run; we don't yet have GC, and it's not feasible to implement it as
a prerequisite for this urgently needed feature, so we take an approach
that may require several re-runs in case of very recent data corruption.
2026-10-10 00:36:48 +02:00
Xavier Vello 0d886689ae Gracefully exit audit-server on SIGINT 2026-10-08 19:54:24 +02:00
Xavier VelloandCatherine d833deabf3 Support notifying an audit-server over unix socket (#266)
The audit-server is able to listen on a unix socket, but the client does not support http on unix socket. It's pretty simple to implement in golang, by overriding the socket dialer in a http client.

We could also depend on https://github.com/peterbourgon/unixtransport for a better-tested implementation, but I don't think it's worth the maintenance cost.

Reviewed-on: https://codeberg.org/git-pages/git-pages/pulls/266
Reviewed-by: Catherine <whitequark@whitequark.org>
2026-10-07 22:42:15 +02:00
Catherine 762ff0ae65 FS: Skip temporary files in Enumerate{Blobs,Manifests}. 2026-10-07 20:10:24 +00:00
Catherine 01904858a1 Use less confusing temporary file names.
While dealing with an unrelated incident I got extremely confused by
what appeared to be sha256 names with 74 characters in them. This was
never intentional, a refactoring of how temporary files are created has
created a call site with this format.
2026-10-07 20:04:38 +00:00
Catherine a8c7bbb316 Add -repair-storage command.
This command replaces corrupted manifests and audit records with
placeholders indicating the corrupt status of the object in question.
As a result, other operations (many of which require that all objects
can be parsed) continue to work as expected.

The contents of a corrupted site manifest is replaced with a human
readable index page explaining the situation, and every URL is
rewritten to point to that index page.
2026-10-05 00:27:29 +00:00
Catherine e52dc6ed86 Include manifest name in protobuf decode errors. 2026-10-04 22:27:27 +00:00
miyuko 6c2f34c54d Allow specifying a reason for a mutation done via the CLI.
The reason is appended to the audit record and is surfaced in the log.
2026-09-20 10:12:15 +01:00
phanirithvij 507e57edbc feat: use os.MkdirAll for creating root directory
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
2026-09-04 02:16:16 +05:30
miyuko 0176494816 Treat wildcard domains and preview domains as public suffixes. 2026-08-27 02:11:48 +01:00
Catherine d525cb61fc Add -purge-domain command (like wildcard -delete-site). 2026-08-26 16:56:27 +00:00
Catherine 255f91dd32 Harmonize log messages for admin commands. 2026-08-26 16:56:07 +00:00
8463eed5ba Retain query params for automatic redirects to .../.
Co-authored-by: phanirithvij <phanirithvij2000@gmail.com>
Reviewed-on: https://codeberg.org/git-pages/git-pages/pulls/253
Reviewed-by: Catherine <whitequark@whitequark.org>
2026-08-20 14:20:21 +02:00
miyukoandCatherine e02c8dd138 Group domains belonging to the same owner when analyzing storage.
Resolves: https://codeberg.org/git-pages/git-pages/issues/239
2026-07-28 01:53:12 +02:00
miyukoandCatherine 3332df668b Improve command-line help for -analyze-storage. 2026-07-28 01:53:12 +02:00
miyukoandCatherine 899e62a75d Add repository as a principal when updating via webhook.
Resolves: https://codeberg.org/git-pages/git-pages/issues/234
2026-07-28 01:47:08 +02:00
miyukoandCatherine f31d55c9ef Fold case of pull request author's username for preview uploads.
Hostnames are lowercase ASCII, so preview upload authorization would
always fail for repositories whose owners have uppercase letters in
their usernames.

Resolves: https://codeberg.org/git-pages/git-pages/issues/228
2026-07-28 01:44:20 +02:00
miyuko 6c1882911a Expose X-Server when responding to mutating requests.
Resolves: https://codeberg.org/git-pages/git-pages/issues/209
2026-07-20 15:23:46 +01:00
Catherine 5c1c8299a5 Color expiring manifests in -list-manifest output.
The color scheme is the same as in `-audit-log`.
2026-07-16 12:43:30 +00:00
Catherine 25462fbd42 Rename -site-expire to -expire-sites for consistency.
The flag is feature-gated.
2026-07-16 12:39:01 +00:00
imi415 03999af740 backend: s3: add option to choose bucket lookup type.
Certain S3 compatible storage providers does not support path style
bucket lookup anymore, add config option to manually specify DNS style
for minio.

Signed-off-by: imi415 <imi415@imi.moe>
2026-07-08 16:46:19 +08:00
Catherine 7d3368e196 Display audit records for expiring sites in a different color. 2026-07-01 01:03:47 +02:00
miyuko d870d0f9c5 Add an administrative CLI command to delete a site. 2026-06-28 21:27:59 +01:00
miyukoandCatherine 43dec6032a Match on the full request URL when applying headers.
Fixes: https://codeberg.org/git-pages/git-pages/issues/206
2026-06-19 09:20:07 +02:00
miyukoandCatherine 4cc8d58548 Don't serve files for URLs with trailing slashes.
Fixes: https://codeberg.org/git-pages/git-pages/issues/205
2026-06-19 09:15:14 +02:00
miyuko f620381551 Return 422 Unprocessable Entity on invalid archive uploads.
Fixes: https://codeberg.org/git-pages/git-pages/issues/216
2026-06-19 03:10:32 +01:00
miyuko 2737f275cf Add tests for HTTP content encoding negotiation. 2026-06-19 02:08:16 +01:00
miyuko 223512cd7a Fix implicit identity Accept-Encoding handling. 2026-06-19 02:04:56 +01:00
miyuko c2928f483f Fix 406 Not Acceptable when Accept-Encoding ends with *;q=0.
Fixes: https://codeberg.org/git-pages/git-pages/issues/203
2026-06-18 20:46:18 +01:00
Koen Oostveen 28012ffa5a Fix _redirects not using the fragment of the redirect URL
Closes #208
2026-06-08 16:36:59 +02:00
Andrew Cassidy 8be2ad0da1 [breaking-change] Clear redirects and headers when PATCHing manifest
Without this, whenever _redirects or _headers gets PATCHed, any new values are appended to the old instead of overriding it.
2026-06-07 21:21:59 -07:00
Catherine a5f3f2898b [breaking-change] Remove SIGHUP handler entirely.
The implementation contains both data races on single-word memory
accesses as well as multiple-word memory accesses which can result
in observing torn writes. It is unsafe and unsalvageable without
wrapping every access to global state into a mutex, or else stopping
request processing during a reload. Both are invasive options.

Since the server restarts very quickly, remove the handler to fix this.
2026-06-01 13:52:40 +00:00
Catherine 8fa88e0444 Fix regression in commit 0cd96a2b0b.
V12-Ref: F-77365
2026-06-01 10:33:09 +02:00
Catherine d1b652b895 Complete the fix in commit c591959fa9.
Staticcheck should have a lint for using `defer` in a loop, but it
does not.

V12-Ref: F-77363
2026-06-01 10:33:09 +02:00
Catherine 3d52632648 Fix regression in commit 0849735f9e.
The check would always fail.

V12-Ref: F-77362
2026-06-01 10:33:09 +02:00
miyukoandCatherine b78ac59758 Make existence cache refresh checks more robust.
For If-Modified-Since checks on the last change marker, only ever send
timestamps that we previously received from the server. This sidesteps
issues like races and anything dealing with clock precision.

Also make the code simpler to follow: handleFilterUpdates() now owns
lastRefresh, and refresh() now owns lastChanged.

Also retry with an exponential backoff if we fail to refresh the cache.
All sends to accessCh are non-blocking and are not affected.

V12-Ref: F-77198
2026-05-31 19:05:53 +02:00
Catherine 434bc884c5 [security] Forbid backslashes from occurring in project names.
This addresses an authorization bypass (which could occur only on
Windows).

A more principled way to do this would be to use `os.Root.OpenRoot`
and scope the actual filesystem operations per-domain. However, I
prototyped this and it was complicated enough that it wasn't clear
whether this would not introduce new issues.

V12-Ref: F-77209
2026-05-30 19:10:41 +00:00
Catherine c591959fa9 Address minor file descriptor leak in CollectTar.
Before this commit, the reader opened by `GetBlob` was not closed.
This does not matter for the current implementation of the S3 backend,
but for the FS backend the file descriptor was only closed by
the `os.file` finalizer.

V12-Ref: F-77205
2026-05-30 18:13:49 +00:00
Catherine ec66cdb6b4 Check git blob size against cumulative limit before reading it.
This avoids exhausting RAM when reading e.g. a repository with a single
extremely large file. Note that there is still a risk of exhausting
space in `/tmp`.

V12-Ref: F-77211
2026-05-30 18:10:43 +00:00
Catherine 577bd04d53 Limit how long forge API responses can be.
V12-Ref: F-77222
2026-05-30 18:10:43 +00:00
Catherine bde52a911e Limit cardinality for git_pages_http_request_* metrics.
V12-Ref: F-77243
2026-05-30 18:10:43 +00:00