Skip to content

Commit

Permalink
fix(proxy): ignore Referer if got redirect (close #3996)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Mar 31, 2023
1 parent 0c5820a commit 3b07c72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
31 changes: 3 additions & 28 deletions pkg/gowebdav/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ func (c *Client) Read(path string) ([]byte, error) {
}

func (c *Client) Link(path string) (string, http.Header, error) {
method := "HEAD"
url := PathEscape(Join(c.root, path))
r, err := http.NewRequest(method, url, nil)
method := "GET"
u := PathEscape(Join(c.root, path))
r, err := http.NewRequest(method, u, nil)

if err != nil {
return "", nil, newPathErrorErr("Link", path, err)
Expand All @@ -366,31 +366,6 @@ func (c *Client) Link(path string) (string, http.Header, error) {
if c.interceptor != nil {
c.interceptor(method, r)
}

rs, err := c.c.Do(r)
if err != nil {
return "", nil, newPathErrorErr("Link", path, err)
}

if rs.StatusCode == 401 {
wwwAuthenticateHeader := strings.ToLower(rs.Header.Get("Www-Authenticate"))
if strings.Contains(wwwAuthenticateHeader, "digest") {
c.authMutex.Lock()
c.auth = &DigestAuth{auth.User(), auth.Pass(), digestParts(rs)}
c.auth.Authorize(r, method, path)
c.authMutex.Unlock()
} else if strings.Contains(wwwAuthenticateHeader, "basic") {
c.authMutex.Lock()
c.auth = &BasicAuth{auth.User(), auth.Pass()}
c.auth.Authorize(r, method, path)
c.authMutex.Unlock()
} else {
return "", nil, newPathError("Authorize", c.root, rs.StatusCode)
}
} else if rs.StatusCode > 400 {
return "", nil, newPathError("Authorize", path, rs.StatusCode)
}

return r.URL.String(), r.Header, nil
}

Expand Down
10 changes: 9 additions & 1 deletion server/common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ import (
log "github.com/sirupsen/logrus"
)

var HttpClient = &http.Client{}
var HttpClient = &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
req.Header.Del("Referer")
return nil
},
}

func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error {
// read data with native
Expand Down

0 comments on commit 3b07c72

Please sign in to comment.