Skip to content

security: walk full upload path for symlinks - #8332

Merged
unknwon merged 3 commits into
mainfrom
GHSA-89mr-xqfv-758m
Jun 7, 2026
Merged

unknwon merged 3 commits into
mainfrom
GHSA-89mr-xqfv-758m

Conversation

@unknwon

@unknwon unknwon commented Jun 7, 2026

Copy link
Copy Markdown
Member

Describe the pull request

The repository file upload handler only checked whether the leaf of the target path was a symlink before writing. If a sibling commit had placed a directory symlink in the tree, a crafted upload filename could redirect the write through that symlink to anywhere the Gogs process could write.

The check is now consistent with the sibling edit and delete handlers, which lstat every component of the path.

Refs GHSA-89mr-xqfv-758m.

Checklist

Test plan

  1. As a user with write access, commit a directory symlink to the repository (for example ln -s /tmp/elsewhere hijack followed by git push).
  2. Upload a file via POST /:owner/:repo/upload-file with a multipart filename whose parsed value contains a path separator pointing into the symlinked directory (for example hijack/payload).
  3. Commit the upload via POST /:owner/:repo/_upload/:branch/.
  4. Before this change: the file lands outside the working tree at the symlink target.
  5. After this change: the commit is rejected with cannot overwrite symbolic link: <name> and no file is written outside the working tree.

@unknwon unknwon added this to the 0.14.3 milestone Jun 7, 2026
@unknwon
unknwon merged commit 04cb8af into main Jun 7, 2026
8 checks passed
@unknwon
unknwon deleted the GHSA-89mr-xqfv-758m branch June 7, 2026 02:46
unknwon added a commit that referenced this pull request Jun 7, 2026
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