auth-centric-firewall 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e287e19f12735e9c687cb6f79450e78abd78cc28e6b5c9c423444606a3b019fb
4
- data.tar.gz: b3865f72602036e7f9e02280c6bcfb48e8df7f5fdcf1a37cd2dd1588b8599b88
3
+ metadata.gz: 6b0b8e31fe34345f545a3c4896d91eca03c805ace909dd71ba6286f15038770b
4
+ data.tar.gz: 20ca9c8cea11b5266bd62f8beecf732c2301cd7b0ea553e59c64f95b3876b9d1
5
5
  SHA512:
6
- metadata.gz: e725fadcc1372ca2363bfc0f726b8e07a70999ba37574e53e7a674988e2a1977431454c8a8d2be31760ccf0795083aea066a1df6a7b3f587e18695ecb6c5b844
7
- data.tar.gz: bd2fc5072fa375ac835f5bc3be163df97a41c1bdd21f01481e45e81e1167a5c800a98e4dfe114eca06081d5de0172eb6d502658f85bf481c4d11743806848d62
6
+ metadata.gz: 6d6767cccf9c465b35b2cdbbeb7fb98851eb02489f4ddb153a265f2af894d9cb2e20b5d5759149180744d603903b0f78c46d59bd4a400a87865a3d226d2202fb
7
+ data.tar.gz: a4bf16a35820835621ae8243c06cd467e4ac5cebfa64e3a7f3174712b952408b92d969b17b0b46edfddd67aa34b76689e8315e43db2715064be877bfe212316e
data/.rubocop.yml CHANGED
@@ -14,6 +14,7 @@ Layout/IndentationConsistency:
14
14
  Naming/PredicateName:
15
15
  AllowedMethods:
16
16
  - has_access?
17
+ - is_ipv6?
17
18
  NamePrefix:
18
19
  - is_
19
20
  - has_
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ## [Released]
2
2
 
3
- ## [0.1.1] - 2025-05-17
3
+ ## [0.2.0] - 2025-09-13
4
+
5
+ - Update RBS
6
+ - Refactor common codes
7
+ - Retrieve Captcha
8
+ - Verify Captcha code
9
+
10
+ ## [0.1.1, 0.1.2] - 2025-05-17
4
11
 
5
12
  - Try to find real I.P
6
13
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Captcha
6
+ module CheckCode
7
+ def verify_code?(id:, code:)
8
+ return true unless enabled?
9
+
10
+ payload = {
11
+ security_captcha: {
12
+ ip: @ip_address,
13
+ code:,
14
+ session_id: @session_id
15
+ }
16
+ }
17
+
18
+ http = HTTP
19
+ .timeout(timeout_seconds)
20
+ .headers(apikey:)
21
+ .post(check_code_path(id), json: payload)
22
+
23
+ case http.status
24
+ when 202
25
+ return true
26
+ when 404, 406
27
+ return false
28
+ else
29
+ raise Error, "#{http.status}: #{http.body}"
30
+ end
31
+ rescue HTTP::TimeoutError
32
+ false
33
+ end
34
+
35
+ def check_code_path(id)
36
+ [host, "api/v1/security_captchas/#{id}/check_code"].join('/')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Captcha
6
+ module Retrieve
7
+ def retrieve_captcha
8
+ return true unless enabled?
9
+
10
+ payload = {
11
+ security_captcha: {
12
+ ip: @ip_address,
13
+ session_id: @session_id
14
+ }
15
+ }
16
+
17
+ http = HTTP
18
+ .timeout(timeout_seconds)
19
+ .headers(apikey:)
20
+ .post(find_or_create_path, json: payload)
21
+
22
+ case http.status
23
+ when 200..202
24
+ JSON.parse(http.body)['data']['attributes'].except('session_id', 'ip')
25
+ when 422
26
+ raise Error, http.body.to_s
27
+ else
28
+ raise Error, "#{http.status}: #{http.body}"
29
+ end
30
+ rescue HTTP::TimeoutError
31
+ true
32
+ end
33
+
34
+ def find_or_create_path
35
+ [host, 'api/v1/security_captchas'].join('/')
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Common
6
+ module Settings
7
+ def host
8
+ @host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
9
+ end
10
+
11
+ def apikey
12
+ @apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
13
+ end
14
+
15
+ def timeout_seconds
16
+ @timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
17
+ end
18
+
19
+ def enabled?
20
+ @enabled ||= %w[true 1 yes on enabled].include?(ENV['AUTH_CENTRIC_ENABLED']&.downcase)
21
+ end
22
+
23
+ def ip(request)
24
+ @ip ||= InternetProtocol.new(request).ip
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -7,11 +7,12 @@ module Auth
7
7
  class CaptureRequest
8
8
  def initialize(request)
9
9
  @request = request
10
+ nil
10
11
  end
11
12
 
12
13
  def as_json
