wafris 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 919967ec8203e767f77202e17964dbcfd21f60422bb91bd61b806575886c5dbf
4
- data.tar.gz: ffe9b975f6613e1742c90b6335e85f53769d439d32f014517487142a97edb37e
3
+ metadata.gz: 7590310d437ae2574c37907b8c285e236b3e22686769cb2a5043a1e8a4c6171b
4
+ data.tar.gz: 4bbc22d46692a7505b37845a5c39d8b5197441c6dc8b8bf61b12622fa690d9b6
5
5
  SHA512:
6
- metadata.gz: 4efff1ae48ec5417bf9917c0a3b7f073064216ee718eed8246f0b993397454ab4296a2e27ac48a1289f31abe20ca277d32f4bc848978a7c4dd88d04ee08c4cdb
7
- data.tar.gz: 274d14a646e0e706a940d16c53adb050045df1593056f012ba47666af402c37e38a055038fa2074a73e32e73cc49bcf5f5d943c16e7bff71bd3d79d47e8aaadc
6
+ metadata.gz: 89063fcce8dcd2f35c10651bccc9de6b517f2925194493673fa6e2fa672eba4a6c3bfc1444624c957a70cd3d3b401cbc743ad13a0d8981fd5f18bcbba8eb02c8
7
+ data.tar.gz: 61b32244a41efdca5cffa93f753e8bed5fdbf23849fb4f0f8773083493c3bb26e0a9cc23480584d41e674a1cb0fa749faafa428af2c741ee9d12c5fb8078c1d4
@@ -73,13 +73,18 @@ local function ip_in_cidr_range(cidr_set, ip_decimal_lexical)
73
73
  end
74
74
  end
75
75
 
76
+ local function escapePattern(s)
77
+ local patternSpecials = "[%^%$%(%)%%%.%[%]%*%+%-%?]"
78
+ return s:gsub(patternSpecials, "%%%1")
79
+ end
80
+
76
81
  local function match_by_pattern(property_abbreviation, property_value)
77
82
  local hash_name = "rules-blocked-" .. property_abbreviation
78
83
 
79
84
  local patterns = redis.call('HKEYS', hash_name)
80
85
 
81
86
  for _, pattern in ipairs(patterns) do
82
- if string.find(property_value, pattern) then
87
+ if string.find(string.lower(property_value), string.lower(escapePattern(pattern))) then
83
88
  return pattern
84
89
  end
85
90
  end
@@ -14,10 +14,10 @@ module Wafris
14
14
  )
15
15
  @redis_pool_size = 20
16
16
 
17
- puts "[Wafris] attempting firewall connection via REDIS_URL."
17
+ puts "[Wafris] attempting firewall connection via REDIS_URL." unless LogSuppressor.suppress_logs?
18
18
  create_settings
19
19
  rescue Redis::CannotConnectError
20
- puts "[Wafris] firewall disabled. Cannot connect to REDIS_URL. Will attempt Wafris.configure if it exists."
20
+ puts "[Wafris] firewall disabled. Cannot connect to REDIS_URL. Will attempt Wafris.configure if it exists." unless LogSuppressor.suppress_logs?
21
21
  end
22
22
 
23
23
  def connection_pool
@@ -30,7 +30,7 @@ module Wafris
30
30
  'version', Wafris::VERSION,
31
31
  'client', 'ruby',
32
32
  'redis-host', 'heroku')
33
- puts "[Wafris] firewall enabled. Connected to Redis. Ready to process requests. Set rules at: https://wafris.org/hub"
33
+ puts "[Wafris] firewall enabled. Connected to Redis. Ready to process requests. Set rules at: https://wafris.org/hub" unless LogSuppressor.suppress_logs?
34
34
  end
35
35
 
36
36
  def core_sha
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wafris
4
+ class LogSuppressor
5
+ def self.suppress_logs?
6
+ suppressed_environments.include?(current_environment)
7
+ end
8
+
9
+ def self.suppressed_environments
10
+ ['test'] + (ENV['CI'] ? ['CI'] : [])
11
+ end
12
+
13
+ def self.current_environment
14
+ if defined?(Rails)
15
+ Rails.env
16
+ else
17
+ ENV['RACK_ENV'] || 'development'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -33,7 +33,7 @@ module Wafris
33
33
  [403, {}, ['Blocked']]
34
34
  end
35
35
  rescue StandardError => e
36
- puts "[Wafris] Redis connection error: #{e.message}. Request passed without rules check."
36
+ puts "[Wafris] Redis connection error: #{e.message}. Request passed without rules check." unless LogSuppressor.suppress_logs?
37
37
  @app.call(env)
38
38
  end
39
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wafris
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.2"
5
5
  end
data/lib/wafris.rb CHANGED
@@ -6,6 +6,7 @@ require 'redis'
6
6
 
7
7
  require 'wafris/configuration'
8
8
  require 'wafris/middleware'
9
+ require 'wafris/log_suppressor'
9
10
 
10
11
  require 'wafris/railtie' if defined?(Rails::Railtie)
11
12
 
@@ -13,10 +14,10 @@ module Wafris
13
14
  class << self
14
15
  def configure
15
16
  yield configuration
16
- puts "[Wafris] attempting firewall connection via Wafris.configure initializer."
17
+ puts "[Wafris] attempting firewall connection via Wafris.configure initializer." unless LogSuppressor.suppress_logs?
17
18
  configuration.create_settings
18
19
  rescue Redis::CannotConnectError
19
- puts "[Wafris] firewall disabled. Cannot connect via Wafris.configure. Please check your configuration settings."
20
+ puts "[Wafris] firewall disabled. Cannot connect via Wafris.configure. Please check your configuration settings." unless LogSuppressor.suppress_logs?
20
21
  end
21
22
 
22
23
  def configuration
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wafris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micahel Buckbee
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-07 00:00:00.000000000 Z
12
+ date: 2023-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: connection_pool
@@ -188,6 +188,7 @@ files:
188
188
  - lib/lua/dist/wafris_core.lua
189
189
  - lib/wafris.rb
190
190
  - lib/wafris/configuration.rb
191
+ - lib/wafris/log_suppressor.rb
191
192
  - lib/wafris/middleware.rb
192
193
  - lib/wafris/railtie.rb
193
194
  - lib/wafris/version.rb