Skip to content

security: reject path traversal in owner and repository names - #8334

Merged
unknwon merged 2 commits into
mainfrom
GHSA-c39w-43gm-34h5
Jun 7, 2026
Merged

unknwon merged 2 commits into
mainfrom
GHSA-c39w-43gm-34h5

Conversation

@unknwon

@unknwon unknwon commented Jun 7, 2026

Copy link
Copy Markdown
Member

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 via repox.UserPath and repox.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:

  1. The API createOrgRequest.UserName field now goes through the same AlphaDashDot;MaxSize(35) binding the web form has always used, rejecting traversal characters before any handler logic runs.
  2. repox.UserPath and repox.RepositoryPath run their inputs through pathx.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

  1. As any signed-in user, send POST /api/v1/orgs (or POST /api/v1/admin/users/:user/orgs) with {"username": "../../../tmp/poc", ...}.
  2. Before this change: response is 201 Created and the organization directory is written under /tmp/poc, enabling the hook overwrite path described in the advisory.
  3. After this change: response is 422 Unprocessable Entity with an AlphaDashDot validation error, no filesystem entry is created.
  4. Repeat with {"username": "foo/bar"} and confirm the same rejection.
  5. Confirm normal organization creation ({"username": "good-org_1"}) still returns 201 Created.

@unknwon unknwon added this to the 0.14.3 milestone Jun 7, 2026
@unknwon
unknwon merged commit f6acd46 into main Jun 7, 2026
8 checks passed
@unknwon
unknwon deleted the GHSA-c39w-43gm-34h5 branch June 7, 2026 03:14
unknwon added a commit that referenced this pull request Jun 7, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址