GetRepositoryByName shouldn't find a repository if name is empty #13333

Closed
opened 2025-11-02 10:38:49 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @tik-stbuehler on GitHub (Jul 26, 2024).

Description

Hi,

URLs with an empty repository name before .git find "random" repositories.

Example: https://gitea.com/gitea/.git/info/refs

As far as I can tell this happends because:

  1. The "githttp"-handling will strip .git from the :reponame path parameter, i.e. ending up with an empty string:

4b376a0ed9/routers/web/repo/githttp.go (L59-L107)

  1. GetRepositoryByName uses some magic "Get" method on an partially initialized object, passing an empty string as LowerName - but empty fields are likely not used in the WHERE filter string for the databse.

4b376a0ed9/models/repo/repo.go (L747-L759)

Imho the most reliable solution is for GetRepositoryByName not to find repositories with empty names.

cheers,
Stefan

Gitea Version

gitea.com doesn't say

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

gitea.com is your instance.

Database

None

Originally created by @tik-stbuehler on GitHub (Jul 26, 2024). ### Description Hi, URLs with an empty repository name before `.git` find "random" repositories. Example: https://gitea.com/gitea/.git/info/refs As far as I can tell this happends because: 1. The "githttp"-handling will strip `.git` from the `:reponame` path parameter, i.e. ending up with an empty string: https://github.com/go-gitea/gitea/blob/4b376a0ed934ba77d91ab182215fcff07b13c8df/routers/web/repo/githttp.go#L59-L107 2. `GetRepositoryByName` uses some magic "Get" method on an partially initialized object, passing an empty string as `LowerName` - but empty fields are likely not used in the `WHERE` filter string for the databse. https://github.com/go-gitea/gitea/blob/4b376a0ed934ba77d91ab182215fcff07b13c8df/models/repo/repo.go#L747-L759 Imho the most reliable solution is for `GetRepositoryByName` not to find repositories with empty names. cheers, Stefan ### Gitea Version gitea.com doesn't say ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? gitea.com is your instance. ### Database None
GiteaMirror added the type/bug label 2025-11-02 10:38:49 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13333