Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 806033e

Browse files
committed
Fix headers+stats for acceptance case
1 parent 4d4aada commit 806033e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/resty/iprepd.lua

+16-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function _M.new(options)
6363
end
6464

6565
function _M.check(self, ip)
66+
ngx.req.set_header('X-Foxsec-IP-Reputation-Below-Threshold', 'false')
67+
ngx.req.set_header('X-Foxsec-Block', 'false')
6668
if self.whitelist then
6769
if iputils.ip_in_cidrs(ip, self.whitelist) then
6870
return
@@ -76,20 +78,27 @@ function _M.check(self, ip)
7678
ngx.req.set_header('X-Foxsec-IP-Reputation-Below-Threshold', 'true')
7779
ngx.req.set_header('X-Foxsec-Block', 'true')
7880
if self.statsd then
79-
self.statsd.incr("iprepd.status.rejected")
81+
self.statsd.incr("iprepd.status.below_threshold")
8082
end
8183

8284
if self.dont_block == 1 then
83-
ngx.log(ngx.ERR, '[logonly] ' .. ip .. ' rejected with a reputation of ' .. reputation)
85+
ngx.log(ngx.ERR, ip .. ' is below threshold with a reputation of ' .. reputation)
8486
else
8587
ngx.log(ngx.ERR, ip .. ' rejected with a reputation of ' .. reputation)
88+
if self.statsd then
89+
self.statsd.incr("iprepd.status.rejected")
90+
end
8691
ngx.exit(ngx.HTTP_FORBIDDEN)
8792
end
93+
else
94+
if self.statsd then
95+
self.statsd.incr("iprepd.status.accepted")
96+
end
8897
end
98+
99+
return
89100
end
90101

91-
ngx.req.set_header('X-Foxsec-IP-Reputation-Below-Threshold', 'false')
92-
ngx.req.set_header('X-Foxsec-Block', 'false')
93102
if self.statsd then
94103
self.statsd.incr("iprepd.status.accepted")
95104
end
@@ -125,6 +134,9 @@ function _M.get_reputation(self, ip)
125134
self.cache:set(ip, 100, self.cache_ttl)
126135
else
127136
ngx.log(ngx.ERR, 'iprepd responded with a ' .. resp.status .. ' http status code')
137+
if self.statsd then
138+
self.statsd.incr("iprepd.err." .. resp.status)
139+
end
128140
if self.cache_errors == 1 then
129141
ngx.log(ngx.ERR, 'cache_errors is enabled, setting reputation of ' .. ip .. ' to 100 within the cache')
130142
self.cache:set(ip, 100, self.cache_ttl)

0 commit comments

Comments
 (0)