Skip to content

Trailing slash middleware open redirect #1771

Closed
@GeoffreyFrogeye

Description

@GeoffreyFrogeye

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions