Skip to content

repository: validate remote address on mirror address update - #8225

Merged
unknwon merged 5 commits into
mainfrom
wh/fix-mirror-repo-check
Jun 5, 2026
Merged

unknwon merged 5 commits into
mainfrom
wh/fix-mirror-repo-check

Conversation

@wuhan005

@wuhan005 wuhan005 commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Describe the pull request

Mirror address update (SaveAddress) bypasses all validation enforced during mirror creation (ParseRemoteAddr), including protocol whitelist (http://, https://, git:// only), local network address blocking (netx.IsBlockedLocalHostname), and CRLF injection checks for git:// URLs.

A mirror repository admin can exploit this by first creating a mirror with a valid URL, then changing the address to file:///path/to/other-repo.git to read contents of other local repositories on the server, or to internal network addresses for SSRF.

This patch applies equivalent validation in the update path to match the creation path.

Ref: GHSA-wv27-2vqp-j7g5

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. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)

Test plan

  • Update a mirror address to file:///path/to/other-repo.git, verify it is rejected.
  • Update a mirror address to http://127.0.0.1:3000, verify it is rejected.
  • Update a mirror address to a valid https:// remote, verify it works and sync succeeds.
  • Create a new mirror via migration with a valid URL, verify existing validation is unaffected.

@wuhan005
wuhan005 requested a review from unknwon as a code owner April 4, 2026 06:54
Copilot AI review requested due to automatic review settings April 4, 2026 06:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR closes a security gap where updating a mirror’s remote address (SaveAddress) bypassed the clone-address validation that is enforced during mirror creation, enabling SSRF and local file/path abuse.

Changes:

  • Apply ParseRemoteAddr validation when updating a mirror address in repo settings.
  • Refactor clone address parsing from a MigrateRepo method to a shared form.ParseRemoteAddr(options) helper and update both web + API migration paths to use it.
  • Add a changelog entry documenting the security fix.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/route/repo/setting.go Validates mirror address updates using the same remote address rules as mirror creation.
internal/route/repo/repo.go Switches migration to use the new shared form.ParseRemoteAddr(options) helper.
internal/route/api/v1/repo_repo.go Switches API migration to use the same shared remote address parsing/validation.
internal/form/repo.go Introduces ParseRemoteAddrOptions and a package-level ParseRemoteAddr function to unify validation logic.
CHANGELOG.md Documents the security fix (SSRF via mirror address update validation bypass).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/route/repo/setting.go Resolved
Comment thread internal/route/repo/setting.go Resolved
@unknwon unknwon added this to the 0.14.3 milestone Jun 5, 2026
@unknwon
unknwon force-pushed the wh/fix-mirror-repo-check branch from b215ba6 to 740d52f Compare June 5, 2026 12:19
@unknwon
unknwon merged commit 11e19f2 into main Jun 5, 2026
8 checks passed
@unknwon
unknwon deleted the wh/fix-mirror-repo-check branch June 5, 2026 13:03
unknwon added a commit that referenced this pull request Jun 7, 2026
Signed-off-by: E99p1ant <[email protected]>
Co-authored-by: Joe Chen <[email protected]>
(cherry picked from commit 11e19f2)
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.

3 participants