veracode 1.0.0 → 1.1.7
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/bin/veracode +16 -5
- data/lib/veracode/version.rb +1 -1
- data/lib/veracode.rb +92 -45
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2748dd2d1f9ca4ad77e27e5135143f3e310f2b78722d095439126afe3aa5a433
|
4
|
+
data.tar.gz: 6a15bb00abca2f8471d0a535bcd812bd9ae8366e60998b211236981ad5aff5fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd794f9d29c5e9d226af29e0de4425a0beea89677396698e01955043ca0054b964718dc662c7bab6dfdddf3e60f7988fe9dc5e5b7bd494c8846eb0517994b79
|
7
|
+
data.tar.gz: 9132bf0aa6955ca63449dadcd4965e36fda893940f995d652aa59d1f34d5be43506c00c1f2ab89359db7d9212b10c2d3f55a80f99f548438a539339aaef4d7b5
|
data/bin/veracode
CHANGED
@@ -4,10 +4,10 @@ require 'optparse'
|
|
4
4
|
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
5
5
|
$:.unshift Dir.pwd
|
6
6
|
|
7
|
-
if File.
|
7
|
+
if File.exist?('Gemfile.lock')
|
8
8
|
rails_version = File.open('Gemfile.lock').grep(/^\s*rails\s*\(=\s*[34]/)
|
9
9
|
else
|
10
|
-
rails_version = File.
|
10
|
+
rails_version = File.exist?("script/rails") #fallback for rails 3.0
|
11
11
|
end
|
12
12
|
unless rails_version
|
13
13
|
$stderr.puts "Current directory #{File.basename(Dir.pwd).dump} does not appear to be a Rails 3/4 application."
|
@@ -25,7 +25,7 @@ $options = {
|
|
25
25
|
:include_inherited => false,
|
26
26
|
:environment => false,
|
27
27
|
:verbose => false,
|
28
|
-
:
|
28
|
+
:skipenvironment => false,
|
29
29
|
:skipactiverecord => false,
|
30
30
|
:skipactionview => false,
|
31
31
|
:skipsprockets => false,
|
@@ -42,8 +42,8 @@ case subcommand
|
|
42
42
|
$options[:verbose] = true
|
43
43
|
end
|
44
44
|
|
45
|
-
opts.on("-
|
46
|
-
$options[:
|
45
|
+
opts.on("-E", "--skip-environment", "Skip environment") do
|
46
|
+
$options[:skipenvironment] = true
|
47
47
|
end
|
48
48
|
|
49
49
|
opts.on("-O", "--skip-active-record", "Skip ActiveRecord") do
|
@@ -70,6 +70,17 @@ case subcommand
|
|
70
70
|
$options[:snapshot] = true
|
71
71
|
end
|
72
72
|
|
73
|
+
# only print the options that match the documentation in the help center
|
74
|
+
opts.on("-h", "--help", "Print help") do
|
75
|
+
msg = <<-HELPMSG.strip
|
76
|
+
Usage: veracode prepare [options]
|
77
|
+
-v, --verbose Run verbosely
|
78
|
+
-D, --debug Enable debug output
|
79
|
+
HELPMSG
|
80
|
+
puts msg
|
81
|
+
exit
|
82
|
+
end
|
83
|
+
|
73
84
|
end.parse!
|
74
85
|
|
75
86
|
Veracode.prepare
|
data/lib/veracode/version.rb
CHANGED
data/lib/veracode.rb
CHANGED
@@ -39,7 +39,7 @@ module Veracode
|
|
39
39
|
@expanded_app_dir = Dir.getwd
|
40
40
|
|
41
41
|
def self.init
|
42
|
-
if Gem::Dependency.new('', '~> 2.2.0').match?('', RUBY_VERSION)
|
42
|
+
if Gem::Dependency.new('', '~> 2.2.0').match?('', RUBY_VERSION.dup)
|
43
43
|
$stderr.puts "Ruby 2.2 is not supported, please consult the compilation guide for all supported Ruby versions"
|
44
44
|
exit
|
45
45
|
end
|
@@ -48,7 +48,7 @@ module Veracode
|
|
48
48
|
@archive_dirname = File.join("tmp","veracode-#{@run_id}")
|
49
49
|
@required_libs.merge(["pathname", "set", "zlib", "zip/zip", "veracode"])
|
50
50
|
|
51
|
-
if !Dir.
|
51
|
+
if !Dir.exist?("tmp")
|
52
52
|
begin
|
53
53
|
Dir.mkdir("tmp")
|
54
54
|
rescue Exception => e
|
@@ -57,7 +57,7 @@ module Veracode
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
while Dir.
|
60
|
+
while Dir.exist?(@archive_dirname)
|
61
61
|
@run_id = Time.now.strftime("%Y%m%d%H%M%S")
|
62
62
|
@archive_dirname = File.join("tmp","veracode-#{@run_id}")
|
63
63
|
end
|
@@ -184,6 +184,7 @@ module Veracode
|
|
184
184
|
}
|
185
185
|
}
|
186
186
|
else
|
187
|
+
Zip.write_zip64_support = true
|
187
188
|
Zip::File.open(@archive_filename, Zip::File::CREATE) { |zf|
|
188
189
|
@manifest.each { |file|
|
189
190
|
|
@@ -291,17 +292,20 @@ module Veracode
|
|
291
292
|
|
292
293
|
def self.safe_name(o)
|
293
294
|
begin
|
295
|
+
restore_original_class_method(o)
|
294
296
|
case
|
295
297
|
when o == ActiveSupport::TimeWithZone
|
296
298
|
"ActiveSupport::TimeWithZone"
|
297
299
|
when o.is_a?(Module)
|
298
300
|
begin
|
299
301
|
( o.name.nil? ? o.to_s : o.name.to_s )
|
300
|
-
rescue
|
302
|
+
rescue Exception => e
|
301
303
|
begin
|
304
|
+
log_error "Exception rescued trying to call .name on object. Object: #{o.inspect}. Exception: #{e.inspect}"
|
302
305
|
( o.nil? ? "nil" : o.to_s )
|
303
|
-
rescue
|
304
|
-
|
306
|
+
rescue Exception => e
|
307
|
+
log_error "Exception rescued trying to call .nil on object. Object: #{o.inspect}. Exception: #{e.inspect}"
|
308
|
+
( o == nil ? "nil" : o.to_s ) # in case of monkey patched nil?
|
305
309
|
end
|
306
310
|
end
|
307
311
|
when o.is_a?(Method), o.is_a?(UnboundMethod)
|
@@ -309,10 +313,28 @@ module Veracode
|
|
309
313
|
else
|
310
314
|
o.to_s
|
311
315
|
end
|
312
|
-
rescue
|
316
|
+
rescue Exception => e
|
317
|
+
log_error "Exception rescued trying to get safe_name on object. Dropping from archive. Exception: #{e.inspect}"
|
313
318
|
"Veracode" #should result in this being dropped from the archive since we can't get a safe name for it
|
314
319
|
end
|
315
320
|
end
|
321
|
+
|
322
|
+
# Some Ruby devs override the `class` method.
|
323
|
+
# This is bad practice but is still done sometimes.
|
324
|
+
# For example: https://github.com/faker-ruby/faker/blob/v2.2.1/lib/faker/games/heroes_of_the_storm.rb#L11-L13
|
325
|
+
# This messes with our ability to get the class name.
|
326
|
+
# So we detect this and if it is overriden we restore the original method from `Kernel`
|
327
|
+
def self.restore_original_class_method(obj)
|
328
|
+
original_class_method = Kernel.instance_method(:class)
|
329
|
+
|
330
|
+
class_method_owner = obj.method(:class).owner
|
331
|
+
|
332
|
+
if class_method_owner != Kernel
|
333
|
+
obj.define_singleton_method(:class) do
|
334
|
+
original_class_method.bind(self).call
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
316
338
|
|
317
339
|
def self.quote(o)
|
318
340
|
o.to_s.dump
|
@@ -488,7 +510,17 @@ module Veracode
|
|
488
510
|
|
489
511
|
formatted_contents = ""
|
490
512
|
|
491
|
-
m.
|
513
|
+
constants_method = m.method(:constants)
|
514
|
+
original_constants_method = Module.instance_method(:constants)
|
515
|
+
|
516
|
+
if constants_method != original_constants_method
|
517
|
+
puts " constants method has been overridden, fall back to original method" if $options[:verbose]
|
518
|
+
constants = original_constants_method.bind(m).call($options[:include_inherited])
|
519
|
+
else
|
520
|
+
constants = m.constants($options[:include_inherited])
|
521
|
+
end
|
522
|
+
|
523
|
+
constants.each do |c_symbol|
|
492
524
|
begin
|
493
525
|
c = m.const_get(c_symbol) if m.const_defined? c_symbol
|
494
526
|
formatted_contents += format_constant(c_symbol, c)
|
@@ -643,29 +675,33 @@ module Veracode
|
|
643
675
|
|
644
676
|
def self.archive_rails6_templates
|
645
677
|
puts "archiving views" if $options[:verbose]
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
678
|
+
begin
|
679
|
+
o = @view.compiled_method_container
|
680
|
+
compiled_views = o.instance_methods - @view_methods
|
681
|
+
formatted_contents = ""
|
682
|
+
for m_symbol in compiled_views
|
683
|
+
begin
|
684
|
+
m = o.instance_method(m_symbol)
|
685
|
+
formatted_contents += format_method(m, "public_instance", true)
|
686
|
+
rescue Exception => e
|
687
|
+
log_error "Error archiving singleton method #{m_symbol.to_s.dump}: #{e.message}"
|
688
|
+
end
|
655
689
|
end
|
690
|
+
# fake the module outpput to match what SAF expects from Rails <= 5
|
691
|
+
add_to_archive "module \"ActionView::CompiledTemplates\"\n" +
|
692
|
+
"extend \"ActiveSupport::Dependencies::ModuleConstMissing\"\n" +
|
693
|
+
"extend \"Module::Concerning\"\n" +
|
694
|
+
"extend \"ActiveSupport::ToJsonWithActiveSupportEncoder\"\n" +
|
695
|
+
"extend \"PP::ObjectMixin\"\n" +
|
696
|
+
"extend \"ActiveSupport::Dependencies::Loadable\"\n" +
|
697
|
+
"extend \"JSON::Ext::Generator::GeneratorMethods::Object\"\n" +
|
698
|
+
"extend \"ActiveSupport::Tryable\"\n" +
|
699
|
+
"extend \"Kernel\"\n" +
|
700
|
+
formatted_contents +
|
701
|
+
"endmodule\n"
|
702
|
+
rescue Exception => e
|
703
|
+
log_error "Error archiving Rails 6 views: #{e.message}"
|
656
704
|
end
|
657
|
-
# fake the module outpput to match what SAF expects from Rails <= 5
|
658
|
-
add_to_archive "module \"ActionView::CompiledTemplates\"\n" +
|
659
|
-
"extend \"ActiveSupport::Dependencies::ModuleConstMissing\"\n" +
|
660
|
-
"extend \"Module::Concerning\"\n" +
|
661
|
-
"extend \"ActiveSupport::ToJsonWithActiveSupportEncoder\"\n" +
|
662
|
-
"extend \"PP::ObjectMixin\"\n" +
|
663
|
-
"extend \"ActiveSupport::Dependencies::Loadable\"\n" +
|
664
|
-
"extend \"JSON::Ext::Generator::GeneratorMethods::Object\"\n" +
|
665
|
-
"extend \"ActiveSupport::Tryable\"\n" +
|
666
|
-
"extend \"Kernel\"\n" +
|
667
|
-
formatted_contents +
|
668
|
-
"endmodule\n"
|
669
705
|
end
|
670
706
|
|
671
707
|
|
@@ -773,6 +809,7 @@ module Veracode
|
|
773
809
|
File.read(template),
|
774
810
|
template,
|
775
811
|
ActionView::Template::Handlers::ERB,
|
812
|
+
:locals => [],
|
776
813
|
:virtual_path => template
|
777
814
|
)
|
778
815
|
|
@@ -857,7 +894,7 @@ module Veracode
|
|
857
894
|
def self.require_libs(lib_paths)
|
858
895
|
for lib_path in lib_paths
|
859
896
|
dirsToProcess = [Pathname(lib_path)]
|
860
|
-
until dirsToProcess.count == 0 || !Dir.
|
897
|
+
until dirsToProcess.count == 0 || !Dir.exist?(dirsToProcess[0])
|
861
898
|
currentDir = dirsToProcess.delete_at(0)
|
862
899
|
for child in currentDir.children
|
863
900
|
if child.directory?
|
@@ -989,7 +1026,11 @@ end
|
|
989
1026
|
|
990
1027
|
glob_require "config/application.rb"
|
991
1028
|
|
992
|
-
|
1029
|
+
begin
|
1030
|
+
Rails.application.require_environment! unless $options[:skipenvironment]
|
1031
|
+
rescue Exception => e
|
1032
|
+
log_error "Unable to require environment: #{e.message}"
|
1033
|
+
end
|
993
1034
|
# Following line will actually kick off IRB
|
994
1035
|
# Rails::Console.start(Rails.application)
|
995
1036
|
|
@@ -1029,21 +1070,26 @@ end
|
|
1029
1070
|
puts "new successful requires? #{any_new.to_s}" if $options[:verbose]
|
1030
1071
|
end
|
1031
1072
|
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1073
|
+
begin
|
1074
|
+
if @rails6
|
1075
|
+
self.update
|
1076
|
+
@view = ActionView::Base.with_empty_template_cache
|
1077
|
+
@view_methods = @view.compiled_method_container.instance_methods
|
1078
|
+
compile_erb_templates
|
1079
|
+
compile_haml_templates
|
1080
|
+
self.stats if $options[:verbose]
|
1081
|
+
else
|
1082
|
+
compile_templates
|
1083
|
+
self.update
|
1084
|
+
self.stats if $options[:verbose]
|
1085
|
+
end
|
1044
1086
|
|
1045
|
-
|
1046
|
-
|
1087
|
+
# Ensure compiled templates are fully disassembled in archive
|
1088
|
+
@baseline_modules.delete(ActionView::CompiledTemplates) unless @rails6
|
1089
|
+
rescue Exception => e
|
1090
|
+
puts "Unable to compile templates: #{e.message}" if $options[:verbose]
|
1091
|
+
log_error "Unable to compile templates: #{e.message}"
|
1092
|
+
end
|
1047
1093
|
|
1048
1094
|
if $options[:environment]
|
1049
1095
|
puts "Processing and disassembling environment"
|
@@ -1070,6 +1116,7 @@ end
|
|
1070
1116
|
log_error e.message
|
1071
1117
|
log_error e.backtrace.join("\n")
|
1072
1118
|
else
|
1119
|
+
puts "Failed to prepare veracode archive. Please see #{@errorlog_filename}."
|
1073
1120
|
raise
|
1074
1121
|
end
|
1075
1122
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: veracode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Veracode
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
description: Prepares your Ruby on Rails app for submission to Veracode.
|
@@ -39,7 +39,7 @@ files:
|
|
39
39
|
homepage: http://veracode.com/
|
40
40
|
licenses: []
|
41
41
|
metadata: {}
|
42
|
-
post_install_message:
|
42
|
+
post_install_message:
|
43
43
|
rdoc_options: []
|
44
44
|
require_paths:
|
45
45
|
- lib
|
@@ -54,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.1.
|
58
|
-
signing_key:
|
57
|
+
rubygems_version: 3.1.6
|
58
|
+
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Command line tool for preparing your Ruby on Rails app for submission to
|
61
61
|
Veracode
|