Skip to content

Commit

Permalink
fix removing double slash prefix in raw req path
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Jul 19, 2023
1 parent 0828339 commit addf40b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions v2/pkg/protocols/http/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ func Parse(request string, inputURL *urlutil.URL, unsafe, disablePathAutomerge b
return nil, err
}

// edge case for double slash in path
// uri part in raw req '//CFIDE/wizards/common/utils.cfc' (valid uri without scheme)
// for ^ex url.Parse results in scheme="",host="CFIDE",path="/wizards/common/utils.cfc"
startWithDoubleSlash := strings.HasPrefix(rawrequest.Path, "//")
_, hasHost := rawrequest.Headers["Host"]
var pathPrefix string
if startWithDoubleSlash && hasHost {
if u, err := urlutil.Parse(rawrequest.Path); err == nil && u.Host != "" {
pathPrefix = "//" + u.Host
}
}

switch {
// If path is empty do not tamper input url (see doc)
// can be omitted but makes things clear
Expand Down Expand Up @@ -83,7 +95,7 @@ func Parse(request string, inputURL *urlutil.URL, unsafe, disablePathAutomerge b
}
unsafeRelativePath = cloned.GetRelativePath()
}
rawrequest.Path = cloned.GetRelativePath()
rawrequest.Path = pathPrefix + cloned.GetRelativePath()
rawrequest.UnsafeRawBytes = bytes.Replace(rawrequest.UnsafeRawBytes, []byte(prevPath), []byte(unsafeRelativePath), 1)

default:
Expand All @@ -95,7 +107,7 @@ func Parse(request string, inputURL *urlutil.URL, unsafe, disablePathAutomerge b
if parseErr != nil {
return nil, errorutil.NewWithTag("raw", "could not automergepath for template path %v", rawrequest.Path).Wrap(parseErr)
}
rawrequest.Path = cloned.GetRelativePath()
rawrequest.Path = pathPrefix + cloned.GetRelativePath()
}

if !unsafe {
Expand Down

0 comments on commit addf40b

Please sign in to comment.