SSRF via repository mirror URL -- 302 Redirect
Gitaly followed HTTP redirects when fetching a repository mirror, so a user who could configure mirroring could make the server issue GET requests to arbitrary internal hosts. The attacker could not read the responses, so this was a blind request-forgery issue reaching localhost, cloud metadata and the local network.
GitLab
Originally disclosed on GitLab
- Fixed in 8 months
- Disclosed after 8 months
Opening a new issue here as suggested by https://gitlab.com/gitlab-org/gitlab/-/issues/215879#note_381058501, the fix for https://gitlab.com/gitlab-org/gitlab/-/issues/215879 would not address the 302 redirect bypass in this case.
https://hackerone.com/reports/904288 H1 report:
Summary
Gitaly supports HTTP redirects when running the git-receive-pack command. This issue allows a malicious authenticated user to send GET HTTP requests to arbitrary hosts, including the localhost, cloud metadata services and the local network, without reading the HTTP response.
Steps to reproduce
- Run redirect server on
evil.com:
#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
if 'receive' in self.path:
self.send_response(302)
self.send_header('Location', 'http://0:1234')
else:
self.send_response(200)
self.end_headers()
def main():
handler = SocketServer.TCPServer(("0.0.0.0", 80), RedirectHandler)
handler.serve_forever()
if __name__ == "__main__":
main()
- Create a new project
- Add a commit to the repository
- Go to Settings > Repository > Mirroring repositories
- Add mirroring repository with URL:
http://evil.com
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the mirror fetch followed HTTP redirects without re-checking the destination against the internal-address blocklist applied to the original URL.
Impact
An authenticated user could make the server send requests to localhost, cloud metadata endpoints and internal hosts, though responses were not returned to the attacker.
What the attacker needed
An authenticated account; ability to create a project and mirror; attacker-controlled redirect server
The fix
The existing fix for the related issue would not address this 302 redirect bypass.
How it was found
- Run a redirect server that answers the receive-pack path with a 302 to an internal address.
- Create a project and add a commit.
- Open Settings, Repository, Mirroring repositories.
- Add a mirror whose URL points at the redirect server.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you add a mirror, the server fetches from a URL you give it. Here the server also obeyed a redirect to a second address, so the attacker could point it at machines only the server can reach. They could not see the replies.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.