auth-centric-firewall 0.0.1
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 +7 -0
- data/.rbenv-vars.example +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +12 -0
- data/lib/auth_centric/firewall/capture_request.rb +70 -0
- data/lib/auth_centric/firewall/constants.rb +30 -0
- data/lib/auth_centric/firewall/version.rb +7 -0
- data/lib/auth_centric/firewall.rb +74 -0
- data/sig/auth_centric/firewall/capture_request.rbs +30 -0
- data/sig/auth_centric/firewall/check_ip.rbs +9 -0
- data/sig/auth_centric/firewall/constants.rbs +7 -0
- data/sig/auth_centric/firewall.rbs +21 -0
- data/sig/ignore_header_keys.rbs +1 -0
- data/sig/ignore_ip.rbs +1 -0
- data/sig/ignore_request.rbs +1 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a00ae75ed3fd2e771940475c9cc9deb20d4ba8e2bdc513ec00c5b2835e5411ba
|
4
|
+
data.tar.gz: a77c13530988f331f8484ad57ab4ca699caecd7edd0f4b3f96fe66a48a44d510
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 751b1b6390bdb766308cedeea5692b9d28dc51bdf437958e2131086bef3f83e9bf6b38c5081c4ee107006bfbeea59f6a4cff7d210d884864650257e499aa330b
|
7
|
+
data.tar.gz: a7ba68574f38eb859c4b6592bc43b74d85a22c47673ecb5fa50a0dc18be905073941ad268ddd4845e3c279d6abc91c0a1dcf04b2ba91bdcf0c2c20f71c995eed
|
data/.rbenv-vars.example
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.1
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
EnforcedStyle: single_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
EnforcedStyle: single_quotes
|
10
|
+
|
11
|
+
Layout/IndentationConsistency:
|
12
|
+
EnforcedStyle: indented_internal_methods
|
13
|
+
|
14
|
+
Naming/PredicateName:
|
15
|
+
AllowedMethods:
|
16
|
+
- has_access?
|
17
|
+
NamePrefix:
|
18
|
+
- is_
|
19
|
+
- has_
|
20
|
+
- have_
|
21
|
+
MethodDefinitionMacros:
|
22
|
+
- define_method
|
23
|
+
- define_singleton_method
|
24
|
+
- def_node_matcher
|
25
|
+
- def_node_search
|
26
|
+
|
27
|
+
Metrics/MethodLength:
|
28
|
+
CountComments: false # count full line comments?
|
29
|
+
Max: 28
|
30
|
+
|
31
|
+
Layout/CaseIndentation:
|
32
|
+
Description: 'Indentation of when in a case/when/[else/]end.'
|
33
|
+
StyleGuide: '#indent-when-to-case'
|
34
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Saimon Lovell
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Auth::Centric::Firewall
|
2
|
+
|
3
|
+
Stop bad actors.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
|
8
|
+
```bash
|
9
|
+
bundle add auth-centric-firewall
|
10
|
+
```
|
11
|
+
|
12
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
gem install auth-centric-firewall
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
### Env Variables
|
21
|
+
|
22
|
+
```bash
|
23
|
+
AUTH_CENTRIC_HOST=http://localhost:3003
|
24
|
+
AUTH_CENTRIC_API_KEY=...
|
25
|
+
AUTH_CENTRIC_TIMEOUT_SECONDS=3
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://gitlab.com/authcentric/auth-centric-firewall.
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuthCentric
|
4
|
+
module Firewall
|
5
|
+
# Takes the incoming request and extracts
|
6
|
+
class CaptureRequest
|
7
|
+
def initialize(request)
|
8
|
+
@request = request
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json
|
12
|
+
{
|
13
|
+
domain:,
|
14
|
+
url:,
|
15
|
+
query_string:,
|
16
|
+
request_method:,
|
17
|
+
request_post_body:,
|
18
|
+
user_agent:,
|
19
|
+
language:,
|
20
|
+
request_formats:,
|
21
|
+
remote_ip:,
|
22
|
+
headers:
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def domain
|
27
|
+
@request.domain || @request.headers.env['HTTP_HOST']
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
return @request.original_fullpath if @request.original_fullpath.length == 1
|
32
|
+
|
33
|
+
@request.original_fullpath[1...]
|
34
|
+
end
|
35
|
+
|
36
|
+
def query_string
|
37
|
+
@request.query_string
|
38
|
+
end
|
39
|
+
|
40
|
+
def request_method
|
41
|
+
@request.method
|
42
|
+
end
|
43
|
+
|
44
|
+
def request_post_body
|
45
|
+
@request.body.read
|
46
|
+
end
|
47
|
+
|
48
|
+
def user_agent
|
49
|
+
@request.user_agent
|
50
|
+
end
|
51
|
+
|
52
|
+
def language
|
53
|
+
@request.accept_language
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_formats
|
57
|
+
@request.formats.map(&:to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
def remote_ip
|
61
|
+
@request.remote_ip
|
62
|
+
end
|
63
|
+
|
64
|
+
def headers
|
65
|
+
data = @request.headers.env.reject { |key| key.to_s.include?('.') || IGNORE_HEADER_KEYS.include?(key) }
|
66
|
+
data.as_json
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuthCentric
|
4
|
+
module Firewall
|
5
|
+
IGNORE_HEADER_KEYS = %w[
|
6
|
+
HTTP_HOST
|
7
|
+
HTTP_REFERER
|
8
|
+
HTTP_IF_NONE_MATCH
|
9
|
+
HTTP_CACHE_CONTROL
|
10
|
+
ORIGINAL_FULLPATH
|
11
|
+
PATH_INFO
|
12
|
+
QUERY_STRING
|
13
|
+
REMOTE_ADDR
|
14
|
+
REQUEST_URI
|
15
|
+
REQUEST_PATH
|
16
|
+
REQUEST_METHOD
|
17
|
+
SERVER_NAME
|
18
|
+
SERVER_SOFTWARE
|
19
|
+
warden
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
IGNORE_IP = %w[
|
23
|
+
0.0.0.0
|
24
|
+
127.0.0.1
|
25
|
+
127.0.0.2
|
26
|
+
].freeze
|
27
|
+
|
28
|
+
IGNORE_REQUEST = %w[/ delayed_job favicon.ico robots.txt ads.txt humans.txt].freeze
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'pry'
|
4
|
+
require 'http'
|
5
|
+
|
6
|
+
require_relative 'firewall/version'
|
7
|
+
require_relative 'firewall/constants'
|
8
|
+
require_relative 'firewall/capture_request'
|
9
|
+
|
10
|
+
module AuthCentric
|
11
|
+
# Client code for the firewall
|
12
|
+
module Firewall
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
def log_firewall(request)
|
16
|
+
return true if IGNORE_IP.include?(request.remote_ip)
|
17
|
+
return true if IGNORE_REQUEST.include?(request.original_fullpath)
|
18
|
+
|
19
|
+
cr = CaptureRequest.new(request)
|
20
|
+
payload = { request: cr.as_json }
|
21
|
+
|
22
|
+
http = HTTP
|
23
|
+
.timeout(timeout_seconds)
|
24
|
+
.headers(apikey:)
|
25
|
+
.post(capture_path, json: payload)
|
26
|
+
|
27
|
+
http.status == 200
|
28
|
+
rescue HTTP::TimeoutError
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_ip?(ip_address)
|
33
|
+
return true if IGNORE_IP.include?(ip_address)
|
34
|
+
|
35
|
+
http = HTTP
|
36
|
+
.timeout(timeout_seconds)
|
37
|
+
.headers(apikey:)
|
38
|
+
.get(ip_status_path(ip_address))
|
39
|
+
|
40
|
+
case http.status
|
41
|
+
when 200, 202
|
42
|
+
true
|
43
|
+
when 403
|
44
|
+
false
|
45
|
+
else
|
46
|
+
raise Error, "#{http.status}: #{http.body}"
|
47
|
+
end
|
48
|
+
rescue HTTP::TimeoutError
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def host
|
55
|
+
@host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
|
56
|
+
end
|
57
|
+
|
58
|
+
def apikey
|
59
|
+
@apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
|
60
|
+
end
|
61
|
+
|
62
|
+
def ip_status_path(ip_address)
|
63
|
+
[host, "api/v1/internet_protocols/status?ip=#{ip_address}"].join('/')
|
64
|
+
end
|
65
|
+
|
66
|
+
def capture_path
|
67
|
+
@capture_path ||= [host, 'api/v1/incoming_requests/capture'].join('/')
|
68
|
+
end
|
69
|
+
|
70
|
+
def timeout_seconds
|
71
|
+
@timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module AuthCentric
|
2
|
+
module Firewall
|
3
|
+
class CaptureRequest
|
4
|
+
@request: Net::HTTPRequest
|
5
|
+
|
6
|
+
def as_json: -> { }
|
7
|
+
|
8
|
+
def domain: -> string
|
9
|
+
|
10
|
+
def headers: -> { }
|
11
|
+
|
12
|
+
def language: -> string
|
13
|
+
|
14
|
+
def query_string: -> string
|
15
|
+
|
16
|
+
def remote_ip: -> string
|
17
|
+
|
18
|
+
def request_formats: -> [ ]
|
19
|
+
|
20
|
+
def request_method: -> string
|
21
|
+
|
22
|
+
def request_post_body: -> string
|
23
|
+
|
24
|
+
def url: -> string
|
25
|
+
|
26
|
+
def user_agent: -> string
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AuthCentric
|
2
|
+
module Firewall
|
3
|
+
VERSION: string
|
4
|
+
|
5
|
+
@host: string
|
6
|
+
@apikey: string
|
7
|
+
@capture_path: string
|
8
|
+
@timeout_seconds: int
|
9
|
+
|
10
|
+
def log_firewall: -> bool
|
11
|
+
def valid_ip?: -> bool
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def host: -> string
|
16
|
+
def apikey: -> string
|
17
|
+
def capture_path: -> string
|
18
|
+
def ip_status_path: -> string
|
19
|
+
def timeout_seconds: -> int
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
IGNORE_HEADER_KEYS: []
|
data/sig/ignore_ip.rbs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
IGNORE_IP: []
|
@@ -0,0 +1 @@
|
|
1
|
+
IGNORE_REQUEST: []
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auth-centric-firewall
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Saimon Lovell
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-03-20 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: http
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '5'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '5'
|
26
|
+
description: Uses A.I to analyze connections to find hackers.
|
27
|
+
email:
|
28
|
+
- staysynchronize@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".rbenv-vars.example"
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- CHANGELOG.md
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/auth_centric/firewall.rb
|
41
|
+
- lib/auth_centric/firewall/capture_request.rb
|
42
|
+
- lib/auth_centric/firewall/constants.rb
|
43
|
+
- lib/auth_centric/firewall/version.rb
|
44
|
+
- sig/auth_centric/firewall.rbs
|
45
|
+
- sig/auth_centric/firewall/capture_request.rbs
|
46
|
+
- sig/auth_centric/firewall/check_ip.rbs
|
47
|
+
- sig/auth_centric/firewall/constants.rbs
|
48
|
+
- sig/ignore_header_keys.rbs
|
49
|
+
- sig/ignore_ip.rbs
|
50
|
+
- sig/ignore_request.rbs
|
51
|
+
homepage: https://gitlab.com/authcentric/auth-centric-firewall
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata:
|
55
|
+
allowed_push_host: https://rubygems.org
|
56
|
+
homepage_uri: https://gitlab.com/authcentric/auth-centric-firewall
|
57
|
+
source_code_uri: https://gitlab.com/authcentric/auth-centric-firewall
|
58
|
+
changelog_uri: https://gitlab.com/authcentric/auth-centric-firewall/-/blob/dev/CHANGELOG.md
|
59
|
+
rubygems_mfa_required: 'true'
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.1.0
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.6.6
|
75
|
+
specification_version: 4
|
76
|
+
summary: Use artificial intelligence to find hackers.
|
77
|
+
test_files: []
|