Skip to content

Update module github.com/go-chi/chi/v5 to v5.4.0 [SECURITY] - #74

Open
renovate[bot] wants to merge 1 commit into
masterfrom
renovate/go-github.com-go-chi-chi-v5-vulnerability
Open

renovate[bot] wants to merge 1 commit into
masterfrom
renovate/go-github.com-go-chi-chi-v5-vulnerability

Conversation

@renovate

@renovate renovate Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

This PR contains the following updates:

Package Change Age Confidence
github.com/go-chi/chi/v5 v5.2.2 → v5.4.0 age confidence

chi has an open redirect vulnerability in the RedirectSlashes middleware

CVE-2025-69725 / GHSA-mqqf-5wvp-8fh8

More information

Details

Summary

The RedirectSlashes function in middleware/strip.go does not perform correct input validation and can lead to an open redirect vulnerability.

Details

The RedirectSlashes function performs a Trim to all forward slash (/) characters, while prepending a single one at the begining of the path (Line 52).

However, it does not trim backslashes (\).

File: middleware/strip.go
41: func RedirectSlashes(next http.Handler) http.Handler {
...
51: 			// Trim all leading and trailing slashes (e.g., "//evil.com", "/some/path//")
52: 			path = "/" + strings.Trim(path, "/")
...
62: }

Also, from version 5.2.2 onwards the RedirectSlashes function does not take into consideration the Host Header in the redirect response returned. This was done in order to combat another [vulnerability](https://redirect.github.com/go-chi/chi/security/advisories/GHSA-vrw8-fxc6-2r93).

The above make it possible for a response in the following form:

HTTP/1.1 301 Moved Permanently
Location: /\evil.com

The /\evil.com will be transformed by most browsers (Chrome, Firefox, etc. not Safari) into //evil.com which is a protocol relative URL and will result in a redirect to evil.com, essentially making it an open redirect vulnerability.

PoC

A minimal working example can be seen below.

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.RedirectSlashes)

	r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
	})

	fmt.Println("Server starting on port 8081...")
	if err := http.ListenAndServe(":8081", r); err != nil {
		fmt.Printf("Error starting server: %v\n", err)
	}
}

And when we request the path /\evil.com (needs a second backslash or URL encoding in the terminal), the HTTP Redirect Location is just /\evil.com without any domain/Host information.

$ curl -I  localhost:8081/\\evil.com/
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: /\evil.com
$ curl -I  localhost:8081/%5Cevil.com/
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: /\evil.com

This opened in a browser (Chrome, Firefox) will result in a transformation to //evil.com which in turn will result in a redirect to evil.com.
image-20250829115619807

image-20250829115632067
Impact

This essentially consists of an open redirect vulnerability, provided that victim users use the most popular browsers (Chrome, Firefox, etc. It does not work in e.g. Safari).

The attacker can construct a malicious URL on a domain of a legitimate website and send it to the victim user. The victim users thinking that they will click on a legitimate website's URL, they will unknowingly be reidrected to an attacker controlled website.

This can lead to credential theft if the victim gets redirected to a phishing website, to malware that is hosted on the attacker controlled website etc. Also, it has a greate reputation / business impact for the affected legitimate website.

In order to exploit this vulnerability the attacker does not need to be authenticated or have ay other priviledge / knowledge regarding the affected application.

CVSS Score: 4.7 (Medium)

Severity

  • CVSS Score: 4.7 / 10 (Medium)
  • Vector String: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:N/A:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


chi: Client IP spoofing in ClientIPFromXFF via X-Forwarded-For

CVE-2026-114437 / GHSA-j6qf-3m9c-vwj3

More information

Details

Summary

ClientIPFromXFF skips any X-Forwarded-For entry in a configured trusted CIDR but never verifies that the direct TCP peer in http.Request.RemoteAddr belongs to that CIDR. A client that can reach the Go server directly can therefore append a trusted-looking proxy address and choose the client IP returned by middleware.GetClientIP.

The attack is remote and requires one unauthenticated HTTP request with no user interaction (AV:N/AC:L/PR:N/UI:N). It changes security decisions and exposes one protected handler within the same application (S:U/C:L/I:L); no availability loss was observed (A:N).

Preconditions: The application uses ClientIPFromXFF and makes the origin server reachable by an anonymous client outside the configured trusted-proxy CIDRs. No victim interaction is required.

  1. Send GET /admin directly to the origin with no X-Forwarded-For header.
  2. Observe a 403 Forbidden response and an empty derived client IP.
  3. Repeat the request with X-Forwarded-For: 10.0.0.7, 198.51.100.42.
  4. Observe 200 OK and client-ip="10.0.0.7". Expected: the untrusted direct peer prevents the forwarding chain from being accepted.
Details

The vulnerable code is ClientIPFromXFF in middleware/client_ip.go, lines 93-116 at the tested revision. It calls walkXFF with only the attacker-controlled header, skips every entry that matches a trusted prefix, and stores the first remaining address:

