@@ -21,7 +21,7 @@ func (data EndpointsMiddleware) Use() http.Handler {
2121 blockedEndpoints := settings .BLOCKED_ENDPOINTS
2222 allowedEndpoints := settings .ALLOWED_ENDPOINTS
2323
24- if blockedEndpoints == nil {
24+ if blockedEndpoints == nil && allowedEndpoints == nil {
2525 blockedEndpoints = getSettings ("*" ).BLOCKED_ENDPOINTS
2626 }
2727
@@ -38,25 +38,37 @@ func (data EndpointsMiddleware) Use() http.Handler {
3838}
3939
4040func isBlocked (endpoint string , allowed []string , blocked []string ) bool {
41- var result bool
42-
4341 if blocked == nil {
44- return false
42+ blocked = [] string {}
4543 }
4644
4745 if allowed == nil {
48- return true
46+ allowed = [] string {}
4947 }
5048
51- isBlocked := slices .ContainsFunc (blocked , func (try string ) bool {
49+ isExplicitlyBlocked := slices .ContainsFunc (blocked , func (try string ) bool {
5250 return strings .HasPrefix (endpoint , try )
5351 })
5452
5553 isExplictlyAllowed := slices .ContainsFunc (allowed , func (try string ) bool {
5654 return strings .HasPrefix (endpoint , try )
5755 })
5856
59- result = isBlocked && ! isExplictlyAllowed
57+ // Block all except explicitly Allowed
58+ if len (blocked ) == 0 && len (allowed ) != 0 {
59+ return ! isExplictlyAllowed
60+ }
61+
62+ // Allow all except explicitly Blocked
63+ if len (allowed ) == 0 && len (blocked ) != 0 {
64+ return isExplicitlyBlocked
65+ }
66+
67+ // Excplicitly Blocked except excplictly Allowed
68+ if len (blocked ) != 0 && len (allowed ) != 0 {
69+ return isExplicitlyBlocked && ! isExplictlyAllowed
70+ }
6071
61- return result
72+ // Block all
73+ return true
6274}
0 commit comments