Skip to content

security: fix SSRF in repository migration #6812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 8, 2022
Merged

security: fix SSRF in repository migration #6812

merged 10 commits into from
Mar 8, 2022

Conversation

michaellrowley
Copy link
Contributor

https://huntr.dev/bounties/327797d7-ae41-498f-9bff-cc0bf98cf531/ / CVE-2022-0870

Describe the pull request

This pull requests contains a proposed patch for the vulnerability noted in the above links.

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.

@unknwon
Copy link
Member

unknwon commented Mar 7, 2022

Thanks for the patch! Looks like the CI is failing.

@unknwon unknwon linked an issue Mar 7, 2022 that may be closed by this pull request
1 task
@unknwon unknwon changed the title SSRF mitigation (#6754) security: fix SSRF in repository migration Mar 7, 2022
This should fix: ``Error: internal/route/repo/webhook.go:149:44: undefined: host``
This should fix: ``Error: internal/route/repo/webhook_test.go:31:40: missing ',' before newline in composite literal``
@michaellrowley
Copy link
Contributor Author

I think that the issues have been fixed.

@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #6812 (f042516) into main (e452d94) will increase coverage by 0.14%.
The diff coverage is 86.20%.

@@           Coverage Diff            @@
##            main   #6812      +/-   ##
========================================
+ Coverage   8.79%   8.93%   +0.14%     
========================================
  Files         97      98       +1     
  Lines      13206   13231      +25     
========================================
+ Hits        1161    1182      +21     
- Misses     11883   11885       +2     
- Partials     162     164       +2     

@unknwon
Copy link
Member

unknwon commented Mar 8, 2022

I think this PR is only fixing part of problem after a closer look, which is the webhook... not the repository migration, because the isLocalHostname is only used by webhook related code logic.

I'm going to make few direct pushes.

@unknwon
Copy link
Member

unknwon commented Mar 8, 2022

@michaellrowley If you wanna look at the steps I made, you can go through each commit.

Comment on lines +74 to +76
if netutil.IsLocalHostname(u.Hostname()) {
return "", db.ErrInvalidCloneAddr{IsURLError: true}
}
Copy link
Member

Choose a reason for hiding this comment

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

@michaellrowley This is where the real fix to the report as far as I understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that seems to be the case (although without the rewritten IsLocalHostname it would still have been possible to bypass this call and the one in validateWebhook)

@unknwon unknwon merged commit 242deca into gogs:main Mar 8, 2022
@unknwon unknwon mentioned this pull request Mar 11, 2022
29 tasks
unknwon added a commit that referenced this pull request Mar 11, 2022
Co-authored-by: Joe Chen <jc@unknwon.io>
# Conflicts:
#	CHANGELOG.md
#	internal/route/repo/webhook.go
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSRF in repository migration
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy