Gitea API can't handle slash on method https://git_url/api/v1/repos/repo_owner/repo_name/branch_protections #9528

Closed
opened 2025-11-02 08:41:53 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @nazario29 on GitHub (Sep 6, 2022).

Description

When using Gitea API method https://git_url/api/v1/repos/repo_owner/repo_name/branch_protections and in particular aiming to branches with a slash on the name the response is 404 page not found instead of a treated message from the API itself, got me thinking that maybe this method is not ready to handle slashes on URL.

This is the request:

curl -X 'GET' \
  'https://git_url/api/v1/repos/repo_owner/repo_name/branch_protections/release%2F1' \
  -H 'accept: application/json'

But if I use other method for example:

curl -X 'GET' \
  'https://git_url/api/v1/repos/devops/sample-java-app/branches/release%2F1' \
  -H 'accept: application/json'

I got an expected response from the API:

{
  "errors": null,
  "message": "The target couldn't be found.",
  "url": "https://git_url/api/swagger"
}

Gitea Version

1.17.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.37.2

Operating System

CentOS 8

How are you running Gitea?

Running gitea as a systemd service together with postgres DB on a CentOS 8

Database

PostgreSQL

Originally created by @nazario29 on GitHub (Sep 6, 2022). ### Description When using **Gitea API** method `https://git_url/api/v1/repos/repo_owner/repo_name/branch_protections` and in particular aiming to branches with a slash on the name the response is `404 page not found` instead of a treated message from the API itself, got me thinking that maybe this method is not ready to handle slashes on URL. This is the request: ``` curl -X 'GET' \ 'https://git_url/api/v1/repos/repo_owner/repo_name/branch_protections/release%2F1' \ -H 'accept: application/json' ``` But if I use other method for example: ``` curl -X 'GET' \ 'https://git_url/api/v1/repos/devops/sample-java-app/branches/release%2F1' \ -H 'accept: application/json' ``` I got an expected response from the API: ``` { "errors": null, "message": "The target couldn't be found.", "url": "https://git_url/api/swagger" } ``` ### Gitea Version 1.17.1 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version 2.37.2 ### Operating System CentOS 8 ### How are you running Gitea? Running gitea as a systemd service together with postgres DB on a CentOS 8 ### Database PostgreSQL
GiteaMirror added the issue/needs-feedback label 2025-11-02 08:41:53 -06:00
Author
Owner

@jolheiser commented on GitHub (Sep 6, 2022):

I get expected responses on https://try.gitea.io when I use these endpoints.

Is there anything in your logs?

These endpoints require a token, which I notice you didn't have in your example requests, but other than that they appear to work correctly on the demo.

@jolheiser commented on GitHub (Sep 6, 2022): I get expected responses on https://try.gitea.io when I use these endpoints. Is there anything in your logs? These endpoints require a token, which I notice you didn't have in your example requests, but other than that they appear to work correctly on the demo.
Author
Owner

@nazario29 commented on GitHub (Sep 6, 2022):

I removed the Authorization header from this thread on purpose but I get expected responses from other methods.
Nothing relevant in the logs, just the trace of the request itself.

Also, something I forgot to mention is we have Nginx on top of Gitea.

I'm attaching prints from swagger to help explain it:

Failed request on branch_protection with just a 404:
image
Request on branches method that we can see API accepts it and responds:
image

@nazario29 commented on GitHub (Sep 6, 2022): I removed the Authorization header from this thread on purpose but I get expected responses from other methods. Nothing relevant in the logs, just the trace of the request itself. Also, something I forgot to mention is we have Nginx on top of Gitea. I'm attaching prints from swagger to help explain it: Failed request on branch_protection with just a 404: ![image](https://user-images.githubusercontent.com/69314381/188697833-2176d9e0-938e-4a46-a42f-a78963826222.png) Request on branches method that we can see API accepts it and responds: ![image](https://user-images.githubusercontent.com/69314381/188698489-f079d29c-a428-4731-9a74-201d412190f3.png)
Author
Owner

@jolheiser commented on GitHub (Sep 6, 2022):

Can you try to reproduce on the demo?
As well, maybe try on your server directly using curl without hitting the proxy, just to check.

@jolheiser commented on GitHub (Sep 6, 2022): Can you try to reproduce on the demo? As well, maybe try on your server directly using curl without hitting the proxy, just to check.
Author
Owner

@nazario29 commented on GitHub (Sep 7, 2022):

Ok it worked on demo gitea, definitely something wrong on my end, will try to investigate it further.
Thank you @jolheiser

@nazario29 commented on GitHub (Sep 7, 2022): Ok it worked on demo gitea, definitely something wrong on my end, will try to investigate it further. Thank you @jolheiser
Author
Owner

@wxiaoguang commented on GitHub (Sep 7, 2022):

Check your nginx config (especially the ending slash for proxy_pass)

Some reverse proxy will decode the path from release%2F1 to release/1, but Gitea expects to see release%2F1, you can check whether the URI is correct in Gitea's log.

See this one:

@wxiaoguang commented on GitHub (Sep 7, 2022): Check your nginx config (especially the ending slash for proxy_pass) Some reverse proxy will decode the path from `release%2F1` to `release/1`, but Gitea expects to see `release%2F1`, you can check whether the URI is correct in Gitea's log. See this one: * https://github.com/go-gitea/gitea/issues/20890#issuecomment-1222291868
Author
Owner

@nazario29 commented on GitHub (Sep 7, 2022):

After doing the mentioned change here https://github.com/go-gitea/gitea/issues/20890#issuecomment-1222347277 just fixed this issue.
thanks, everyone!

@nazario29 commented on GitHub (Sep 7, 2022): After doing the mentioned change here https://github.com/go-gitea/gitea/issues/20890#issuecomment-1222347277 just fixed this issue. thanks, everyone!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#9528