veracode 1.0.0.alpha16 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f9679b127c0fea3a3044f5470c2336d02dcbd3c453df0bdc121827d41ce27c7
4
- data.tar.gz: c4a8fb0378e691164646c70f53e8c866b4355fad557daedbc701d4afc05f695b
3
+ metadata.gz: f66a40787c8297707914cc96ba81def96cff04a70d119b07bbd84c3fc59933d3
4
+ data.tar.gz: 1183be46375e9050ffa70a61565f17c428fc2478a03ef7f80d09658a3cdda9e0
5
5
  SHA512:
6
- metadata.gz: 431b1b21871f274c9c394fff11873bf53730356f5c589aa439f59ab857c6dbcc22e9297d7dbd1f479438eafc0b25ca15cb7cbf5c5dc36f2346246670fd135f40
7
- data.tar.gz: fb1c0e34fc6d61955557b439f7b855b977cdaa5431684654a03868021913cd2137f0ad64688f7eeca36e4723ace8024a84434af37d4c6a3dcfd1768a35ab022a
6
+ metadata.gz: 285a3853aed2b60503bbd7d042fe4a3a9d9f7b5652a6435791ff909774b9ab46b955fdf41f962bc78cb10c290c96e878804da389ebf83f777c5a336ad739b659
7
+ data.tar.gz: 27e5ac6b2d3fdb44d36284a131f8b337daa0529e06e0dbf042751df169dddb2b51d7b395013e2fc03a3556c7afd2f96ed6016b644ddfa8ded6c6b3cf5b7ef5d4
data/bin/veracode CHANGED
@@ -23,8 +23,13 @@ require 'veracode/version'
23
23
  $options = {
24
24
  :archive_source => true,
25
25
  :include_inherited => false,
26
- :jruby => false,
27
26
  :environment => false,
27
+ :verbose => false,
28
+ :jruby => false,
29
+ :skipactiverecord => false,
30
+ :skipactionview => false,
31
+ :skipsprockets => false,
32
+ :snapshot => false
28
33
  }
29
34
 
30
35
  subcommand = ARGV.shift
@@ -61,6 +66,10 @@ case subcommand
61
66
  $DEBUG = true
62
67
  end
63
68
 
69
+ opts.on("--debug-snapshot", "Generate a snapshot of the prepare state for Veracode debugging.") do
70
+ $options[:snapshot] = true
71
+ end
72
+
64
73
  end.parse!
65
74
 
66
75
  Veracode.prepare
data/lib/veracode.rb CHANGED
@@ -36,6 +36,7 @@ module Veracode
36
36
  @archive_filename = nil
37
37
  @archive_dirname = nil
38
38
 
39
+ @expanded_app_dir = Dir.getwd
39
40
 
40
41
  def self.init
41
42
  if Gem::Dependency.new('', '~> 2.2.0').match?('', RUBY_VERSION)
@@ -120,10 +121,11 @@ module Veracode
120
121
 
121
122
  @manifest += Dir.glob("*").keep_if {|f| File.file?(f)}
122
123
 
