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

Misuse of mount results in infinite loop when calling unregistered method #663

Closed
carmo-evan opened this issue Oct 7, 2021 · 5 comments
Closed

Comments

@carmo-evan
Copy link

When misusing Mount like so:

func main() {
	r := chi.NewRouter()
	mux := r.Group(func(r chi.Router) {
		r.Use(middleware.Logger)
		r.Group(func(r chi.Router) {
			r.Get("/products", printPath)
		})
		r.Mount("/", r)
	})
	if err := http.ListenAndServe(":3004", mux); err != nil {
		log.Fatal(err)
	}
}

func printPath(w http.ResponseWriter, r *http.Request) {
	log.Println(r.URL.Path)
}

Calling unregistered methods on the /products path (POST /products, PUT /products, etc) results in Chi entering an infinite loop. This could be used maliciously by an attacker. The expectation is that either this should still work as intended, or an error should be thrown.

@j1cs
Copy link

j1cs commented Nov 11, 2022

this happens to me too. there's any advice to avoid this?

@VojtechVitek
Copy link
Contributor

remove r.Mount("/", r) - it's mounting the very same router on top of itself, thus entering the infinite loop

@VojtechVitek
Copy link
Contributor

technically, we could check for pointer equality in the Mount() method and panic()

thoughts?

@pkieltyka
Copy link
Member

I don’t think we should do anything.. you can write an infinite loop in Go easily too

@j1cs
Copy link

j1cs commented Nov 15, 2022

I added a prefix like /v1and the loop stopped.

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

No branches or pull requests

4 participants