Skip to content

Commit

Permalink
www redirects are too broad (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbell authored and vishr committed Feb 15, 2019
1 parent 8716acb commit 5aec1b2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions middleware/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type RedirectConfig struct {
// 2) return the appropriate redirect url.
type redirectLogic func(scheme, host, uri string) (ok bool, url string)

const www = "www"
const www = "www."

// DefaultRedirectConfig is the default Redirect middleware config.
var DefaultRedirectConfig = RedirectConfig{
Expand Down Expand Up @@ -60,7 +60,7 @@ func HTTPSWWWRedirect() echo.MiddlewareFunc {
// See `HTTPSWWWRedirect()`.
func HTTPSWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
return redirect(config, func(scheme, host, uri string) (ok bool, url string) {
if ok = scheme != "https" && host[:3] != www; ok {
if ok = scheme != "https" && host[:4] != www; ok {
url = "https://www." + host + uri
}
return
Expand All @@ -80,7 +80,7 @@ func HTTPSNonWWWRedirect() echo.MiddlewareFunc {
func HTTPSNonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
return redirect(config, func(scheme, host, uri string) (ok bool, url string) {
if ok = scheme != "https"; ok {
if host[:3] == www {
if host[:4] == www {
host = host[4:]
}
url = "https://" + host + uri
Expand All @@ -101,7 +101,7 @@ func WWWRedirect() echo.MiddlewareFunc {
// See `WWWRedirect()`.
func WWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
return redirect(config, func(scheme, host, uri string) (ok bool, url string) {
if ok = host[:3] != www; ok {
if ok = host[:4] != www; ok {
url = scheme + "://www." + host + uri
}
return
Expand All @@ -120,7 +120,7 @@ func NonWWWRedirect() echo.MiddlewareFunc {
// See `NonWWWRedirect()`.
func NonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
return redirect(config, func(scheme, host, uri string) (ok bool, url string) {
if ok = host[:3] == www; ok {
if ok = host[:4] == www; ok {
url = scheme + "://" + host[4:] + uri
}
return
Expand Down

0 comments on commit 5aec1b2

Please sign in to comment.