Skip to content

fix(server): --git defers to plugin-owned prefixes (#616) - #630

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
git-skip-plugin-prefixes
Oct 18, 2026
Merged

melvincarvalho merged 1 commit into
gh-pagesfrom
git-skip-plugin-prefixes

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Problem

With --git on, core's git preHandler runs on every URL containing info/refs, git-upload-pack or git-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 appPaths check 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. appPaths is read per request, so prefixes pushed during plugin activation count.

Eleven lines in src/server.js, inside the existing if (gitEnabled) block.

Test

test/git-plugin-prefix.test.js boots with git: true and a fixture plugin at /forge that answers every request under its mount:

  • GET /forge/alice/repo.git/info/refs?service=git-receive-pack reaches the plugin, unauthenticated, with the full query intact
  • POST …/git-receive-pack and …/git-upload-pack reach the plugin
  • GET /alice/repo.git/info/refs?service=git-receive-pack outside 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 --git with the forge plugin; a nostr agent pushing into its own namespace /forge/<hex>/<name>.git with a forge push token got core's 401 before the forge's own owner check ran.

Closes #616

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 git preHandler in src/server.js so plugin-owned git prefixes are not intercepted by core.
  • Add test/git-plugin-prefix.test.js covering 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

@melvincarvalho
melvincarvalho merged commit fdc1c4d into gh-pages Oct 18, 2026
2 checks passed
@melvincarvalho
melvincarvalho deleted the git-skip-plugin-prefixes branch October 18, 2026 10:40
melvincarvalho added a commit that referenced this pull request Oct 18, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--git shadows plugin-owned git paths (isGitRequest is a global substring match)

2 participants