mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
backports from main
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -1165,7 +1165,9 @@ func (s *httpdServer) redirectToWebPath(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *httpdServer) isStaticFileURL(r *http.Request) bool {
|
||||
// The StripSlashes causes infinite redirects at the root path if used with http.FileServer.
|
||||
// We also don't strip paths with more than one trailing slash, see #1434
|
||||
func (s *httpdServer) mustStripSlash(r *http.Request) bool {
|
||||
var urlPath string
|
||||
rctx := chi.RouteContext(r.Context())
|
||||
if rctx != nil && rctx.RoutePath != "" {
|
||||
@@ -1173,7 +1175,8 @@ func (s *httpdServer) isStaticFileURL(r *http.Request) bool {
|
||||
} else {
|
||||
urlPath = r.URL.Path
|
||||
}
|
||||
return !strings.HasPrefix(urlPath, webOpenAPIPath) && !strings.HasPrefix(urlPath, webStaticFilesPath)
|
||||
return !strings.HasSuffix(urlPath, "//") && !strings.HasPrefix(urlPath, webOpenAPIPath) &&
|
||||
!strings.HasPrefix(urlPath, webStaticFilesPath) && !strings.HasPrefix(urlPath, acmeChallengeURI)
|
||||
}
|
||||
|
||||
func (s *httpdServer) initializeRouter() {
|
||||
@@ -1223,7 +1226,7 @@ func (s *httpdServer) initializeRouter() {
|
||||
}
|
||||
s.router.Use(middleware.GetHead)
|
||||
// StripSlashes causes infinite redirects at the root path if used with http.FileServer
|
||||
s.router.Use(middleware.Maybe(middleware.StripSlashes, s.isStaticFileURL))
|
||||
s.router.Use(middleware.Maybe(middleware.StripSlashes, s.mustStripSlash))
|
||||
|
||||
s.router.NotFound(s.notFoundHandler)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user