Skip to content

Commit

Permalink
Fix open redirect check for more cases (go-gitea#25143)
Browse files Browse the repository at this point in the history
If redirect_to parameter has set value starting with `\\example.com`
redirect will be created with header `Location: /\\example.com` that
will redirect to example.com domain.
  • Loading branch information
lafriks authored and GiteaBot committed Jun 8, 2023
1 parent 82a8c26 commit 8d23c1e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/context/context_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (ctx *Context) RedirectToFirst(location ...string) {
continue
}

// Unfortunately browsers consider a redirect Location with preceding "//" and "/\" as meaning redirect to "http(s)://REST_OF_PATH"
// Unfortunately browsers consider a redirect Location with preceding "//", "\\" and "/\" as meaning redirect to "http(s)://REST_OF_PATH"
// Therefore we should ignore these redirect locations to prevent open redirects
if len(loc) > 1 && loc[0] == '/' && (loc[1] == '/' || loc[1] == '\\') {
if len(loc) > 1 && (loc[0] == '/' || loc[0] == '\\') && (loc[1] == '/' || loc[1] == '\\') {
continue
}

Expand Down

0 comments on commit 8d23c1e

Please sign in to comment.