CVE-2026-42554: Github.com/gofiber/fiber/v3 Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-qjv7-627w-8qjv
CWE-79
Published
Advisory Summary

CVE-2026-42554 is a MODERATE cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Github.com/gofiber/fiber/v3 libraries in the Go ecosystem. The issue involves fiber vulnerable to xss in autoformat content negotiation. Remediation is available by upgrading affected packages to version 3.2.0, 2.52.13.

CVE-2026-42554 at a Glance

CVE Identifier CVE-2026-42554
GHSA Identifier GHSA-qjv7-627w-8qjv
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Github.com/gofiber/fiber/v3
Package Ecosystem Go
Published Date
Last Updated

How to Fix CVE-2026-42554

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

github.com/gofiber/fiber/v3 fixed: 3.2.0
Upgrade github.com/gofiber/fiber/v3 to 3.2.0
github.com/gofiber/fiber/v2 fixed: 2.52.13
Upgrade github.com/gofiber/fiber/v2 to 2.52.13
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 github.com/gofiber/fiber/v3

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-42554, inspect your project dependencies for Github.com/gofiber/fiber/v3:

inspect dependencies for github.com/gofiber/fiber/v3

Analyze the terminal output to locate any version of Github.com/gofiber/fiber/v3 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.2.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-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Github.com/gofiber/fiber/v3, 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

## Summary **Description** A Cross-Site Scripting (CWE-79) vulnerability in Go Fiber allows a remote attacker to inject arbitrary HTML/JavaScript by supplying `Accept: text/html` on any request whose handler passes attacker-influenced data to the AutoFormat() feature. This affects `github.com/gofiber/fiber/v3` (`DefaultRes.AutoFormat`) through version 3.1.0 and `github.com/gofiber/fiber/v2` (`Ctx.Format`) through version 2.52.12. The developer opts into content negotiation by calling AutoFormat(), but does not opt into raw HTML emission for a particular request; Fiber chooses that branch from attacker-controlled Accept. Five of the six branches of the same method already escape. `JSON`, `XML`, `MsgPack`, and `CBOR` all route through encoders that neutralize markup; the txt branch emits `text/plain` and cannot execute. The html branch is the sole outlier in a method whose name (`AutoFormat`) and symmetrical structure actively telegraph "safe, format-agnostic reply." ## Details The issue resides in `res.go` within `(*DefaultRes).AutoFormat()`. The method negotiates against the request Accept header, selects one of `html | json | txt | xml | msgpack | cbor`, and serializes the caller-supplied body accordingly. The "html" branch concatenates the stringified body directly into HTML markup with no output encoding: - `accept` comes from `r.c.Accepts(...)`, i.e. is fully attacker-controlled. An attacker can force the "html" branch on any `AutoFormat()` call regardless of which format the developer tested against. - `b` is produced from `body` via direct assignment (`string` / `[]byte`) or `fmt.Sprintf("%v", body)`. No `html.EscapeString` is applied. - The resulting string is sent as `text/html; charset=utf-8`, so browsers render it as active HTML. ```go // res.go func (r *DefaultRes) AutoFormat(body any) error { accept := r.c.DefaultReq.Accepts("html", "json", "txt", "xml", "msgpack", "cbor") r.Type(accept) var b string switch val := body.(type) { case string: b = val case []byte: b = r.c.app.toString(val) default: b = fmt.Sprintf("%v", val) } switch accept { case "txt": return r.SendString(b) case "json": return r.JSON(body) case "xml": return r.XML(body) case "html": return r.SendString("<p>" + b + "</p>") case "msgpack": return r.MsgPack(body) case "cbor": return r.CBOR(body) } return r.SendString(b) } ``` ## Impact This impacts all current v3 releases ≤ 3.1.0 containing `DefaultRes.AutoFormat`, and all current v2 releases ≤ 2.52.12 where the identical `"<p>" + b + "</p>"` construction exists in `(*Ctx).Format()`. Exploitation requires that an application call `c.AutoFormat(v)` where `v` (or a field stringified by `%v`) contains request-influenced data. A handler that uses `AutoFormat()` to serve multiple representations of the same data can be turned into an HTML XSS sink when the client sends `Accept: text/html`, even if the developer only tested the JSON path. This may result in: - **Reflected XSS** in the application's origin via any request-derived value reaching `AutoFormat`. - **Stored XSS** where the reflected value originates from persisted input later passed to `AutoFormat`. ## Proposed Patch The injection surface is `r.Type("html")` followed by `r.SendString(b)` with unescaped caller data, where it constructs markup on the caller's behalf around a value whose HTML-ness the caller did not declare. A few options: - `AutoFormat()` should treat `body` as data, not markup, in the `"html"` branch and escape it before concatenating it into the framework-generated `<p>` wrapper. Callers that need raw negotiated HTML should use `Format()` with an explicit HTML handler. - Introduce a sibling method that escapes, leave `AutoFormat` alone for backward compatibility. HTML-escape the value in the "html" branch before concatenating it into the `<p>` wrapper. ```go import "html" // ... case "html": return r.SendString("<p>" + html.EscapeString(b) + "</p>") ``` `html.EscapeString` escapes `<`, `>`, `&`, `'`, `"`, which is sufficient for an element-text context. Apply the same change to v2's `(*Ctx).Format()`. ## Proof of Concept ```bash # Create project directory mkdir fiber-xss-poc && cd fiber-xss-poc # Initialize Go module go mod init fiber-xss-poc # Install Fiber v3 go get github.com/gofiber/fiber/v3 # Create the PoC file cat > main.go << 'EOF' package main import ( "github.com/gofiber/fiber/v3" ) type User struct { ID int `json:"id"` Name string `json:"name"` } func main() { app := fiber.New() app.Get("/api/user", func(c fiber.Ctx) error { user := User{ ID: 1, Name: c.Query("name", "anonymous"), } return c.AutoFormat(user) }) app.Listen(":3000") } EOF # Run it go run main.go } ``` Benign JSON ```bash curl -s 'http://127.0.0.1:3000/api/user?name=Alice' -H 'Accept: application/json' {"id":1,"name":"Alice"} ``` HTML sink enables XSS ```bash curl -s 'http://127.0.0.1:3000/api/user?name=<script>alert(document.domain)</script>' -H 'Accept: text/html' <p>{1 <script>alert(document.domain)</script>}</p> ```

