Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Weblate 2026.12

.. rubric:: Security fixes

* Restricted Git exporter requests to the managed Git repository and supported HTTP endpoints.
Comment thread
nijel marked this conversation as resolved.
Resolved

* Warn before and after restoring a :ref:`project backup <projectbackup>` when a public-only billing plan makes the project public.

* Enforced GitHub App repository and push settings when restoring a :ref:`projectbackup`.
Expand Down
37 changes: 37 additions & 0 deletions weblate/gitexport/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,43 @@ def test_git_info(self) -> None:
)
self.assertEqual(404, response.status_code)

def create_nested_repository(self, path: str) -> None:
"""Create files shaped like a bare repository, as upstream could commit."""
nested = pathlib.Path(self.component.full_path, path)
for name in ("objects", "refs"):
(nested / name).mkdir(parents=True)
(nested / "HEAD").write_text("ref: refs/heads/main\n", encoding="utf-8")

def test_git_nested_path(self) -> None:
nested = "info/a/b/c/d/e"
self.create_nested_repository(nested)
url = self.get_git_url()
for method, path in (
("GET", "info/refs"),
("GET", "HEAD"),
("GET", "objects/info/packs"),
("GET", f"objects/00/{'0' * 38}"),
("POST", "git-upload-pack"),
("POST", "git-receive-pack"),
):
with self.subTest(method=method, path=path):
response = self.client.generic(
method, url.replace("info/refs", f"{nested}/{path}")
)
self.assertEqual(404, response.status_code)
for path in ("info/refs/", "info/packs", "git-upload-pack-x"):
with self.subTest(path=path):
response = self.client.get(url.replace("info/refs", path), follow=True)
self.assertEqual(404, response.status_code)

def test_git_backend_ignores_working_tree(self) -> None:
nested = "info/a/b/c/d/e"
self.create_nested_repository(nested)
request = self.get_request()
request.META["QUERY_STRING"] = "service=git-upload-pack"
wrapper = GitHTTPBackendWrapper(self.component, request, f"{nested}/info/refs")
self.assertEqual(404, wrapper.get_response().status_code)

def git_receive(self, **kwargs):
return self.client.get(
self.get_git_url(),
Expand Down
7 changes: 5 additions & 2 deletions weblate/gitexport/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class GitHTTPBackendWrapper:
def __init__(
self, obj, request: AuthenticatedHttpRequest, git_request: str
) -> None:
self.path = os.path.join(obj.full_path, git_request)
self.git_request = git_request
self.obj = obj
self.request = request
self.selector = DefaultSelector()
Expand Down Expand Up @@ -400,7 +400,10 @@ def __init__(
def get_env(self) -> dict[str, str]:
result = {
"REQUEST_METHOD": self.request.method,
"PATH_TRANSLATED": self.path,
# Bind the backend to the Git directory of the checkout. The working
# tree holds upstream content and must never be opened as a repository.
"GIT_PROJECT_ROOT": os.path.join(self.obj.full_path, ".git"),
"PATH_INFO": f"/{self.git_request}",
"GIT_HTTP_EXPORT_ALL": "1",
"CONTENT_TYPE": self.request.headers.get("content-type", ""),
"QUERY_STRING": self.request.META.get("QUERY_STRING", ""),
Expand Down
3 changes: 2 additions & 1 deletion weblate/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class WeblateSlugConverter(StringConverter):


class GitPathConverter(StringConverter):
regex = "(info/|git-upload-pack|git-receive-pack)[a-z0-9_/-]*"
# Only the smart HTTP requests served by the Git exporter
regex = "(info/refs|git-upload-pack|git-receive-pack)"


class WordConverter(StringConverter):
Expand Down
Loading