paraxial 0.1.0 → 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: 1bd3d81eda937e486869f0796af505440ba3268ef365a59170ac0545dcf06a10
4
- data.tar.gz: '099afef44bbc41beb2fdad948610864fa4592837428701c77d0f965d047e7d68'
3
+ metadata.gz: 70c0596f1eef97562cfcb511a053227074b08349c28081f76fde5e7481085eeb
4
+ data.tar.gz: a129cedace488343816f94ad89a712825b9e000de2dffa041f0ba9ab997f18d7
5
5
  SHA512:
6
- metadata.gz: 59db9199f831f0d4b65d8aa56bfca1ed976da91c03799b237c5b2d4fe62d5df1fd76c9de6dbf4969c90c6a0c50d6cfedfe57762f89a36f63997f1df7f811178c
7
- data.tar.gz: 5efcc6c94e05db287a6679e06188f86b354ec4c098c8f2f4276e10a73385895cbbf3b2c6bc2a7364e11c26d3ae4e953ff18109193d533eec6e41e0356895c9b8
6
+ metadata.gz: 3e67e1dc3fe51b437fc52b6ad026d155b7caea38a9d804e7676d96a2825fcd8833b320dd88f1151c313784eb7b49468c07a6f37275cdbf25bd5d66fda0d00c39
7
+ data.tar.gz: 0c93c320b498c22f7feaea3483562da418fe36af99c587652ffa8a19a2da10216b8ec4b131c44096dd6a3fd46a7ded086c161ff035f8b3264868b5e64ae15f3a
data/lib/paraxial/cli.rb CHANGED
@@ -7,27 +7,72 @@ require 'time'
7
7
 
8
8
  module Paraxial
9
9
  class CLI < Thor
10
- desc "scan", "Run scan"
10
+ desc 'scan', 'Run scan'
11
+ option :github_app, type: :boolean, default: false, desc: 'Use GitHub app'
12
+ option :install_id, type: :numeric, desc: 'GitHub App installation ID'
13
+ option :repo_owner, type: :string, desc: 'Repository owner'
14
+ option :repo_name, type: :string, desc: 'Repository name'
15
+ option :pr_number, type: :numeric, desc: 'Pull request number'
16
+
11
17
  def scan
12
- puts "[Paraxial] Scan NOW"
13
- cops = "Paraxial,Security/Eval,Security/IoMethods,Security/JSONLoad,Security/MarshalLoad,Security/Open,Security/YAMLLoad"
14
- rubocop = `rubocop --only #{cops} --format json`
15
- lockfile = File.read("./Gemfile.lock")
16
- api_key = ENV['PARAXIAL_API_KEY']
17
- uri = URI.parse(ENV['PARAXIAL_URL'] + "/api/ruby_scan")
18
- headers = { 'Content-Type': 'application/json' }
19
-
20
- body = { rubocop: rubocop, lockfile: lockfile, api_key: api_key, timestamp: Paraxial.get_timestamp() }
21
- response = Net::HTTP.post(uri, body.to_json, headers)
22
- puts response.body
23
-
24
- if ENV['PARAXIAL_API_KEY'] == nil
25
- puts "[Paraxial] Environment variable PARAXIAL_API_KEY not found, set with: "
26
- puts "[Paraxial] export PARAXIAL_API_KEY=your_site_api_key_here"
27
- puts "[Paraxial] Exiting"
28
- exit()
18
+ puts '[Paraxial] Scan starting...'
19
+
20
+ if ENV['PARAXIAL_API_KEY'].nil?
21
+ puts '[Paraxial] Environment variable PARAXIAL_API_KEY not found'
29
22
  else
30
- puts "[Paraxial] Scan result here"
23
+ github_app = options[:github_app]
24
+ install_id = options[:install_id]
25
+ repo_owner = options[:repo_owner]
26
+ repo_name = options[:repo_name]
27
+ pr_number = options[:pr_number]
28
+
29
+ cops = 'Paraxial,Security/Eval,Security/IoMethods,Security/JSONLoad,Security/MarshalLoad,Security/Open,Security/YAMLLoad'
30
+ rubocop = `rubocop --only #{cops} --format json`
31
+ lockfile = File.read('./Gemfile.lock')
32
+ api_key = ENV['PARAXIAL_API_KEY']
33
+ uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/ruby_scan')
34
+ headers = { 'Content-Type': 'application/json' }
35
+
36
+ body = { rubocop:, lockfile:, api_key:, timestamp: Paraxial.get_timestamp }
37
+ response = Net::HTTP.post(uri, body.to_json, headers)
38
+ puts "[Paraxial] scan result: #{response.body}"
39
+ github_valid = (!!github_app and !!install_id and !!repo_owner and !!repo_name and !!pr_number)
40
+
41
+ if github_app and github_valid == false
42
+ puts '[Paraxial] --github_app missing arguments'
43
+ puts '[Paraxial] Required: --github_app, --install_id, --repo_owner, --repo_name, --pr_number'
44
+ elsif github_app and github_valid
45
+ uuid_regex = /UUID\s+(\S+)/
46
+ match = response.body.match(uuid_regex)
47
+ uuid = match[1] if match
48
+ if uuid
49
+ final_uuid = uuid.chomp('.')
50
+ censored_backend_map = {
51
+ 'installation_id' => install_id,
52
+ 'repository_owner' => repo_owner,
53
+ 'repository_name' => repo_name,
54
+ 'pull_request_number' => pr_number,
55
+ 'scan_uuid' => final_uuid,
56
+ 'api_key' => 'REDACTED'
57
+ }
58
+ cbms = JSON.pretty_generate(censored_backend_map)
59
+ puts "[Paraxial] GitHub hash: #{cbms}"
60
+
61
+ censored_backend_map['api_key'] = api_key
62
+ backend_map = censored_backend_map
63
+ parax_uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/github_app')
64
+ github_pr_url = "https://github.com/#{repo_owner}/#{repo_name}/pull/#{pr_number}"
65
+
66
+ rr = Net::HTTP.post(parax_uri, backend_map.to_json, headers)
67
+ puts "[Paraxial] parax_uri response: #{rr.body}"
68
+ puts "[Paraxial] #{github_pr_url}"
69
+ else
70
+ puts '[Paraxial] No scan UUID found'
71
+ end
72
+
73
+ else
74
+ :ok
75
+ end
31
76
  end
