Vulnerabilities in pkg:golang/github.com/go-chi/chi/v4/middleware

PACKAGE
Advisory Summary

GHSA-rjr7-jggh-pgcp is a HIGH chi's realip middleware allows ip vulnerability (CWE-348: Use of Less Trusted Source) affecting Github.com/go chi/chi/middleware libraries in the Go ecosystem. The issue involves chi's realip middleware allows ip spoofing via unvalidated x-forwarded-for header. Remediation is available by upgrading affected packages to version 5.3.0.

2 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:golang/github.com/go-chi/chi/v4/middleware

2 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:golang/github.com/go-chi/chi/v4/middleware. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-rjr7-jggh-pgcp - HIGH chi's RealIP Middleware allows IP spoofing via unvalidated X-Forwarded-For header
GHSA-9g5q-2w5x-hmxf - HIGH chi Middleware Vulnerable to Potential IP Spoofing via `X-Forwarded-For` Header in `Request.RemoteAddr` Resolution

GHSA-rjr7-jggh-pgcp at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-rjr7-jggh-pgcp
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-348: Use of Less Trusted Source
Affected Product Github.com/go chi/chi/middleware
Package Ecosystem Go
Published Date
Last Updated

How to Fix GHSA-rjr7-jggh-pgcp

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-rjr7-jggh-pgcp, 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-348: Use of Less Trusted Source, where the product has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack. 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 realip middleware in go-chi/chi trusts headers like x-forwarded-for without checking them, so attackers can fake their ip and bypass rate limits or access controls ### Details the vuln is in middleware/realip.go , the realIP() function pulls IPs straight from client headers and replaces r.RemoteAddr without checking if the request came from a trusted proxy ```go func realIP(r *http.Request) string { var ip string if tcip := r.Header.Get(trueClientIP); tcip != "" { ip = tcip // controlled by attacker } else if xrip := r.Header.Get(xRealIP); xrip != "" { ip = xrip // controlled by attacker } else if xff := r.Header.Get(xForwardedFor); xff != "" { ip, _, _ = strings.Cut(xff, ",") // controlled by attacker } // ... return ip } ``` no trusted proxy cidr check in place, any client can send these headers ### PoC create a server with chi and use realip middleware ```go package main import ( "fmt" "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) func main() { r := chi.NewRouter() r.Use(middleware.RealIP) r.Get("/admin", func(w http.ResponseWriter, r *http.Request) { // ip-based access control got bypassed if r.RemoteAddr == "127.0.0.1" { w.Write([]byte("SECRET ADMIN DATA")) return } http.Error(w, "Forbidden", 403) }) http.ListenAndServe(":8080", r) } ``` spoofed the ip to bypass access control ```bash curl -H "X-Forwarded-For: 127.0.0.1" http://localhost:8080/admin ``` ### Impact - ip-based access control bypass lets attackers reach restricted endpoints - rate limiting bypass lets attackers avoid limits by rotating spoofed ips - audit logs show fake ips picked by attacker instead of real ones - attackers can get around geo ip restrictions ## Remediation Recommendation validate proxy cidr first before trusting forwarded ip headers ```go // add your reverse proxy ip addresses here var trustedProxies = []net.IPNet{ {IP: net.ParseIP("10.0.0.0"), Mask: net.CIDRMask(8, 32)}, {IP: net.ParseIP("172.16.0.0"), Mask: net.CIDRMask(12, 32)}, {IP: net.ParseIP("192.168.0.0"), Mask: net.CIDRMask(16, 32)}, } func isTrustedProxy(ip net.IP) bool { for _, cidr := range trustedProxies { if cidr.Contains(ip) { return true } } return false } ```

GHSA-rjr7-jggh-pgcp 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
≤ 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-rjr7-jggh-pgcp?
GHSA-rjr7-jggh-pgcp is a security vulnerability in Github.com/go chi/chi/middleware involving chi's RealIP Middleware allows IP spoofing via unvalidated X-Forwarded-For header under CWE-348: Use of Less Trusted Source.
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-rjr7-jggh-pgcp?
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-rjr7-jggh-pgcp?
GHSA-rjr7-jggh-pgcp is classified under CWE-348: Use of Less Trusted Source (The product has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack.).
How can I check Go dependencies for GHSA-rjr7-jggh-pgcp?
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-rjr7-jggh-pgcp",
  "modified" : "2026-06-25T18:19:15Z",
  "published" : "2026-06-25T18:19:15Z",
  "aliases" : [ ],
  "summary" : "chi's RealIP Middleware allows IP spoofing via unvalidated X-Forwarded-For header",
  "details" : "### Summary\nrealip middleware in go-chi/chi trusts headers like x-forwarded-for without checking them, so attackers can fake their ip and bypass rate limits or access controls\n\n### Details\n\nthe vuln is in middleware/realip.go , the realIP() function pulls IPs straight from client headers and replaces r.RemoteAddr without checking if the request came from a trusted proxy\n\n```go\nfunc realIP(r *http.Request) string {\n    var ip string\n    if tcip := r.Header.Get(trueClientIP); tcip != \"\" {\n        ip = tcip  // controlled by attacker\n    } else if xrip := r.Header.Get(xRealIP); xrip != \"\" {\n        ip = xrip  // controlled by attacker\n    } else if xff := r.Header.Get(xForwardedFor); xff != \"\" {\n        ip, _, _ = strings.Cut(xff, \",\")  // controlled by attacker\n    }\n    // ...\n    return ip\n}\n```\n\nno trusted proxy cidr check in place, any client can send these headers\n\n### PoC\n\ncreate a server with chi and use realip middleware\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n    \"github.com/go-chi/chi/v5\"\n    \"github.com/go-chi/chi/v5/middleware\"\n)\n\nfunc main() {\n    r := chi.NewRouter()\n    r.Use(middleware.RealIP)\n\n    r.Get(\"/admin\", func(w http.ResponseWriter, r *http.Request) {\n        // ip-based access control got bypassed\n        if r.RemoteAddr == \"127.0.0.1\" {\n            w.Write([]byte(\"SECRET ADMIN DATA\"))\n            return\n        }\n        http.Error(w, \"Forbidden\", 403)\n    })\n\n    http.ListenAndServe(\":8080\", r)\n}\n```\n\nspoofed the ip to bypass access control\n\n```bash\ncurl -H \"X-Forwarded-For: 127.0.0.1\" http://localhost:8080/admin\n```\n\n\n### Impact\n\n- ip-based access control bypass lets attackers reach restricted endpoints\n- rate limiting bypass lets attackers avoid limits by rotating spoofed ips\n- audit logs show fake ips picked by attacker instead of real ones\n- attackers can get around geo ip restrictions\n\n## Remediation Recommendation\n\nvalidate proxy cidr first before trusting forwarded ip headers\n\n```go\n// add your reverse proxy ip addresses here\nvar trustedProxies = []net.IPNet{\n       {IP: net.ParseIP(\"10.0.0.0\"), Mask: net.CIDRMask(8, 32)},\n    {IP: net.ParseIP(\"172.16.0.0\"), Mask: net.CIDRMask(12, 32)},\n    {IP: net.ParseIP(\"192.168.0.0\"), Mask: net.CIDRMask(16, 32)},\n}\n\nfunc isTrustedProxy(ip net.IP) bool {\n    for _, cidr := range trustedProxies {\n        if cidr.Contains(ip) {\n            return true\n        }\n    }\n    return false\n}\n```",
  "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"
      }, {
        "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-rjr7-jggh-pgcp"
  }, {
    "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-290", "CWE-348" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-25T18:19:15Z",
    "nvd_published_at" : null
  }
}