CVE-2026-56657
Gitea SSH Key Parser Denial of Service
Summary
Gitea's SSH key ingestion endpoint accepts keys in RFC 4716 (SSH2) format and normalises them before storage. The normalisation function contains an O(N²) string concatenation loop with no input size limit, meaning a single malicious key submission can force the server to perform an amount of work that grows quadratically with the size of the input. Any authenticated user can exploit this to exhaust the server's CPU and memory, taking the instance offline. ### Root Cause An attacker sends a POST /api/v1/user/keys request with a Bearer token and a JSON body whose key field contains a malicious RFC 4716 (SSH2) public key. The key consists of a valid SSH2 header followed by a very large number of short content lines — for example, 400,000 lines of 100 characters each (~38 MB total). The request reaches `CreateUserPublicKey` with no prior size check: https://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/routers/api/v1/user/key.go#L201-L212 This calls `CheckPublicKeyString` which immediately calls `parseKeyString`. Inside `parseKeyString`, the SSH2 branch splits the input on newlines and accumulates the key body one line at a time using `keyContent += line`: https://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/models/asymkey/ssh_key_parse.go#L60-L79 Because Go strings are immutable, each `+=` at line 77 allocates a new backing array and copies the entire accumulated string into it. For N lines the total bytes copied is `N*(N+1)/2`, making the operation `O(N²)` in both time and allocations. The validity of the key is only checked after the loop completes, so the entire quadratic work is performed regardless of whether the input is a real SSH key. This is only possible because neither the web form field nor the API struct carries a size constraint: https://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/services/forms/user_form.go#L308-L317 https://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/modules/structs/repo_key.go#L33-L49 ### PoC To reproduce, clone gitea and checkout commit `9155a81b9daf1d46b2380aa91271e623ac947c1e`. Then create the following files from the gitea root directory: `poc/Dockerfile` ```docker FROM golang:1.26-alpine AS builder RUN apk add --no-cache git build-base WORKDIR /gitea # Download deps in a separate layer so rebuilds are fast after source changes. COPY go.mod go.sum ./ RUN go mod download # Copy full source (needed for fixtures, config templates, and compilation). COPY . . # Compile the integration test binary. # modernc sqlite (pure Go, no CGO needed) is the default driver. RUN CGO_ENABLED=0 go test -c \ -o /integration.test \ gitea.dev/tests/integration # ── runtime image ──────────────────────────────────────────────────────────── FROM alpine:3.22 # git is required at runtime: the test framework initialises git repos. RUN apk add --no-cache git COPY --from=builder /integration.test /integration.test # Keep the full source at /gitea so runtime.Caller(0) path resolution works # and fixtures / config templates are accessible. COPY --from=builder /gitea /gitea RUN adduser -D -u 1000 poc && chown -R poc:poc /gitea WORKDIR /gitea USER poc ENTRYPOINT ["/integration.test", \ "-test.run", "TestDoSSSHKeyParserOOM", \ "-test.v", \ "-test.timeout", "600s"] ``` `tests/integration/poc_dos_test.go` ```go package integration import ( "fmt" "runtime" "runtime/debug" "strings" "sync" "sync/atomic" "testing" "time" auth_model "gitea.dev/models/auth" api "gitea.dev/modules/structs" "gitea.dev/tests" ) func TestDoSSSHKeyParserOOM(t *testing.T) { defer tests.PrepareTestEnv(t)() // Raise the GC trigger so intermediate strings accumulate faster, // matching realistic server behaviour under sustained allocation load. debug.SetGCPercent(400) // Log in as an ordinary user — no special privileges needed. session := loginUser(t, "user
Affected packages
| Ecosystem | Package | Affected versions | Fixed versions |
|---|---|---|---|
| Go | code.gitea.io/gitea | — | 1.27.0 |
Remediation: Upgrade to 1.27.0 or later.
References
Includes data from the GitHub Advisory Database, licensed under CC-BY 4.0.
CVE® is a registered trademark of The MITRE Corporation. CVE content reproduced under the CVE Terms of Use; copyright designation © MITRE.