neetob 0.5.56 → 0.5.57
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/neetob/cli/github/unused_assets_audit.rb +85 -0
- data/lib/neetob/cli/monthly_audit/security/code/checks_for_unused_assets.rb +43 -0
- data/lib/neetob/cli/monthly_audit/security/code/main.rb +3 -0
- data/lib/neetob/cli/ui.rb +1 -1
- data/lib/neetob/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3821951c5318dd72f074db7e8eb6fe1361bda15654b920074adbaf70555e0a01
|
4
|
+
data.tar.gz: 5fde35a1fe499c6023d3804be70f0c2ab839e8ebd05a46bf7ff8b7cf2367f3bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af3dc2565387e07251580b4e13e91f2c6c249bee01a96d6fcec61a5001a492c98ff0d55c754a8e464aef017d07a576ac45742de17e2eff91e7dc0ade3da595d2
|
7
|
+
data.tar.gz: ec9229722dc0af2ec1ec25bb95b0639ca4ea7e76fb55849b21eef7d9a91c8a6a00b0e874ac8343e84e4b67d49c5f082c81aec915bdac4a87544abaa8104892eb
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./make_pr/base"
|
4
|
+
module Neetob
|
5
|
+
class CLI
|
6
|
+
module Github
|
7
|
+
class UnusedAssetsAudit < MakePr::Base
|
8
|
+
DESCRIPTION = "Fix security vulnerabilities reported by unused assets audit"
|
9
|
+
attr_accessor :repos, :sandbox
|
10
|
+
|
11
|
+
def initialize(repos, sandbox = false)
|
12
|
+
super()
|
13
|
+
@repos = repos
|
14
|
+
@sandbox = sandbox
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
|
19
|
+
report = nil
|
20
|
+
matching_repos.each do |repo|
|
21
|
+
begin
|
22
|
+
ui.info("\nWorking on repo #{repo}", print_to_audit_log: false)
|
23
|
+
clone_repo_in_tmp_dir(repo)
|
24
|
+
image_dir = "/tmp/neetob/#{repo_name_without_org_suffix(repo)}/app/assets/images"
|
25
|
+
src_dir = "/tmp/neetob/#{repo_name_without_org_suffix(repo)}/app/javascript/src"
|
26
|
+
views_dir = "/tmp/neetob/#{repo_name_without_org_suffix(repo)}/app/views"
|
27
|
+
report = find_unused_images(image_dir, src_dir, views_dir)
|
28
|
+
ui.success("Successfully executed unused assets audit for #{repo}", print_to_audit_log: false)
|
29
|
+
rescue StandardError => e
|
30
|
+
ExceptionHandler.new(e).process
|
31
|
+
end
|
32
|
+
end
|
33
|
+
`rm -rf /tmp/neetob` unless Thread.current[:audit_mode]
|
34
|
+
if Thread.current[:audit_mode]
|
35
|
+
report
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def list_image_files(dir_path)
|
42
|
+
Dir.glob("#{dir_path}/**/*").select { |file| File.file?(file) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_unused_images(image_dir, src_dir, views_dir)
|
46
|
+
images = Set.new(list_image_files(image_dir))
|
47
|
+
images = filter_used_images(src_dir, images)
|
48
|
+
images = filter_used_images(views_dir, images, true)
|
49
|
+
images.to_a
|
50
|
+
end
|
51
|
+
|
52
|
+
def filter_used_images(dir, images, is_views_path = false)
|
53
|
+
new_images_set = Set.new(images)
|
54
|
+
Dir.glob("#{dir}/**/*") do |file|
|
55
|
+
next unless File.file?(file)
|
56
|
+
|
57
|
+
File.open(file, "r") do |file_content|
|
58
|
+
new_images_set.each do |image_file_path|
|
59
|
+
destructured_image_path = split_image_path(is_views_path, image_file_path)
|
60
|
+
if image_file_imported(file_content.read, destructured_image_path, is_views_path)
|
61
|
+
new_images_set.delete(image_file_path)
|
62
|
+
end
|
63
|
+
file_content.rewind
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
new_images_set
|
68
|
+
end
|
69
|
+
|
70
|
+
def image_file_imported(file, image_path, is_views_path)
|
71
|
+
regex = is_views_path ? /"#{image_path}"/ : /import .* from "#{image_path}";/
|
72
|
+
file.match(regex)
|
73
|
+
end
|
74
|
+
|
75
|
+
def split_image_path(is_views_path, image_file_path)
|
76
|
+
if is_views_path
|
77
|
+
image_file_path.split("images/").last
|
78
|
+
else
|
79
|
+
image_file_path[image_file_path.index("images")..image_file_path.rindex(".") - 1]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../../github/unused_assets_audit"
|
4
|
+
|
5
|
+
module Neetob
|
6
|
+
class CLI
|
7
|
+
module MonthlyAudit
|
8
|
+
module Security
|
9
|
+
module Code
|
10
|
+
class ChecksForUnusedAssets < CLI::Base
|
11
|
+
def initialize
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
ui.success("### 1.1.5. Checking whether running `unused assets audit` throws any vulnerabilities")
|
17
|
+
repo_data = [["Repository", "Unused Assets Found", "Comments", "Audit Passed"]]
|
18
|
+
ui.info "\n"
|
19
|
+
|
20
|
+
NeetoCompliance::NeetoRepos.products.keys.each do |repo|
|
21
|
+
ui.info("Checking unused assets for #{repo}", print_to_audit_log: false)
|
22
|
+
unused_files = Neetob::CLI::Github::UnusedAssetsAudit.new([repo]).run
|
23
|
+
if unused_files && unused_files.any?
|
24
|
+
unused_assets_found = "Yes"
|
25
|
+
audit_passed = "No"
|
26
|
+
comments = unused_files.join("<br>")
|
27
|
+
else
|
28
|
+
unused_assets_found = "No"
|
29
|
+
audit_passed = "Yes"
|
30
|
+
comments = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
repo_data << [repo, unused_assets_found, comments, audit_passed]
|
34
|
+
end
|
35
|
+
|
36
|
+
ui.print_table(repo_data)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,6 +4,7 @@ require_relative "bundle_audit"
|
|
4
4
|
require_relative "yarn_audit"
|
5
5
|
require_relative "brakeman"
|
6
6
|
require_relative "active_record_doctor"
|
7
|
+
require_relative "checks_for_unused_assets"
|
7
8
|
|
8
9
|
module Neetob
|
9
10
|
class CLI
|
@@ -23,6 +24,8 @@ module Neetob
|
|
23
24
|
Brakeman.new.run
|
24
25
|
ui.info "\n"
|
25
26
|
ActiveRecordDoctor.new.run
|
27
|
+
ui.info "\n"
|
28
|
+
ChecksForUnusedAssets.new.run
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
data/lib/neetob/cli/ui.rb
CHANGED
data/lib/neetob/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neetob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.57
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Udai Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -261,6 +261,7 @@ files:
|
|
261
261
|
- lib/neetob/cli/github/repositories/get_security_details.rb
|
262
262
|
- lib/neetob/cli/github/repositories/pull_requests.rb
|
263
263
|
- lib/neetob/cli/github/search.rb
|
264
|
+
- lib/neetob/cli/github/unused_assets_audit.rb
|
264
265
|
- lib/neetob/cli/github/yarn_audit.rb
|
265
266
|
- lib/neetob/cli/heroku/access/add.rb
|
266
267
|
- lib/neetob/cli/heroku/access/commands.rb
|
@@ -313,6 +314,7 @@ files:
|
|
313
314
|
- lib/neetob/cli/monthly_audit/security/code/active_record_doctor.rb
|
314
315
|
- lib/neetob/cli/monthly_audit/security/code/brakeman.rb
|
315
316
|
- lib/neetob/cli/monthly_audit/security/code/bundle_audit.rb
|
317
|
+
- lib/neetob/cli/monthly_audit/security/code/checks_for_unused_assets.rb
|
316
318
|
- lib/neetob/cli/monthly_audit/security/code/main.rb
|
317
319
|
- lib/neetob/cli/monthly_audit/security/code/yarn_audit.rb
|
318
320
|
- lib/neetob/cli/monthly_audit/security/github/dependabot_prs_merged.rb
|