GHSA-9g5q-2w5x-hmxf: Github.com/go chi/chi/middleware Chi Middleware Vulnerable To Potential Vulnerability

HIGH
CWE-346
Published
Advisory Summary

GHSA-9g5q-2w5x-hmxf is a HIGH chi middleware vulnerable to potential vulnerability (CWE-346: Origin Validation Error) affecting Github.com/go chi/chi/middleware libraries in the Go ecosystem. The issue involves chi middleware vulnerable to potential ip spoofing via `x-forwarded-for` header in `request.remoteaddr` resolution. Remediation is available by upgrading affected packages to version 5.3.0.

GHSA-9g5q-2w5x-hmxf at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-9g5q-2w5x-hmxf
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-346: Origin Validation Error
Affected Product Github.com/go chi/chi/middleware
Package Ecosystem Go
Published Date
Last Updated

How to Fix GHSA-9g5q-2w5x-hmxf

To remediate this vulnerability, upgrade all affected Github.com/go chi/chi/middleware 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/go-chi/chi/middleware fixed: Latest secure release
Upgrade github.com/go-chi/chi/middleware to Latest secure release
github.com/go-chi/chi/v2/middleware fixed: Latest secure release
Upgrade github.com/go-chi/chi/v2/middleware to Latest secure release
github.com/go-chi/chi/v3/middleware fixed: Latest secure release
Upgrade github.com/go-chi/chi/v3/middleware to Latest secure release
github.com/go-chi/chi/v4/middleware fixed: Latest secure release
Upgrade github.com/go-chi/chi/v4/middleware to Latest secure release
github.com/go-chi/chi/v5/middleware fixed: 5.3.0
Upgrade github.com/go-chi/chi/v5/middleware to 5.3.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 github.com/go-chi/chi/middleware

How to Check if You Are Affected

To determine whether your application is affected by GHSA-9g5q-2w5x-hmxf, inspect your project dependencies for Github.com/go chi/chi/middleware:

inspect dependencies for github.com/go-chi/chi/middleware

Analyze the terminal output to locate any version of Github.com/go chi/chi/middleware in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.3.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-346: Origin Validation Error, where the product does not properly verify that the source of data or communication is valid. In Github.com/go chi/chi/middleware, 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 The vulnerability allows the `Request.RemoteAddr` to be spoofed when determining the request source IP via the `X-Forwarded-For` header. This could result in misidentification of the request source and potentially compromise access control and logging integrity. ### Details Currently, the `RealIP()` implementation splits the `X-Forwarded-For` header by `,` and uses the first IP. https://github.com/go-chi/chi/blob/v5.1.0/middleware/realip.go#L50-L54 However, relying on the first IP in the `X-Forwarded-For` header is insecure because it can be manipulated by attackers to falsify the source IP. Malicious Case: 1. A malicious client sends a request with a forged IP in the X-Forwarded-For header: `X-Forwarded-For: <forged-ip>` 2. The proxy appends the actual client’s IP and forwards the request: `X-Forwarded-For: <forged-ip>,<client-ip>` 3. If the server always uses the first IP, it becomes vulnerable to IP spoofing. Ideally, the implementation should verify IPs starting from the end of the `X-Forwarded-For` header value, skipping trusted IPs within the system, and using the first untrusted IP as the actual client IP. For example, the `labstack/echo` web framework processes the `X-Forwarded-For` header by checking IPs from the end, skipping trusted IPs, and using the first untrusted IP as the client's ip. https://github.com/labstack/echo/blob/v4.13.2/ip.go#L261-L273 ### PoC #### 1. Run the Go application with the following code: ```go package main import ( "fmt" "log" "net/http" "github.com/go-chi/chi/v5/middleware" ) func main() { // Set handler to print the remote address handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln( w, fmt.Sprintf("remote addr: %s (want 192.0.2.1)", r.RemoteAddr), ) }) // Use RealIP middleware log.Fatal(http.ListenAndServe(":8080", middleware.RealIP(handler))) } ``` #### 2. Send a request to the server using curl with a manipulated X-Forwarded-For header: ``` $ curl localhost:8080 -H 'X-Forwarded-For: 192.0.2.2, 192.0.2.1' remote addr: 192.0.2.2 (want 192.0.2.1) ``` ### Impact This vulnerability can lead to a request source IP spoofing issue, which may allow attackers to bypass access controls or falsify request logs. It primarily affects systems that rely on X-Forwarded-For to determine the actual client IP, particularly in scenarios where intermediary proxies or load balancers are involved.

GHSA-9g5q-2w5x-hmxf Affected Github.com/go chi/chi/middleware Versions

5 component(s)
Fixed Versions:
5.3.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/go-chi/chi/middleware
Go
≥ 0.9.0
≤ 1.5.5
github.com/go-chi/chi/v2/middleware
Go
≤ 2.1.1
github.com/go-chi/chi/v3/middleware
Go
≤ 3.3.5
github.com/go-chi/chi/v4/middleware
Go
≤ 4.1.3
github.com/go-chi/chi/v5/middleware
Go
< 5.3.0
5.3.0

