Browse Source

Added white blacklist function to webdav

tobychui 3 years ago
parent
commit
22f629e1d2
2 changed files with 9 additions and 0 deletions
  1. 1 0
      mod/storage/ftp/drivers.go
  2. 8 0
      mod/storage/webdav/webdav.go

+ 1 - 0
mod/storage/ftp/drivers.go

@@ -64,6 +64,7 @@ func (m mainDriver) AuthUser(cc ftp.ClientContext, user string, pass string) (ft
 			//Check if the request is from a blacklisted ip range
 			allowAccess, err := m.userHandler.GetAuthAgent().ValidateLoginIpAccess(cc.RemoteAddr().String())
 			if !allowAccess {
+				accessOK = false
 				return nil, err
 			}
 		}

+ 8 - 0
mod/storage/webdav/webdav.go

@@ -229,6 +229,14 @@ func (s *Server) HandleRequest(w http.ResponseWriter, r *http.Request) {
 
 	//validate username and password
 	authAgent := s.userHandler.GetAuthAgent()
+
+	//Validate request origin
+	allowAccess, err := authAgent.ValidateLoginRequest(w, r)
+	if !allowAccess {
+		log.Println("Someone from " + r.RemoteAddr + " try to log into " + username + " WebDAV endpoint but got rejected: " + err.Error())
+		http.Error(w, err.Error(), http.StatusUnauthorized)
+		return
+	}
 	passwordValid, rejectionReason := authAgent.ValidateUsernameAndPasswordWithReason(username, password)
 	if !passwordValid {
 		authAgent.Logger.LogAuthByRequestInfo(username, r.RemoteAddr, time.Now().Unix(), false, "webdav")