GHSA-RJR7-JGGH-PGCP

GHSA-RJR7-JGGH-PGCP is a high-severity security vulnerability in github.com/go-chi/chi/middleware (go), affecting versions <= 1.5.5. It is fixed in 5.3.0.

Does this CVE actually affect you?

Kodem shows which CVEs are reachable and running in your applications, so you fix what's exploitable, not just what's listed.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Runtime intelligence, not another scanner.

Summary

chi's RealIP Middleware allows IP spoofing via unvalidated X-Forwarded-For header

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

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

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

curl -H "X-Forwarded-For: 127.0.0.1" http://localhost:8080/admin

Remediation Recommendation

validate proxy cidr first before trusting forwarded ip headers

// 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
}

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

Affected versions

github.com/go-chi/chi/middleware (<= 1.5.5) github.com/go-chi/chi/v2/middleware (<= 2.1.1) github.com/go-chi/chi/v3/middleware (<= 3.3.5) github.com/go-chi/chi/v4/middleware (<= 4.1.3) github.com/go-chi/chi/v5/middleware (< 5.3.0)

Security releases

github.com/go-chi/chi/v5/middleware → 5.3.0 (go)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

Already deployed Kodem?

See it in your environmentNew to Kodem? Get a demo →

Remediation advice

Upgrade github.com/go-chi/chi/v5/middleware to 5.3.0 or later to resolve this vulnerability.

Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.

Frequently Asked Questions

  1. What is GHSA-RJR7-JGGH-PGCP? GHSA-RJR7-JGGH-PGCP is a high-severity security vulnerability in github.com/go-chi/chi/middleware (go), affecting versions <= 1.5.5. It is fixed in 5.3.0.
  2. Which packages are affected by GHSA-RJR7-JGGH-PGCP?
    • github.com/go-chi/chi/middleware (go) (versions <= 1.5.5)
    • github.com/go-chi/chi/v2/middleware (go) (versions <= 2.1.1)
    • github.com/go-chi/chi/v3/middleware (go) (versions <= 3.3.5)
    • github.com/go-chi/chi/v4/middleware (go) (versions <= 4.1.3)
    • github.com/go-chi/chi/v5/middleware (go) (versions < 5.3.0)
  3. Is there a fix for GHSA-RJR7-JGGH-PGCP? Yes. GHSA-RJR7-JGGH-PGCP is fixed in 5.3.0. Upgrade to this version or later.
  4. Is GHSA-RJR7-JGGH-PGCP exploitable, and should I be worried? Whether GHSA-RJR7-JGGH-PGCP is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  5. What actually determines whether GHSA-RJR7-JGGH-PGCP is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  6. How do I fix GHSA-RJR7-JGGH-PGCP? Upgrade github.com/go-chi/chi/v5/middleware to 5.3.0 or later.

Other vulnerabilities in github.com/go-chi/chi/middleware

Stop the waste.
Protect your environment with Kodem.