13
14
  {
14
- ip:,
15
+ ip: ip(@request),
15
16
  domain:,
16
17
  url:,
17
18
  query_string:,
@@ -24,10 +25,6 @@ module Auth
24
25
  }
25
26
  end
26
27
 
27
- def ip
28
- @request.env['HTTP_X_REAL_IP'] || @request.env['HTTP_X_FORWARDED_FOR'] || @request.remote_ip
29
- end
30
-
31
28
  def domain
32
29
  @request.domain || @request.headers.env['HTTP_HOST']
33
30
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Firewall
6
+ # Try to find the IPv4
7
+ class InternetProtocol
8
+ require 'ipaddr'
9
+
10
+ def initialize(request)
11
+ @request = request
12
+ end
13
+
14
+ def ip
15
+ return @ip unless @ip.blank?
16
+
17
+ @ip = @request.env['HTTP_X_REAL_IP'] || @request.env['HTTP_X_FORWARDED_FOR'] || @request.remote_ip
18
+ return @ip unless @ip.include?(',')
19
+
20
+ @ip.split(',').each do |ip|
21
+ next if is_ipv6?(ip.strip)
22
+
23
+ @ip = ip.strip
24
+ break
25
+ end
26
+
27
+ @ip
28
+ end
29
+
30
+ def is_ipv6?(ip_string)
31
+ IPAddr.new(ip_string).ipv6?
32
+ rescue IPAddr::AddressFamilyError, IPAddr::InvalidAddressError
33
+ false
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,7 +3,7 @@
3
3
  module Auth
4
4
  module Centric
5
5
  module Firewall
6
- VERSION = '0.1.1'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -5,12 +5,16 @@ require 'http'
5
5
 
6
6
  require_relative 'firewall/version'
7
7
  require_relative 'firewall/constants'
8
+ require_relative 'common/settings'
8
9
  require_relative 'firewall/capture_request'
10
+ require_relative 'firewall/internet_protocol'
9
11
 
10
12
  module Auth
11
13
  module Centric
12
14
  # Client firewall module
13
15
  module Firewall
16
+ include Auth::Centric::Common::Settings
17
+
14
18
  class Error < StandardError; end
15
19
 
16
20
  def log_firewall(request, forced: false, exception: nil)
@@ -37,7 +41,7 @@ module Auth
37
41
  def valid_ip?(request, forced: false)
38
42
  return true unless enabled?
39
43
 
40
- ip_address = request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip
44
+ ip_address = InternetProtocol.new(request).ip
41
45
  return true if !forced && IGNORE_IP.include?(ip_address)
42
46
 
43
47
  http = HTTP
@@ -59,14 +63,6 @@ module Auth
59
63
 
60
64
  private
61
65
 
62
- def host
63
- @host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
64
- end
65
-
66
- def apikey
67
- @apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
68
- end
69
-
70
66
  def ip_status_path(ip_address)
71
67
  [host, "api/v1/internet_protocols/status?ip=#{ip_address}"].join('/')
72
68
  end
@@ -74,14 +70,20 @@ module Auth
74
70
  def capture_path
75
71
  @capture_path ||= [host, 'api/v1/incoming_requests/capture'].join('/')
76
72
  end
73
+ end
77
74
 
78
- def timeout_seconds
79
- @timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
80
- end
75
+ class SecurityCaptcha
76
+ require_relative 'captcha/retrieve'
77
+ require_relative 'captcha/check_code'
81
78
 
82
- def enabled?
83
- @enabled ||= %w[true 1 yes on enabled].include?(ENV['AUTH_CENTRIC_ENABLED']&.downcase)
84
- end
79
+ include Auth::Centric::Common::Settings
80
+ include Auth::Centric::Captcha::Retrieve
81
+ include Auth::Centric::Captcha::CheckCode
82
+
83
+ def initialize(ip_address:, session_id:)
84
+ @ip_address = ip_address
85
+ @session_id = session_id
86
+ end
85
87
  end
86
88
  end
87
89
  end