References

Frequently Asked Questions

What is GHSA-9g5q-2w5x-hmxf?
GHSA-9g5q-2w5x-hmxf is a security vulnerability in Github.com/go chi/chi/middleware involving chi Middleware Vulnerable to Potential IP Spoofing via `X-Forwarded-For` Header in `Request.RemoteAddr` Resolution under CWE-346: Origin Validation Error.
Which Github.com/go chi/chi/middleware versions are affected?
Affected versions include releases prior to 5.3.0 across affected packages: github.com/go-chi/chi/middleware, github.com/go-chi/chi/v2/middleware, github.com/go-chi/chi/v3/middleware, github.com/go-chi/chi/v4/middleware, github.com/go-chi/chi/v5/middleware.
What version fixes GHSA-9g5q-2w5x-hmxf?
Upgrading to 5.3.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/go-chi/chi/middleware affected?
Yes, github.com/go-chi/chi/middleware is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
Is github.com/go-chi/chi/v2/middleware affected?
Yes, github.com/go-chi/chi/v2/middleware is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What CWE is associated with GHSA-9g5q-2w5x-hmxf?
GHSA-9g5q-2w5x-hmxf is classified under CWE-346: Origin Validation Error (The product does not properly verify that the source of data or communication is valid.).
How can I check Go dependencies for GHSA-9g5q-2w5x-hmxf?
Run the dependency tree command: 'inspect dependencies for github.com/go-chi/chi/middleware'. 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-9g5q-2w5x-hmxf",
  "modified" : "2026-06-25T18:18:56Z",
  "published" : "2026-06-25T18:18:56Z",
  "aliases" : [ ],
  "summary" : "chi Middleware Vulnerable to Potential IP Spoofing via `X-Forwarded-For` Header in `Request.RemoteAddr` Resolution",
  "details" : "### Summary\nThe vulnerability allows the `Request.RemoteAddr` to be spoofed when determining the request source IP via the `X-Forwarded-For` header. This could result in misidentification of the request source and potentially compromise access control and logging integrity.\n\n### Details\nCurrently, the `RealIP()` implementation splits the `X-Forwarded-For` header by `,` and uses the first IP.\nhttps://github.com/go-chi/chi/blob/v5.1.0/middleware/realip.go#L50-L54\n\nHowever, relying on the first IP in the `X-Forwarded-For` header is insecure because it can be manipulated by attackers to falsify the source IP.\n\nMalicious Case:\n1. A malicious client sends a request with a forged IP in the X-Forwarded-For header: `X-Forwarded-For: <forged-ip>`\n2. The proxy appends the actual client’s IP and forwards the request: `X-Forwarded-For: <forged-ip>,<client-ip>`\n3. If the server always uses the first IP, it becomes vulnerable to IP spoofing.\n\nIdeally, the implementation should verify IPs starting from the end of the `X-Forwarded-For` header value, skipping trusted IPs within the system, and using the first untrusted IP as the actual client IP.\n\nFor example, the `labstack/echo` web framework processes the `X-Forwarded-For` header by checking IPs from the end, skipping trusted IPs, and using the first untrusted IP as the client's ip.\nhttps://github.com/labstack/echo/blob/v4.13.2/ip.go#L261-L273\n\n### PoC\n#### 1. Run the Go application with the following code:\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"net/http\"\n\n    \"github.com/go-chi/chi/v5/middleware\"\n)\n\nfunc main() {\n    // Set handler to print the remote address\n    handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n        fmt.Fprintln(\n            w,\n            fmt.Sprintf(\"remote addr: %s (want 192.0.2.1)\", r.RemoteAddr),\n        )\n    })\n    // Use RealIP middleware\n    log.Fatal(http.ListenAndServe(\":8080\", middleware.RealIP(handler)))\n}\n```\n#### 2. Send a request to the server using curl with a manipulated X-Forwarded-For header:\n```\n$ curl localhost:8080 -H 'X-Forwarded-For: 192.0.2.2, 192.0.2.1'\nremote addr: 192.0.2.2 (want 192.0.2.1)\n```\n\n### Impact\nThis vulnerability can lead to a request source IP spoofing issue, which may allow attackers to bypass access controls or falsify request logs. It primarily affects systems that rely on X-Forwarded-For to determine the actual client IP, particularly in scenarios where intermediary proxies or load balancers are involved.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N/E:P"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/go-chi/chi/middleware"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.9.0"
      }, {
        "last_affected" : "1.5.5"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/go-chi/chi/v2/middleware"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "2.1.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/go-chi/chi/v3/middleware"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "3.3.5"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/go-chi/chi/v4/middleware"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "4.1.3"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/go-chi/chi/v5/middleware"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "5.3.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/go-chi/chi/security/advisories/GHSA-9g5q-2w5x-hmxf"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/go-chi/chi"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/go-chi/chi/releases/tag/v5.3.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-346" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-25T18:18:56Z",
    "nvd_published_at" : null
  }
}