32
77
  end
33
78
  end
@@ -1,25 +1,57 @@
1
1
  require 'bundler'
2
2
  require 'paraxial'
3
+ require 'rpatricia'
4
+
3
5
  Bundler.setup
4
6
 
5
7
  Rails.application.config.to_prepare do
6
8
  # Your code here
7
- puts "[Paraxial] Runtime start"
8
-
9
- deps_and_licenses = []
10
- Bundler.load.specs.each do |spec|
11
- # Print the gem name and license
12
- h = { name: spec.name, version: spec.version.to_s, description: Paraxial.trim_dep(spec.description), license: spec.license || 'None' }
13
- deps_and_licenses << h
14
- end
15
- deps_and_licenses << { name: "ruby", version: RUBY_VERSION, description: "The Ruby Programming Language", license: "Ruby"}
9
+ puts '[Paraxial] Runtime start'
16
10
  api_key = ENV['PARAXIAL_API_KEY']
17
- uri = URI.parse(ENV['PARAXIAL_URL'] + "/api/ruby_app_lic")
18
- headers = { 'Content-Type': 'application/json' }
19
11
 
20
- body = { app_lic: deps_and_licenses, api_key: api_key, timestamp: Paraxial.get_timestamp() }
21
- Thread.new do
22
- response = Net::HTTP.post(uri, body.to_json, headers)
23
- end
12
+ if api_key.nil?
13
+ puts '[Paraxial] PARAXIAL_API_KEY key not set, agent not started'
14
+ elsif ENV['PARAXIAL_URL'].nil?
15
+ puts '[Paraxial] PARAXIAL_URL key not set, agent not started'
16
+ elsif Rails.env.test?
17
+ puts '[Paraxial] Test environment detected, agent not started'
18
+ else
19
+ deps_and_licenses = []
20
+ Bundler.load.specs.each do |spec|
21
+ # Print the gem name and license
22
+ h = { name: spec.name, version: spec.version.to_s, description: Paraxial.trim_dep(spec.description),
23
+ license: spec.license || 'None' }
24
+ deps_and_licenses << h
25
+ end
26
+ deps_and_licenses << { name: 'ruby', version: RUBY_VERSION, description: 'The Ruby Programming Language',
27
+ license: 'Ruby' }
28
+ uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/ruby_app_lic')
29
+ headers = { 'Content-Type': 'application/json' }
24
30
 
31
+ body = { app_lic: deps_and_licenses, api_key:, timestamp: Paraxial.get_timestamp }
32
+ Thread.new do
33
+ Net::HTTP.post(uri, body.to_json, headers)
34
+ end
35
+
36
+ cloud_uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/cloud_ip_list')
37
+ response = Net::HTTP.get(cloud_uri)
38
+
39
+ # https://github.com/jkitching/rpatricia
40
+ pt_v4 = Patricia.new
41
+ pt_v6 = Patricia.new(:AF_INET6)
42
+ cloud_list = JSON.parse(response)
43
+ cloud_list.each do |k, v|
44
+ if k.include?('::')
45
+ pt_v6.add(k, v)
46
+ else
47
+ pt_v4.add(k, v)
48
+ end
49
+ end
50
+ # puts '[Paraxial] pt_v4.num_nodes'
51
+ # puts pt_v4.num_nodes
52
+ # puts 'pt_v6.num_nodes'
53
+ # puts pt_v6.num_nodes
54
+ PARAXIAL_IPV4 = pt_v4
55
+ PARAXIAL_IPV6 = pt_v6
56
+ end
25
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paraxial
4
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/paraxial.rb CHANGED
@@ -17,11 +17,33 @@ module Paraxial
17
17
  class Error < StandardError; end
18
18
  # Your code goes here...
19
19
 
20
+ class Defense
21
+ def initialize(app)
22
+ @app = app
23
+ end
24
+
25
+ def call(env)
26
+ request_path = env['PATH_INFO']
27
+
28
+ if request_path.end_with?('.php')
29
+ # Return a 404 response if the request path ends with '.php'
30
+ [404, { 'Content-Type' => 'text/plain' }, ["Not Found from Paraxial.io"]]
31
+ else
32
+ # Pass the request to the next middleware or the application
33
+ @app.call(env)
34
+ end
35
+ end
36
+ end
37
+
20
38
  def self.get_timestamp
21
39
  utc_time = Time.now.utc
22
40
  utc_time.strftime("%Y-%m-%d %H:%M:%S.%6N") + "Z"
23
41
  end
24
42
 
43
+ def self.cloud_ip?(ip)
44
+ !!(PARAXIAL_IPV4.search_best(ip) or PARAXIAL_IPV6.search_best(ip))
45
+ end
46
+
25
47
  def self.trim_dep(input)
26
48
  if input == nil
27
49
  nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paraxial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Lubas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-24 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rpatricia
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: thor
29
57
  requirement: !ruby/object:Gem::Requirement