walkXFF(r.Header[xForwardedForHeader], func(v string) bool {
	ip, ok := parseHeaderAddr(v)
	if !ok {
		return true
	}
	if inAnyPrefix(ip, prefixes) {
		return false
	}
	found = ip
	return true
})

The function does not parse r.RemoteAddr before this walk. Consequently, the configured CIDRs identify trusted strings inside X-Forwarded-For, but do not establish that the immediate sender is one of those trusted proxies.

Proof of concept

Using Go 1.24 or later, create and run this minimal application against the tested revision:

mkdir chi-clientip-poc
cd chi-clientip-poc
go mod init clientip-poc
go get github.com/go-chi/chi/v5@167e1e3bd039d060696b99c8da4e876ae04f42c1
cat > main.go <<'EOF'
package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
)

const allowedIP = "10.0.0.7"

func main() {
	r := chi.NewRouter()
	r.Use(middleware.ClientIPFromXFF("198.51.100.0/24"))
	r.Get("/admin", func(w http.ResponseWriter, r *http.Request) {
		clientIP := middleware.GetClientIP(r.Context())
		if clientIP != allowedIP {
			http.Error(w, fmt.Sprintf("denied: tcp-peer=%q client-ip=%q", r.RemoteAddr, clientIP), http.StatusForbidden)
			return
		}
		fmt.Fprintf(w, "allowed: tcp-peer=%q client-ip=%q\n", r.RemoteAddr, clientIP)
	})

	log.Print("listening on http://127.0.0.1:3001")
	log.Fatal(http.ListenAndServe("127.0.0.1:3001", r))
}
EOF
go run .

The no-header control was rejected:

$ curl --http1.1 -i http://127.0.0.1:3001/admin
HTTP/1.1 403 Forbidden
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Tue, 06 Oct 2026 15:46:27 GMT
Content-Length: 48

denied: tcp-peer="127.0.0.1:54416" client-ip=""

Adding the forged chain authorized the same direct client:

$ curl --http1.1 -i -H 'X-Forwarded-For: 10.0.0.7, 198.51.100.42' http://127.0.0.1:3001/admin
HTTP/1.1 200 OK
Date: Tue, 06 Oct 2026 15:46:33 GMT
Content-Length: 57
Content-Type: text/plain; charset=utf-8

allowed: tcp-peer="127.0.0.1:54417" client-ip="10.0.0.7"
Impact

I made an anonymous direct connection from 127.0.0.1, supplied a header that ended in a different trusted-proxy CIDR, and caused the application to treat my client IP as the allowlisted 10.0.0.7. This changed the authorization decision from 403 Forbidden to 200 OK for the protected handler.

Severity

  • CVSS Score: 4.8 / 10 (Medium)
  • Vector String: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


Release Notes

go-chi/chi (github.com/go-chi/chi/v5)

v5.4.0

Compare Source

What's Changed
New Contributors

Full Changelog: go-chi/chi@v5.3.2...v5.4.0

v5.3.2

Compare Source