CVE-2026-42554 Affected Github.com/gofiber/fiber/v3 Versions

2 component(s)
Fixed Versions:
3.2.02.52.13
Product / Package Ecosystem Affected Versions Fixed Version
github.com/gofiber/fiber/v3
Go
< 3.2.0
3.2.0
github.com/gofiber/fiber/v2
Go
< 2.52.13
2.52.13

References

Frequently Asked Questions

What is CVE-2026-42554?
CVE-2026-42554 is a security vulnerability in Github.com/gofiber/fiber/v3 involving Fiber vulnerable to XSS in AutoFormat Content Negotiation under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Github.com/gofiber/fiber/v3 versions are affected?
Affected versions include releases prior to 3.2.0, 2.52.13 across affected packages: github.com/gofiber/fiber/v3, github.com/gofiber/fiber/v2.
What version fixes CVE-2026-42554?
Upgrading to 3.2.0, 2.52.13 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/gofiber/fiber/v3 affected?
Yes, github.com/gofiber/fiber/v3 is affected in releases prior to 3.2.0. Upgrade your dependency to 3.2.0 or later.
Is github.com/gofiber/fiber/v2 affected?
Yes, github.com/gofiber/fiber/v2 is affected in releases prior to 2.52.13. Upgrade your dependency to 2.52.13 or later.
What CWE is associated with CVE-2026-42554?
CVE-2026-42554 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check Go dependencies for CVE-2026-42554?
Run the dependency tree command: 'inspect dependencies for github.com/gofiber/fiber/v3'. 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-qjv7-627w-8qjv",
  "modified" : "2026-05-13T14:20:14Z",
  "published" : "2026-05-05T20:13:23Z",
  "aliases" : [ "CVE-2026-42554" ],
  "summary" : "Fiber vulnerable to XSS in AutoFormat Content Negotiation",
  "details" : "## Summary\n\n**Description**\n\nA Cross-Site Scripting (CWE-79) vulnerability in Go Fiber allows a remote attacker to inject arbitrary HTML/JavaScript by supplying `Accept: text/html` on any request whose handler passes attacker-influenced data to the AutoFormat() feature. This affects `github.com/gofiber/fiber/v3` (`DefaultRes.AutoFormat`) through version 3.1.0 and `github.com/gofiber/fiber/v2` (`Ctx.Format`) through version 2.52.12. \n\nThe developer opts into content negotiation by calling AutoFormat(), but does not opt into raw HTML emission for a particular request; Fiber chooses that branch from attacker-controlled Accept. Five of the six branches of the same method already escape. `JSON`, `XML`, `MsgPack`, and `CBOR` all route through encoders that neutralize markup; the txt branch emits `text/plain` and cannot execute. The html branch is the sole outlier in a method whose name (`AutoFormat`) and symmetrical structure actively telegraph \"safe, format-agnostic reply.\"\n\n## Details\nThe issue resides in `res.go` within `(*DefaultRes).AutoFormat()`. The method negotiates against the request Accept header, selects one of `html | json | txt | xml | msgpack | cbor`, and serializes the caller-supplied body accordingly.\n\nThe \"html\" branch concatenates the stringified body directly into HTML markup with no output encoding:\n- `accept` comes from `r.c.Accepts(...)`, i.e. is fully attacker-controlled. An attacker can force the \"html\" branch on any `AutoFormat()` call regardless of which format the developer tested against.\n- `b` is produced from `body` via direct assignment (`string` / `[]byte`) or `fmt.Sprintf(\"%v\", body)`. No `html.EscapeString` is applied.\n- The resulting string is sent as `text/html; charset=utf-8`, so browsers render it as active HTML.\n\n```go\n// res.go\nfunc (r *DefaultRes) AutoFormat(body any) error {\n\n    accept := r.c.DefaultReq.Accepts(\"html\", \"json\", \"txt\", \"xml\", \"msgpack\", \"cbor\")\n\n    r.Type(accept)\n    var b string\n    switch val := body.(type) {\n    case string:\n        b = val\n    case []byte:\n        b = r.c.app.toString(val)\n    default:\n        b = fmt.Sprintf(\"%v\", val)\n    }\n\n    switch accept {\n    case \"txt\":\n        return r.SendString(b)\n    case \"json\":\n        return r.JSON(body)\n    case \"xml\":\n        return r.XML(body)\n    case \"html\":\n        return r.SendString(\"<p>\" + b + \"</p>\")\n    case \"msgpack\":\n        return r.MsgPack(body)\n    case \"cbor\":\n        return r.CBOR(body)\n    }\n    return r.SendString(b)\n}\n```\n## Impact\n\nThis impacts all current v3 releases ≤ 3.1.0 containing `DefaultRes.AutoFormat`, and all current v2 releases ≤ 2.52.12 where the identical `\"<p>\" + b + \"</p>\"` construction exists in `(*Ctx).Format()`. Exploitation requires that an application call `c.AutoFormat(v)` where `v` (or a field stringified by `%v`) contains request-influenced data.\n\nA handler that uses `AutoFormat()` to serve multiple representations of the same data can be turned into an HTML XSS sink when the client sends `Accept: text/html`, even if the developer only tested the JSON path.\n\nThis may result in:\n- **Reflected XSS** in the application's origin via any request-derived value reaching `AutoFormat`.\n- **Stored XSS** where the reflected value originates from persisted input later passed to `AutoFormat`.\n\n## Proposed Patch\n\nThe injection surface is `r.Type(\"html\")` followed by `r.SendString(b)` with unescaped caller data, where it constructs markup on the caller's behalf around a value whose HTML-ness the caller did not declare. A few options:\n- `AutoFormat()` should treat `body` as data, not markup, in the `\"html\"` branch and escape it before concatenating it into the framework-generated `<p>` wrapper. Callers that need raw negotiated HTML should use `Format()` with an explicit HTML handler.\n- Introduce a sibling method that escapes, leave `AutoFormat` alone for backward compatibility.\n\nHTML-escape the value in the \"html\" branch before concatenating it into the `<p>` wrapper.\n```go\nimport \"html\"\n\n// ...\ncase \"html\":\n    return r.SendString(\"<p>\" + html.EscapeString(b) + \"</p>\")\n```\n\n`html.EscapeString` escapes `<`, `>`, `&`, `'`, `\"`, which is sufficient for an element-text context. Apply the same change to v2's `(*Ctx).Format()`.\n\n## Proof of Concept\n\n```bash\n# Create project directory\nmkdir fiber-xss-poc && cd fiber-xss-poc\n\n# Initialize Go module\ngo mod init fiber-xss-poc\n\n# Install Fiber v3\ngo get github.com/gofiber/fiber/v3\n\n# Create the PoC file\ncat > main.go << 'EOF'\npackage main\n\nimport (\n\t\"github.com/gofiber/fiber/v3\"\n)\n\ntype User struct {\n\tID   int    `json:\"id\"`\n\tName string `json:\"name\"`\n}\n\nfunc main() {\n\tapp := fiber.New()\n\t\n\tapp.Get(\"/api/user\", func(c fiber.Ctx) error {\n\t\tuser := User{\n\t\t\tID:   1,\n\t\t\tName: c.Query(\"name\", \"anonymous\"),\n\t\t}\n\t\treturn c.AutoFormat(user)\n\t})\n\n\tapp.Listen(\":3000\")\n}\nEOF\n\n# Run it\ngo run main.go\n}\n```\n\nBenign JSON\n```bash\ncurl -s 'http://127.0.0.1:3000/api/user?name=Alice' -H 'Accept: application/json'\n{\"id\":1,\"name\":\"Alice\"}\n```\n\nHTML sink enables XSS\n```bash\ncurl -s 'http://127.0.0.1:3000/api/user?name=<script>alert(document.domain)</script>' -H 'Accept: text/html'\n<p>{1 <script>alert(document.domain)</script>}</p>\n```",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/gofiber/fiber/v3"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.2.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.1.0"
    }
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/gofiber/fiber/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.52.13"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.52.12"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/gofiber/fiber/security/advisories/GHSA-qjv7-627w-8qjv"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-42554"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/gofiber/fiber"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-05-05T20:13:23Z",
    "nvd_published_at" : "2026-05-11T23:19:48Z"
  }
}