Skip to content

security: close SSRF in repository migration and recurring mirror sync - #8324

Merged
unknwon merged 8 commits into
mainfrom
GHSA-g2f5-gjr4-qjvm
Jun 6, 2026
Merged

unknwon merged 8 commits into
mainfrom
GHSA-g2f5-gjr4-qjvm

Conversation

@unknwon

@unknwon unknwon commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Two related SSRFs in the migration / mirror path. Both reduce to the same defense: the up-front clone address validation is the only place Gogs checks where it's about to talk to, and git was free to talk to a different place later.

  • Initial migration (GHSA-g2f5-gjr4-qjvm): ParseRemoteAddr validates the submitted URL against the local-network blocklist, but git clone --mirror followed HTTP redirects with no revalidation. A public-looking source could 302 to an internal endpoint and the contents would land in the new repository.
  • Recurring mirror sync: same redirect-follow on every periodic git remote update, plus no re-validation of the stored URL's hostname at sync time. An attacker who set up a mirror with a benign URL could later flip DNS or start serving redirects to an internal target and the next sync would pull from it.

Ref: GHSA-g2f5-gjr4-qjvm

What changed

  • Pass -c http.followRedirects=false to every remote-touching git call in the migration and mirror paths: source clone, wiki clone, wiki URL probe, periodic git remote update (repo + wiki).
  • Re-validate the mirror's hostname against netx.IsBlockedLocalHostname before each sync, so a DNS flip after creation cannot turn a previously-public source into an internal one.
  • The migration git.Clone wrapper hardcodes clone as the first arg, so adding the git-level -c flag required dropping that wrapper for direct process.ExecTimeout calls, matching the pattern already used elsewhere in the package.

Test plan

  • moon run gogs:lint
  • go test ./internal/database/...
  • Manual: with a public URL that 302s to http://127.0.0.1:<port>/..., confirm migration fails instead of importing the internal repo.
  • Manual: create a mirror with a benign URL, point its DNS at 127.0.0.1, confirm the next sync aborts with a notice instead of pulling.

unknwon added 4 commits June 5, 2026 21:32
Pin git's followRedirects to false when cloning the migration source and
its wiki, and when probing the wiki URL. The clone address is validated
against the local-network blocklist up front, but git was free to follow
a 302 to an internal endpoint, so a public-looking URL could still pull
contents from a host the validator would have rejected.
Apply the same redirect-disable to git remote update on both the repo
and wiki sync. Also re-check the mirror's hostname against the local
network blocklist before each sync, so a DNS flip after the mirror was
created cannot turn a previously-validated source into an internal one.
@unknwon unknwon changed the title security: disable HTTP redirects during repository migration security: close SSRF in repository migration and recurring mirror sync Jun 6, 2026
@unknwon
unknwon force-pushed the GHSA-g2f5-gjr4-qjvm branch from 1771888 to 508672b Compare June 6, 2026 01:52
unknwon added 2 commits June 5, 2026 21:53
git was being asked to fetch over the network with no terminal attached,
and on the failure path it tried to prompt for credentials. The server
process then hung on a prompt that no one was answering. Set GIT_TERMINAL_PROMPT=0
and clear the askpass so any auth failure surfaces immediately as an error.
@unknwon unknwon added this to the 0.14.3 milestone Jun 6, 2026
@unknwon
unknwon merged commit b9a0093 into main Jun 6, 2026
8 checks passed
@unknwon
unknwon deleted the GHSA-g2f5-gjr4-qjvm branch June 6, 2026 02:13
unknwon added a commit that referenced this pull request Jun 7, 2026
unknwon added a commit that referenced this pull request Jun 7, 2026
#8324 imports gogs.io/gogs/internal/netx, which is the renamed netutil
on main. The rename is not part of the 0.14.3 backport, so use the
original netutil package on release/0.14.
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

⌂ 换网址