What's Changed

  • feat(middleware): add text/markdown, text/csv, text/vtt to default compressible types by @​VojtechVitek in #​1151
  • docs: deployment recipe for middleware.ClientIPFromXFFTrustedProxies() by @​VojtechVitek in #​1111
  • fix: don't drop handlers that collide with a Mount()/Route() pattern by @​VojtechVitek in #​1148
  • Don't duplicate methods in Allow: header for 405 responses by @​flimzy in #​1029
  • fix(middleware): reject catch-all compress wildcards by @​VojtechVitek in #​1156
    • middleware.NewCompressor(level, "/*") never worked and silently compressed nothing. Instead of turning it into a compress-everything catch-all (as proposed in #​868 and #​1121), we decided to reject both "/" and "/*" at construction and panic. Compressing every response wastes CPU on already-compressed types (zip, jpeg, png), which is why the middleware keeps a curated default list. Users should pass explicit content types.

Full Changelog: go-chi/chi@v5.3.1...v5.3.2

v5.3.1

Compare Source

What's Changed

New Contributors

Full Changelog: go-chi/chi@v5.3.0...v5.3.1

v5.3.0

Compare Source

What's Changed

New Contributors

SECURITY: middleware.ClientIP, a replacement for middleware.RealIP

@​VojtechVitek submitted PR #​967, which introduces middleware.ClientIP — a replacement for middleware.RealIP that closes the three open spoofing advisories:

It also addresses issues outlined at:

middleware.RealIP is deprecated in this PR with pointers to the new API.

The deprecation only adds a // Deprecated: doc comment; the function keeps working for backward compatibility.

Why a new middleware (not "fix RealIP in place")

RealIP has two unfixable design choices: it mutates r.RemoteAddr, and it tries to be a one-size-fits-all default by walking a hard-coded list of headers any client can supply. Per adam-p's "The perils of the 'real' client IP" (which calls chi out by name on this), there is no safe default — the user must pick their trust source explicitly.

The new API

Four middlewares, two accessors. Pick exactly one middleware based on your
infrastructure, read the result with one of the two accessors:

// One of the four. There is no safe default — pick exactly one.
func ClientIPFromHeader(trustedHeader string) func(http.Handler) http.Handler
func ClientIPFromXFF(trustedIPPrefixes ...string) func(http.Handler) http.Handler
func ClientIPFromXFFTrustedProxies(numTrustedProxies int) func(http.Handler) http.Handler
func ClientIPFromRemoteAddr(h http.Handler) http.Handler

// Read the result.
func GetClientIP(ctx context.Context) string         // for logs, rate-limit keys
func GetClientIPAddr(ctx context.Context) netip.Addr // for typed work

Example usage:

// Pick a single ClientIP middleware based on your deployment
  
// Cloudflare.
r.Use(middleware.ClientIPFromHeader("CF-Connecting-IP"))

// Nginx with ngx_http_realip_module.
r.Use(middleware.ClientIPFromHeader("X-Real-IP"))

// Apache with mod_remoteip.
r.Use(middleware.ClientIPFromHeader("X-Client-IP"))

// AWS CloudFront, or any proxy fleet with known CIDRs.
r.Use(middleware.ClientIPFromXFF(
    "13.32.0.0/15",   // CloudFront IPv4
    "52.46.0.0/18",   // CloudFront IPv4
    "2600:9000::/28", // CloudFront IPv6
))

// Behind exactly 2 trusted proxies with dynamic IPs (autoscaling pools,
// ephemeral containers, dynamic CDN edges).
r.Use(middleware.ClientIPFromXFFTrustedProxies(2))

// Server directly on the public internet, no proxy in front.
r.Use(middleware.ClientIPFromRemoteAddr)

And in your handler or downstream middleware:

clientIP := middleware.GetClientIP(r.Context())
// log it, use it as a rate-limit key, etc.

Thanks to @​adam-p, @​c2h5oh, @​rezmoss, @​Saku0512, @​convto, @​Dirbaio, @​jawnsy, @​lrstanley, @​mfridman, @​n33pm, @​pkieltyka for the prior discussions, detailed reviews, advisory reports, and test contributions that shaped this PR.

Full Changelog: go-chi/chi@v5.2.5...v5.3.0

v5.2.5

Compare Source

What's Changed

New Contributors

Full Changelog: go-chi/chi@v5.2.3...v5.2.5

v5.2.4

Compare Source

What's Changed

New Contributors

Full Changelog: go-chi/chi@v5.2.3...v5.2.4

v5.2.3

Compare Source

What's Changed

New Contributors

Full Changelog: go-chi/chi@v5.2.2...v5.2.3


Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate
renovate Bot requested a review from a team as a code owner June 20, 2026 07:43
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Aug 10, 2026
@renovate renovate Bot closed this Aug 10, 2026
@renovate
renovate Bot deleted the renovate/go-github.com-go-chi-chi-v5-vulnerability branch August 10, 2026 08:33
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Aug 10, 2026
@renovate renovate Bot reopened this Aug 10, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch 2 times, most recently from f1f0c61 to 4207a99 Compare August 10, 2026 15:56
@sonarqubecloud

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Aug 29, 2026
@renovate renovate Bot closed this Aug 29, 2026
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Aug 29, 2026
@renovate renovate Bot reopened this Aug 29, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch 2 times, most recently from 4207a99 to 9dcbd89 Compare August 29, 2026 12:53
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Aug 29, 2026
@renovate renovate Bot closed this Aug 29, 2026
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Aug 29, 2026
@renovate renovate Bot reopened this Aug 29, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch from 9dcbd89 to 34a09a8 Compare August 29, 2026 21:45
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Aug 31, 2026
@renovate renovate Bot closed this Aug 31, 2026
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Aug 31, 2026
@renovate renovate Bot reopened this Aug 31, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch 2 times, most recently from 34a09a8 to 23eac11 Compare August 31, 2026 19:43
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Sep 1, 2026
@renovate renovate Bot closed this Sep 1, 2026
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Sep 2, 2026
@renovate renovate Bot reopened this Sep 2, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch 2 times, most recently from 23eac11 to 140eec3 Compare September 2, 2026 01:40
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Sep 3, 2026
@renovate renovate Bot closed this Sep 3, 2026
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] - autoclosed Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Sep 3, 2026
@renovate renovate Bot reopened this Sep 3, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch 2 times, most recently from 140eec3 to 7e70390 Compare September 3, 2026 05:04
@renovate renovate Bot changed the title Update module github.com/go-chi/chi/v5 to v5.2.4 [SECURITY] Update module github.com/go-chi/chi/v5 to v5.4.0 [SECURITY] Oct 28, 2026
@renovate
renovate Bot force-pushed the renovate/go-github.com-go-chi-chi-v5-vulnerability branch from 7e70390 to 61e0ada Compare October 28, 2026 23:59
@renovate

renovate Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

ℹ️ Artifact update notice

File name: go.mod

In order to perform the update(s) described in the table above, Renovate ran the go get command, which resulted in the following additional change(s):

  • The go directive was updated for compatibility reasons

Details:

Package Change
go 1.22 -> 1.24

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants