@@ -62,10 +62,16 @@ func (s *Server) checkAuthLimit(ip string) error {
6262 attempt .Count = 0
6363 }
6464
65+ if s .isWhitelisted (ip ) {
66+ return nil
67+ }
6568 return nil
6669}
6770
6871func (s * Server ) recordAuthFailure (ip string ) {
72+ if s .isWhitelisted (ip ) {
73+ return
74+ }
6975 s .authAttemptsMu .Lock ()
7076 defer s .authAttemptsMu .Unlock ()
7177
@@ -95,6 +101,9 @@ func (s *Server) recordAuthSuccess(ip string) {
95101}
96102
97103func (s * Server ) recordScanAttempt (ip , path string ) {
104+ if s .isWhitelisted (ip ) {
105+ return
106+ }
98107 s .scanAttemptsMu .Lock ()
99108 defer s .scanAttemptsMu .Unlock ()
100109
@@ -104,10 +113,8 @@ func (s *Server) recordScanAttempt(ip, path string) {
104113 s .scanAttempts [ip ] = attempt
105114 }
106115
107- if ! attempt .Paths [path ] {
108- attempt .Paths [path ] = true
109- attempt .Count ++
110- }
116+ attempt .Paths [path ] = true
117+ attempt .Count ++
111118
112119 if attempt .Count >= 10 {
113120 attempt .LockoutBy = time .Now ().Add (15 * time .Minute )
@@ -167,6 +174,35 @@ func (s *Server) hasAccess(user *config.User, mount string) bool {
167174 return exists
168175}
169176
177+ func (s * Server ) isWhitelisted (ipStr string ) bool {
178+ host , _ , err := net .SplitHostPort (ipStr )
179+ if err != nil {
180+ host = ipStr
181+ }
182+
183+ ip := net .ParseIP (host )
184+ if ip == nil {
185+ return false
186+ }
187+
188+ if ip .IsLoopback () {
189+ return true
190+ }
191+
192+ for _ , whitelisted := range s .Config .WhitelistedIPs {
193+ if strings .Contains (whitelisted , "/" ) {
194+ _ , ipnet , err := net .ParseCIDR (whitelisted )
195+ if err == nil && ipnet .Contains (ip ) {
196+ return true
197+ }
198+ }
199+ if whitelisted == host {
200+ return true
201+ }
202+ }
203+ return false
204+ }
205+
170206func (s * Server ) isCSRFSafe (r * http.Request ) bool {
171207 if r .Method != http .MethodPost {
172208 return true
@@ -200,6 +236,9 @@ func (s *Server) isCSRFSafe(r *http.Request) bool {
200236}
201237
202238func (s * Server ) isBanned (ipStr string ) bool {
239+ if s .isWhitelisted (ipStr ) {
240+ return false
241+ }
203242 host , _ , err := net .SplitHostPort (ipStr )
204243 if err != nil {
205244 host = ipStr
0 commit comments