Branch Protection API {name} parameter cannot parse branch rule names with "/" inside. #14804

Open
opened 2025-11-02 11:23:27 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @ksjdragon on GitHub (Jul 25, 2025).

Description

If a branch protection rule was created with "/", it is not possible to access it with the API, with any of the following:

GET /repos/{owner}/{repo}/branch_protections/{name}
DELETE /repos/{owner}/{repo}/branch_protections/{name}
PATCH /repos/{owner}/{repo}/branch_protections/{name}

You will obtain a 404 error. After looking through the code, the reason seems to be how
the chi router handles parameters. It does not greedily match the rest of the URL, and
will match up to the next /.

My proposed solution is to change the API let the rule_name simply be in the body of the JSON sent.

However, if that's not desired, I noticed that URI-encoding the "/" into "%2F", seems work because ctx.PathParam does unescaping. This is not mentioned anywhere in the docs (to my knowledge),
so in that case, I believe it should be written in the API guide.

Gitea Version

1.24.2

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.47.1

Operating System

CentOS Stream 10

How are you running Gitea?

Docker Container

Database

PostgreSQL

Originally created by @ksjdragon on GitHub (Jul 25, 2025). ### Description If a branch protection rule was created with "/", it is not possible to access it with the API, with any of the following: GET /repos/{owner}/{repo}/branch_protections/{name} DELETE /repos/{owner}/{repo}/branch_protections/{name} PATCH /repos/{owner}/{repo}/branch_protections/{name} You will obtain a 404 error. After looking through the code, the reason seems to be how the chi router handles parameters. It does not greedily match the rest of the URL, and will match up to the next /. My proposed solution is to change the API let the rule_name simply be in the body of the JSON sent. However, if that's not desired, I noticed that URI-encoding the "/" into "%2F", seems work because ctx.PathParam does unescaping. This is not mentioned anywhere in the docs (to my knowledge), so in that case, I believe it should be written in the API guide. ### Gitea Version 1.24.2 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version 2.47.1 ### Operating System CentOS Stream 10 ### How are you running Gitea? Docker Container ### Database PostgreSQL
GiteaMirror added the topic/packagestype/bug labels 2025-11-02 11:23:27 -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#14804