@@ -0,0 +1,10 @@
1
+ module Auth
2
+ module Centric
3
+ module Captcha
4
+ module CheckCode
5
+ def verify_code?: -> bool
6
+ def check_code_path: -> string
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Auth
2
+ module Centric
3
+ module Captcha
4
+ module Retrieve
5
+ def find_or_create_path: -> tring
6
+ def retrieve_captcha: -> {
7
+ "id" => "uuid7",
8
+ "failed_count" => int,
9
+ "image" => { "url" => string },
10
+ "fail_limit" => int
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Auth
2
+ module Centric
3
+ module Common
4
+ module Settings
5
+ @apikey: string
6
+ @enabled: bool
7
+ @host: string
8
+ @ip: string
9
+ @timeout_seconds: int
10
+
11
+ def apikey: -> string
12
+ def enabled?: -> bool
13
+ def host: -> string
14
+ def ip: -> string
15
+ def timeout_seconds: -> int
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,23 +2,29 @@ module Auth
2
2
  module Centric
3
3
  module Firewall
4
4
  class CaptureRequest
5
- @request: Net::HTTPRequest
6
-
7
- def as_json: -> { }
5
+ def as_json: ->
6
+ {
7
+ ip: string,
8
+ domain: string,
9
+ url: string,
10
+ query_string: string,
11
+ request_method: string,
12
+ request_post_body: string,
13
+ user_agent: string,
14
+ language: string,
15
+ request_formats: string,
16
+ headers: {}
17
+ }
8
18
 
9
19
  def domain: -> string
10
20
 
11
- def headers: -> { }
12
-
13
- def ip: -> string
21
+ def headers: -> string
14
22
 
15
23
  def language: -> string
16
24
 
17
25
  def query_string: -> string
18
26
 
19
- def remote_ip: -> string
20
-
21
- def request_formats: -> [ ]
27
+ def request_formats: -> string
22
28
 
23
29
  def request_method: -> string
24
30
 
@@ -1,10 +1,11 @@
1
1
  module Auth
2
2
  module Centric
3
3
  module Firewall
4
- class CheckIp
4
+ class InternetProtocol
5
5
  @ip: string
6
6
 
7
- def is_valid?: -> bool
7
+ def ip: -> string
8
+ def is_ipv6?: -> bool
8
9
  end
9
10
  end
10
11
  end
@@ -1,26 +1,21 @@
1
1
  module Auth
2
2
  module Centric
3
3
  module Firewall
4
+ IGNORE_HEADER_KEYS: []
5
+ IGNORE_REQUEST: []
6
+ IGNORE_IP: []
7
+
4
8
  VERSION: string
5
9
 
6
- @host: string
7
- @apikey: string
8
- @enabled: bool
9
10
  @capture_path: string
10
- @timeout_seconds: int
11
11
 
12
12
  def log_firewall: -> bool
13
13
  def valid_ip?: -> bool
14
14
 
15
15
  private
16
16
 
17
-
18
- def host: -> string
19
- def apikey: -> string
20
- def enabled?: -> bool
21
17
  def capture_path: -> string
22
18
  def ip_status_path: -> string
23
- def timeout_seconds: -> int
24
19
  end
25
20
  end
26
21
  end
@@ -0,0 +1,8 @@
1
+ module Auth
2
+ module Centric
3
+ class SecurityCaptcha
4
+ @ip_address: string
5
+ @session_id: string
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth-centric-firewall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saimon Lovell
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '5'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ipaddr
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
26
40
  description: Uses A.I to analyze connections to find hackers.
27
41
  email:
28
42
  - staysynchronize@gmail.com
@@ -37,18 +51,22 @@ files:
37
51
  - LICENSE.txt
38
52
  - README.md
39
53
  - Rakefile
54
+ - lib/auth/centric/captcha/check_code.rb
55
+ - lib/auth/centric/captcha/retrieve.rb
56
+ - lib/auth/centric/common/settings.rb
40
57
  - lib/auth/centric/firewall.rb
41
58
  - lib/auth/centric/firewall/capture_request.rb
42
59
  - lib/auth/centric/firewall/constants.rb
60
+ - lib/auth/centric/firewall/internet_protocol.rb
43
61
  - lib/auth/centric/firewall/version.rb
44
62
  - public/403.html
63
+ - sig/auth/centric/captcha/check_code.rbs
64
+ - sig/auth/centric/captcha/retrieve.rbs
65
+ - sig/auth/centric/common/settings.rbs
45
66
  - sig/auth/centric/firewall.rbs
46
67
  - sig/auth/centric/firewall/capture_request.rbs
47
- - sig/auth/centric/firewall/check_ip.rbs
48
- - sig/auth/centric/firewall/constants.rbs
49
- - sig/ignore_header_keys.rbs
50
- - sig/ignore_ip.rbs
51
- - sig/ignore_request.rbs
68
+ - sig/auth/centric/firewall/internet_protocol.rbs
69
+ - sig/auth/centric/security_captcha.rbs
52
70
  homepage: https://gitlab.com/authcentric/auth-centric-firewall
53
71
  licenses:
54
72
  - MIT
@@ -72,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
90
  - !ruby/object:Gem::Version
73
91
  version: '0'
74
92
  requirements: []
75
- rubygems_version: 3.6.9
93
+ rubygems_version: 3.7.2
76
94
  specification_version: 4
77
95
  summary: Use artificial intelligence to find hackers.
78
96
  test_files: []
@@ -1,9 +0,0 @@
1
- module Auth
2
- module Centric
3
- module Firewall
4
- IGNORE_HEADER_KEYS: []
5
- IGNORE_REQUEST: []
6
- IGNORE_IP: []
7
- end
8
- end
9
- end
@@ -1 +0,0 @@
1
- IGNORE_HEADER_KEYS: []
data/sig/ignore_ip.rbs DELETED
@@ -1 +0,0 @@
1
- IGNORE_IP: []
@@ -1 +0,0 @@
1
- IGNORE_REQUEST: []