Repository navigation
fix(server): --git defers to plugin-owned prefixes (#616) - #630
Conversation
Core's git preHandler ran on every URL containing info/refs or a pack service, looked the repo up under the pod root and answered 401 before a plugin mounted at that prefix ever saw the request. A plugin that serves git smart-HTTP under its own mount (the forge at /forge/<owner>/<name>.git) was shadowed whenever --git was on. The hook now returns early for a URL below an app path, exactly as the WAC hook and the dotfile guard already defer to appPaths, so plugin git falls through to the plugin and core's lane stays the pod's. Read per request, so prefixes pushed during activation count. Test: a plugin mounted at /forge receives info/refs and both pack services unauthenticated; pod git outside the prefix is still auth-gated. Two of the three checks fail without the fix. Closes #616
There was a problem hiding this comment.
🔵 Needs a closer look
The change alters which requests bypass core's git authorization gate, a security-sensitive auth path that warrants human confirmation despite being consistent with the existing appPaths exemption.
No open issues 🎉
What changed in this PR
This PR fixes issue #616, where core's --git smart-HTTP handler globally intercepted any URL containing info/refs, git-upload-pack, or git-receive-pack. Because isGitRequest matches by substring regardless of path, a plugin serving git under its own mount (e.g. the forge at /forge/<owner>/<name>.git) was shadowed: core looked the repo up under the pod root and answered 401 before the plugin ran. The fix adds an early return in the existing if (gitEnabled) preHandler so that git-shaped URLs below a registered app prefix fall through to the plugin, which does its own authorization — mirroring how the WAC hook (server.js:801) and the dotfile guard (server.js:601) already defer to appPaths. Core's git lane continues to serve the pod's own repos outside those prefixes.
Changes:
- Add an
appPaths-based early return in the gitpreHandlerinsrc/server.jsso plugin-owned git prefixes are not intercepted by core. - Add
test/git-plugin-prefix.test.jscovering plugin-prefix defer (GET discovery + POST pack services) and the pod-git regression guard (still 401 outside the prefix).
| File | Description |
|---|---|
| src/server.js | Adds an early return in the git preHandler so git-shaped URLs under a registered appPaths prefix defer to the owning plugin instead of being auth-gated by core. |
| test/git-plugin-prefix.test.js | New test booting with git: true and a fixture plugin at /forge, asserting plugin git URLs reach the plugin unauthenticated while pod git outside the prefix stays core's 401. |
Review effort: Balanced
Since 0.0.220: - --git defers to plugin-owned prefixes (#616, #630): core's git preHandler returns early for a URL below an app path, so a plugin serving git smart-HTTP under its mount (the forge at /forge/<owner>/<name>.git) is no longer shadowed by core's 401. Pod git outside plugin prefixes is unchanged. - CORS exposes WWW-Authenticate, Last-Modified and Accept-Query to cross-origin clients (#629). - @fastify/websocket registered once at the root (#545, #620). - Hardening: atomic quota reservation and idempotent deposit credit (#619).
Problem
With
--giton, core's gitpreHandlerruns on every URL containinginfo/refs,git-upload-packorgit-receive-pack, looks the repo up under the pod root and answers 401 before a plugin mounted at that prefix sees the request. A plugin serving git smart-HTTP under its own mount (the forge at/forge/<owner>/<name>.git) is shadowed, so pod git and plugin git were either/or. This is #616, option 1.Fix
The hook returns early for a URL below an app path, the same
appPathscheck the WAC hook and the dotfile guard already use. Plugin git falls through to the plugin, which does its own authorization and runs its own backend; core's git lane stays the pod's.appPathsis read per request, so prefixes pushed during plugin activation count.Eleven lines in
src/server.js, inside the existingif (gitEnabled)block.Test
test/git-plugin-prefix.test.jsboots withgit: trueand a fixture plugin at/forgethat answers every request under its mount:GET /forge/alice/repo.git/info/refs?service=git-receive-packreaches the plugin, unauthenticated, with the full query intactPOST …/git-receive-packand…/git-upload-packreach the pluginGET /alice/repo.git/info/refs?service=git-receive-packoutside the prefix is still core's and still 401 "Write access required for push"The first two fail without the fix. Full suite: 1071 pass.
Seen in the wild
melvin.me runs
--gitwith the forge plugin; a nostr agent pushing into its own namespace/forge/<hex>/<name>.gitwith a forge push token got core's 401 before the forge's own owner check ran.Closes #616