Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoded path will be decoded by middleware.StripSlashes and mismatch routers #798

Open
wolfogre opened this issue Mar 2, 2023 · 0 comments · May be fixed by #799
Open

Encoded path will be decoded by middleware.StripSlashes and mismatch routers #798

wolfogre opened this issue Mar 2, 2023 · 0 comments · May be fixed by #799

Comments

@wolfogre
Copy link

wolfogre commented Mar 2, 2023

To reproduce it:

package main

import (
	"net/http"
	"time"

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

func main() {
	go server()
	time.Sleep(time.Second)

	_, _ = http.Get("http://localhost:3000/abc%2Fefg")  // 200
	_, _ = http.Get("http://localhost:3000/abc%2Fefg/") // 404
	_, _ = http.Get("http://localhost:3000/abcefg/")    // 200
}

func server() {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Use(middleware.StripSlashes)
	r.Get("/{name}", func(w http.ResponseWriter, r *http.Request) {
		_, _ = w.Write([]byte("welcome"))
	})
	_ = http.ListenAndServe(":3000", r)
}

And the log:

2023/03/02 17:39:42 "GET http://localhost:3000/abc%2Fefg HTTP/1.1" from [::1]:49977 - 200 7B in 15.338µs
2023/03/02 17:39:42 "GET http://localhost:3000/abc%2Fefg/ HTTP/1.1" from [::1]:49978 - 404 19B in 5.918µs
2023/03/02 17:39:42 "GET http://localhost:3000/abcefg/ HTTP/1.1" from [::1]:49979 - 200 7B in 6.94µs

However, /abc%2Fefg/ should return 200.

@wolfogre wolfogre changed the title Encoded path will be decoded by middleware.StripSlashes and mismatch routers Encoded path will be decoded by middleware.StripSlashes and mismatch routers Mar 2, 2023
@wolfogre wolfogre linked a pull request Mar 2, 2023 that will close this issue
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 a pull request may close this issue.

1 participant