Repository navigation
security: reject path traversal in owner and repository names - #8334
Merged
Merged
Conversation
unknwon
added a commit
that referenced
this pull request
Jun 7, 2026
(cherry picked from commit f6acd46)
unknwon
added a commit
that referenced
this pull request
Jun 7, 2026
#8334 on main added `AlphaDashDot;MaxSize(35)` binding tags to the createOrgRequest struct. On release/0.14 that struct lives in the external go-gogs-client module and cannot carry binding tags, so apply the same validation inline in CreateOrgForUser, which is the common funnel for both /api/v1/orgs and /api/v1/admin/users/:user/orgs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
The organization creation API accepted any non-empty string for the username, including path traversal sequences like
../../../tmp/x. Owner and repository names flow into filesystem paths viarepox.UserPathandrepox.RepositoryPath, so a traversal name made the server place git directories at attacker-chosen locations and ultimately allowed remote code execution through planted hooks.This change adds two independent layers:
createOrgRequest.UserNamefield now goes through the sameAlphaDashDot;MaxSize(35)binding the web form has always used, rejecting traversal characters before any handler logic runs.repox.UserPathandrepox.RepositoryPathrun their inputs throughpathx.Clean, so even if a name with a traversal slips past a future caller, the resulting filesystem path is contained within the repository root.Refs GHSA-c39w-43gm-34h5.
Checklist
Test plan
POST /api/v1/orgs(orPOST /api/v1/admin/users/:user/orgs) with{"username": "../../../tmp/poc", ...}.201 Createdand the organization directory is written under/tmp/poc, enabling the hook overwrite path described in the advisory.422 Unprocessable Entitywith anAlphaDashDotvalidation error, no filesystem entry is created.{"username": "foo/bar"}and confirm the same rejection.{"username": "good-org_1"}) still returns201 Created.