123
- # {app config db doc lib log public script test tmp vendor}
124
- %w{app config lib log public script vendor}.each {|dirname|
124
+ #{app config db doc lib log public script test tmp vendor}
125
+ %w{app config lib log public script}.each {|dirname|
125
126
  @manifest += Dir[File.join(dirname, "**", "*")].keep_if {|f| File.file?(f)}
126
127
  }
128
+ @manifest += Dir[File.join("vendor", "**", "*.rb")]
127
129
  @manifest += Dir[File.join("db", "**", "*.rb")]
128
130
 
129
131
  if $options[:archive_source]
@@ -202,7 +204,11 @@ module Veracode
202
204
  exit
203
205
  end
204
206
 
205
- puts "Please upload #{@archive_filename}"
207
+ if $options[:snapshot]
208
+ puts "Please provide #{@archive_filename} to veracode for further investigation."
209
+ else
210
+ puts "Please upload #{@archive_filename}"
211
+ end
206
212
  end
207
213
 
208
214
  def self.cleanup
@@ -284,23 +290,27 @@ module Veracode
284
290
  end
285
291
 
286
292
  def self.safe_name(o)
287
- case
288
- when o == ActiveSupport::TimeWithZone
289
- "ActiveSupport::TimeWithZone"
290
- when o.is_a?(Module)
291
- begin
292
- ( o.name.nil? ? o.to_s : o.name.to_s )
293
- rescue
293
+ begin
294
+ case
295
+ when o == ActiveSupport::TimeWithZone
296
+ "ActiveSupport::TimeWithZone"
297
+ when o.is_a?(Module)
294
298
  begin
295
- ( o.nil? ? "nil" : o.to_s )
299
+ ( o.name.nil? ? o.to_s : o.name.to_s )
296
300
  rescue
297
- "nil"
301
+ begin
302
+ ( o.nil? ? "nil" : o.to_s )
303
+ rescue
304
+ ( o == nil ? "nil" : o.to_s ) # in case of monkey patched nil?
305
+ end
298
306
  end
307
+ when o.is_a?(Method), o.is_a?(UnboundMethod)
308
+ o.name.to_s
309
+ else
310
+ o.to_s
299
311
  end
300
- when o.is_a?(Method), o.is_a?(UnboundMethod)
301
- o.name.to_s
302
- else
303
- o.to_s
312
+ rescue
313
+ "Veracode" #should result in this being dropped from the archive since we can't get a safe name for it
304
314
  end
305
315
  end
306
316
 
@@ -392,8 +402,8 @@ module Veracode
392
402
 
393
403
  if with_disasm
394
404
  insns = RubyVM::InstructionSequence.disassemble(m)
395
- formatted += ( (insns.nil? || insns.empty?) ?
396
- "== disasm\n== end disasm\n" :
405
+ formatted += ( (insns.nil? || insns.empty? || insns[/.*#{@expanded_app_dir}.*/].nil?) ?
406
+ "\n" :
397
407
  "#{insns}== end disasm\n"
398
408
  )
399
409
  end
@@ -419,20 +429,25 @@ module Veracode
419
429
  ##############################################################################
420
430
  # Archiving Headers
421
431
  def self.class_header(c)
422
- return "" unless c.is_a? Class
432
+ begin
433
+ return "" unless c.is_a? Class
434
+
435
+ puts " class header" if $options[:verbose]
423
436
 
424
- puts " class header" if $options[:verbose]
437
+ case
438
+ when c.superclass.nil? # this should only happen for BasicObject
439
+ return ""
440
+ when c.superclass.name.nil? # in case the parent is anonymous
441
+ name = c.superclass.to_s.dump
442
+ else
443
+ name = c.superclass.name.dump
444
+ end
425
445
 
426
- case
427
- when c.superclass.nil? # this should only happen for BasicObject
446
+ "superclass #{name}\n"
447
+ rescue Exception => e
448
+ log_error e.message
428
449
  return ""
429
- when c.superclass.name.nil? # in case the parent is anonymous
430
- name = c.superclass.to_s.dump
431
- else
432
- name = c.superclass.name.dump
433
450
  end
434
-
435
- "superclass #{name}\n"
436
451
  end
437
452
 
438
453
  def self.module_header(m)
@@ -531,7 +546,14 @@ module Veracode
531
546
  end
532
547
 
533
548
  def self.object_contents(o, with_disasm=true)
534
- return "" unless !o.nil? && o.is_a?(Object)
549
+ begin
550
+ return "" unless !o.nil?
551
+ rescue Exception => e
552
+ log_error "Error testing #{o} with nil?. Probable monkey patching. #{e.message}"
553
+ return "" if o == nil
554
+ end
555
+
556
+ return "" unless o.is_a?(Object)
535
557
 
536
558
  puts " object contents" if $options[:verbose]
537
559
 
@@ -575,12 +597,28 @@ module Veracode
575
597
  ##############################################################################
576
598
  # Archiving Objects
577
599
  def self.archive(objects, with_disasm=true)
578
- objects = objects - [
579
- Veracode,
580
- Veracode::ActiveRecord,
581
- Veracode::ActiveRecord::Model,
582
- Veracode::ActiveRecord::Schema,
583
- ]
600
+ veracode_artifacts = Set[
601
+ safe_name(Veracode),
602
+ safe_name(Veracode::ActiveRecord),
603
+ safe_name(Veracode::ActiveRecord::Model),
604
+ safe_name(Veracode::ActiveRecord::Schema)
605
+ ]
606
+ rails_filters = [
607
+ "ActionCable::",
608
+ "ActionController::",
609
+ "ActionDispatch::",
610
+ "ActionMailer::",
611
+ "ActiveJob::",
612
+ "ActiveSupport::",
613
+ "ActiveStorage::",
614
+ "ActionView::(?!CompiledTemplates)", #Allows Compiled templates with the not group
615
+ "ActiveRecord::",
616
+ ]
617
+ objects = objects.reject do |o|
618
+ sn = safe_name(o).dup
619
+ while with_disasm && !sn.slice!(/^#<(Class|Module):/).nil? do sn = sn[0..-2] end #strip #<Class: and #<Module: prefix, strip corresponding > suffix
620
+ veracode_artifacts.include?(sn) || (with_disasm && sn[/^(#{rails_filters.join('|')}).*/])
621
+ end
584
622
 
585
623
  if $options[:verbose]
586
624
  puts "Archiving #{objects.count.to_s} objects" + (with_disasm ? " with disassembly" : "")
@@ -589,18 +627,47 @@ module Veracode
589
627
 
590
628
  objects.sort_by {|o| safe_name(o) }.each do |o|
591
629
 
592
- puts "archiving #{o.class.to_s.downcase} #{quote(safe_name(o))}" if $options[:verbose]
630
+ sn = safe_name(o)
631
+ puts "archiving #{o.class.to_s.downcase} #{quote(sn)}" if $options[:verbose]
593
632
 
594
- add_to_archive "#{o.class.to_s.downcase} #{quote(safe_name(o))}\n" +
633
+ add_to_archive "#{o.class.to_s.downcase} #{quote(sn)}\n" +
595
634
  ( o.is_a?(Class) ? class_header(o) : "") + # superclass
635
+ ( @rails6 && sn == "ActionView::Base" ? "include \"ActionView::CompiledTemplates\"\n" : "") + #hack for rails 6 compiled template output
596
636
  ( o.is_a?(Module) ? module_header(o) : "") + # included modules
597
- ( (o.is_a?(Object) && !o.nil?) ? object_contents(o, with_disasm) : "") +
637
+ ( o.is_a?(Object) ? object_contents(o, with_disasm) : "") +
598
638
  ( o.is_a?(Module) ? module_contents(o, with_disasm) : "") +
599
639
  "end#{o.class.to_s.downcase}\n" +
600
640
  "\n"
601
641
  end
602
642
  end
603
643
 
644
+ def self.archive_rails6_templates
645
+ puts "archiving views" if $options[:verbose]
646
+ o = @view.compiled_method_container
647
+ compiled_views = o.instance_methods - @view_methods
648
+ formatted_contents = ""
649
+ for m_symbol in compiled_views
650
+ begin
651
+ m = o.instance_method(m_symbol)
652
+ formatted_contents += format_method(m, "public_instance", true)
653
+ rescue Exception => e
654
+ log_error "Error archiving singleton method #{m_symbol.to_s.dump}: #{e.message}"
655
+ end
656
+ 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
+ end
670
+
604
671
 
605
672
  def self.compile_templates
606
673
 
@@ -647,7 +714,7 @@ module Veracode
647
714
  assigns = {}
648
715
  view = ActionView::Base.new(view_paths, assigns)
649
716
  begin
650
- controller_view = ApplicationController.new.view_context
717
+
651
718
  rescue Exception => e
652
719
  log_error "Unable to get controller view context (#{e.message})"
653
720
  end
@@ -663,9 +730,11 @@ module Veracode
663
730
  end
664
731
  }
665
732
 
666
- puts "Compiled #{ActionView::CompiledTemplates.instance_methods.count.to_s} templates" if $options[:verbose]
667
- log_error "Compiled #{ActionView::CompiledTemplates.instance_methods.count.to_s} templates"
668
- log_error "Not all templates were compiled" if ActionView::CompiledTemplates.instance_methods.count < templates.count
733
+ unless @rails6
734
+ puts "Compiled #{ActionView::CompiledTemplates.instance_methods.count.to_s} templates" if $options[:verbose]
735
+ log_error "Compiled #{ActionView::CompiledTemplates.instance_methods.count.to_s} templates"
736
+ log_error "Not all templates were compiled" if ActionView::CompiledTemplates.instance_methods.count < templates.count
737
+ end
669
738
  end
670
739
 
671
740
  def self.compile_erb_templates
@@ -708,7 +777,9 @@ module Veracode
708
777
  )
709
778
 
710
779
  case t.method(:compile).arity
711
- when 2 # Rails 3.1.0+
780
+ when 1 # Rails 6
781
+ t.send(:compile, @view)
782
+ when 2 # Rails 3.1.0+
712
783
  t.send(:compile, ActionView::Base.new, ActionView::CompiledTemplates)
713
784
  when 3
714
785
  t.send(:compile, {}, ActionView::Base.new, ActionView::CompiledTemplates)
@@ -721,7 +792,7 @@ module Veracode
721
792
 
722
793
  }
723
794
 
724
- puts "Compiled templates: " + ActionView::CompiledTemplates.instance_methods.count.to_s if $options[:verbose]
795
+ puts "Compiled templates: " + ActionView::CompiledTemplates.instance_methods.count.to_s if $options[:verbose] && !@rails6
725
796
 
726
797
  end
727
798
 
@@ -764,7 +835,9 @@ module Veracode
764
835
  )
765
836
 
766
837
  case t.method(:compile).arity
767
- when 2 # Rails 3.1.0+
838
+ when 1 # Rails 6
839
+ t.send(:compile, @view)
840
+ when 2 # Rails 3.1.0+
768
841
  t.send(:compile, ActionView::Base.new, ActionView::CompiledTemplates)
769
842
  when 3
770
843
  t.send(:compile, {}, ActionView::Base.new, ActionView::CompiledTemplates)
@@ -777,7 +850,7 @@ module Veracode
777
850
 
778
851
  }
779
852
 
780
- puts "Compiled templates: " + ActionView::CompiledTemplates.instance_methods.count.to_s if $options[:verbose]
853
+ puts "Compiled templates: " + ActionView::CompiledTemplates.instance_methods.count.to_s if $options[:verbose] && !@rails6
781
854
 
782
855
  end
783
856
 
@@ -795,6 +868,9 @@ module Veracode
795
868
  lib = "#{part}/#{lib}"
796
869
  lib = lib[0..lib.length-2] if lib[lib.length-1] == '/'
797
870
  begin
871
+ if @rails6 && (lib =~ /node_modules/ || lib == 'debug')
872
+ next
873
+ end
798
874
  if cond_require lib
799
875
  puts "requiring #{lib}" if $options[:verbose]
800
876
  end
@@ -834,9 +910,6 @@ def self.require_rails(gemdir)
834
910
  end
835
911
  end
836
912
 
837
-
838
-
839
-
840
913
  ################################################################################
841
914
  # Subcommands
842
915
  def self.prepare
@@ -888,11 +961,12 @@ end
888
961
  puts "Required rails" if $options[:verbose]
889
962
  end
890
963
 
964
+ @rails6 = Gem::Version.new(Rails.version) >= Gem::Version.new("6.0.0")
891
965
  ## Imitate script/rails
892
966
  # APP_PATH = File.expand_path('config/application')
893
- # APP_PATH is already set in bin/veracode
967
+ # APP_PATH is already set in bin/veracode
894
968
  #require File.expand_path('../../config/boot', __FILE__)
895
- glob_require "config/boot.rb"
969
+ glob_require "config/boot.rb"
896
970
  #require 'rails/commands'
897
971
  # this will trigger the console to be launched
898
972
  # ARGV.clear
@@ -901,7 +975,16 @@ end
901
975
  # require 'rails/commands'
902
976
 
903
977
  ## Imitate rails/commands when console
904
- cond_require 'rails/commands/console.rb'
978
+ if @rails6 || Gem::Version.new(Rails.version) >= Gem::Version.new("5.1.0")
979
+ cond_require 'rails/command.rb'
980
+ cond_require 'rails/command/actions.rb'
981
+ cond_require 'rails/command/base.rb'
982
+ cond_require 'rails/command/behavior.rb'
983
+ cond_require 'rails/command/environment_argument.rb'
984
+ cond_require 'rails/commands/console/console_command.rb'
985
+ else
986
+ cond_require 'rails/commands/console.rb'
987
+ end
905
988
  # require APP_PATH # => config/application.rb
906
989
 
907
990
  glob_require "config/application.rb"
@@ -937,36 +1020,63 @@ end
937
1020
 
938
1021
  puts "Phase 3 - Imitate Rails" if $options[:verbose]
939
1022
 
940
- any_new = true
941
- while any_new
942
- any_new = false
943
- any_new |= glob_require "lib/**/*.rb"
944
- any_new |= glob_require "app/**/*.rb"
945
- puts "new successful requires? #{any_new.to_s}" if $options[:verbose]
946
- end
1023
+ begin
1024
+ any_new = true
1025
+ while any_new
1026
+ any_new = false
1027
+ any_new |= glob_require "lib/**/*.rb"
1028
+ any_new |= glob_require "app/**/*.rb"
1029
+ puts "new successful requires? #{any_new.to_s}" if $options[:verbose]
1030
+ end
947
1031
 
948
- compile_templates
1032
+ begin
1033
+ if @rails6
1034
+ self.update
1035
+ @view = ActionView::Base.with_empty_template_cache
1036
+ @view_methods = @view.compiled_method_container.instance_methods
1037
+ compile_erb_templates
1038
+ compile_haml_templates
1039
+ self.stats if $options[:verbose]
1040
+ else
1041
+ compile_templates
1042
+ self.update
1043
+ self.stats if $options[:verbose]
1044
+ end
1045
+ rescue Exception => e
1046
+ puts "Unable to compile templates: #{e.message}" if $options[:verbose]
1047
+ log_error "Unable to compile templates: #{e.message}"
1048
+ end
949
1049
 
950
- self.update
951
- self.stats if $options[:verbose]
1050
+ # Ensure compiled templates are fully disassembled in archive
1051
+ @baseline_modules.delete(ActionView::CompiledTemplates) unless @rails6
952
1052
 
953
- # Ensure compiled templates are fully disassembled in archive
954
- @baseline_modules.delete(ActionView::CompiledTemplates)
1053
+ if $options[:environment]
1054
+ puts "Processing and disassembling environment"
1055
+ archive(@modules.reject {|o| safe_name(o) =~ /^#<(Class|Module):0x[0-9a-f]+>/i }
1056
+ .reject {|o| safe_name(o) =~ /^Veracode/ }
1057
+ .reject {|o| safe_name(o) =~ /^EmptyRails/ }
1058
+ .reject {|o| safe_name(o) =~ /^ActionView::CompiledTemplates$/ }, false)
1059
+ else
1060
+ puts "Processing Ruby and Rails classes and modules"
1061
+ archive(@baseline_modules, false)
1062
+ add_to_archive "\n# Phase 3 - App disassembly\n"
1063
+ puts "Processing and disassembling #{APP_NAME} classes and modules"
1064
+ safe_baseline_modules = @baseline_modules.each_with_object(Set.new) { |o, s| s << safe_name(o) }
1065
+ archive(@modules.reject {|o| safe_baseline_modules.include?(safe_name(o))}, true)
1066
+ if @rails6
1067
+ archive_rails6_templates()
1068
+ end
1069
+ archive_schema
955
1070
 
956
- if $options[:environment]
957
- puts "Processing and disassembling environment"
958
- archive(@modules.reject {|o| safe_name(o) =~ /^#<(Class|Module):0x[0-9a-f]+>/i }
959
- .reject {|o| safe_name(o) =~ /^Veracode/ }
960
- .reject {|o| safe_name(o) =~ /^EmptyRails/ }
961
- .reject {|o| safe_name(o) =~ /^ActionView::CompiledTemplates$/ }, false)
962
- else
963
- puts "Processing Ruby and Rails classes and modules"
964
- archive(@baseline_modules, false)
965
- add_to_archive "\n# Phase 3 - App disassembly\n"
966
- puts "Processing and disassembling #{APP_NAME} classes and modules"
967
- archive(@modules - @baseline_modules, true)
968
- archive_schema
1071
+ end
969
1072
 
1073
+ rescue Exception => e
1074
+ if $options[:snapshot]
1075
+ log_error e.message
1076
+ log_error e.backtrace.join("\n")
1077
+ else
1078
+ raise
1079
+ end
970
1080
  end
971
1081
 
972
1082
  ## /phase 3 - require app
@@ -1,4 +1,4 @@
1
1
  module Veracode
2
- VERSION = '1.0.0.alpha16'
3
- ARCHIVE_VERSION = '2012-07-04'
2
+ VERSION = '1.0.1'
3
+ ARCHIVE_VERSION = '2020-06-29'
4
4
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veracode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha16
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Veracode
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-24 00:00:00.000000000 Z
11
+ date: 2021-02-03 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
- version: '1.0'
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
- version: '1.0'
26
+ version: '1.3'
27
27
  description: Prepares your Ruby on Rails app for submission to Veracode.
28
28
  email: devcontact@veracode.com
29
29
  executables:
@@ -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
@@ -50,13 +50,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  version: 1.9.3.0
51
51
  required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 1.3.1
55
+ version: '0'
56
56
  requirements: []
57
- rubyforge_project:
58
- rubygems_version: 2.7.8
59
- signing_key:
57
+ rubygems_version: 3.1.4
58
+ signing_key:
60
59
  specification_version: 4
61
60
  summary: Command line tool for preparing your Ruby on Rails app for submission to
62
61
  Veracode