Skip to content

security: authorize Git HTTP by routed action, not client-supplied service - #8331

Merged
unknwon merged 4 commits into
mainfrom
GHSA-wmfg-5p4h-5fw3
Jun 7, 2026
Merged

unknwon merged 4 commits into
mainfrom
GHSA-wmfg-5p4h-5fw3

Conversation

@unknwon

@unknwon unknwon commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Gogs' Git smart-HTTP handler decided read vs write from the client-supplied ?service= query parameter, so a POST /repo.git/git-receive-pack?service=git-upload-pack was authorized as a read while the route still executed git-receive-pack. A user with read-only access could push.

This branch derives the access mode from the routed action instead:

  • git-receive-pack (and info/refs?service=git-receive-pack) are the only operations that demand write access. service= is consulted only on info/refs, the one endpoint shared between fetch and push. Everywhere else the RPC path is authoritative.
  • The dead gitHTTPAction(c) call left over from the old check is removed.

Security advisory: GHSA-wmfg-5p4h-5fw3

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan.
  • I have added an entry to CHANGELOG.

Test plan

  1. Create two users victim and attacker.
  2. As victim, create a private repository and add attacker as a read-only collaborator.
  3. Run the advisory PoC, which proxies git push and rewrites the request to POST /victim/target.git/git-receive-pack?service=git-upload-pack.
  4. Before this change: push succeeds, attacker writes to the read-only repository.
  5. After this change: push is rejected with 403 User permission denied, and the repository remains unchanged.

@unknwon unknwon added this to the 0.14.3 milestone Jun 7, 2026
@unknwon unknwon changed the title security: harden Git HTTP access checks security: authorize Git HTTP by routed action, not client-supplied service Jun 7, 2026
@unknwon
unknwon merged commit 7c9cf53 into main Jun 7, 2026
8 checks passed
@unknwon
unknwon deleted the GHSA-wmfg-5p4h-5fw3 branch June 7, 2026 02:35
unknwon added a commit that referenced this pull request Jun 7, 2026
unknwon added a commit that referenced this pull request Jun 7, 2026
golangci-lint flagged two issues:

- internal/form/form.go used the deprecated reflect.Ptr alias in two
  spots. Replace with reflect.Pointer (the constant the deprecation
  notice points to) so govet stops reporting the inline hint.
- internal/route/repo/http.go had a stray blank line between the new
  gitHTTPIsPull helper and HTTPContexter, leftover from the #8331
  cherry-pick. Drop it to satisfy gofmt.
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.

1 participant