Closed
Description
Issue Description
When using middleware.AddTrailingSlashWithConfig
(resp middleware.RemoveTrailingSlashWithConfig
) with a RedirectCode
configured, it is possible to create open redirects with addresses like this one: http://my_echo_app.com/%5Cevil_website_com
(resp http://my_echo_app.com/%5Cevil_website_com/
).
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Steps to reproduce
- Compile example code and run
- Open http://localhost:1323/%5Cexample.com
Expected behaviour
Obtain a 404 error, or anything as long as I stay on localhost:1232.
Actual behaviour
Being redirected to example.com
.
Working code to debug
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
e.Use(middleware.AddTrailingSlashWithConfig(middleware.TrailingSlashConfig{
RedirectCode: http.StatusMovedPermanently,
}))
e.Logger.Fatal(e.Start(":1323"))
}
This is basically the Full Go Example stripped down with the Custom Configuration example of the documentation on the Trailing Slash Middleware.
This also works with RemoveTrailingSlashWithConfig
and the link http://localhost:1323/%5Cexample.com/.
Version/commit
Whatever is fetched by go get github.com/labstack/echo/v4
today (sorry, not super familiar with Go).