Class: Pipeline::NodeSecurityProject

Inherits:
BaseTask
  • Object
show all
Includes:
Util
Defined in:
lib/pipeline/tasks/nsp.rb

Instance Attribute Summary

Attributes inherited from BaseTask

#appname, #description, #findings, #labels, #name, #stage, #trigger, #warnings

Instance Method Summary collapse

Methods included from Util

#fingerprint, #relative_path, #runsystem, #strip_archive_path

Methods inherited from BaseTask

#report, #severity, #warn

Constructor Details

#initialize(trigger, tracker) ⇒ NodeSecurityProject

Returns a new instance of NodeSecurityProject.



9
10
11
12
13
14
15
# File 'lib/pipeline/tasks/nsp.rb', line 9

def initialize(trigger, tracker)
  super(trigger, tracker)
  @name = "NodeSecurityProject"
  @description = "Node Security Project"
  @stage = :code
  @labels << "code"
end

Instance Method Details

#analyzeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pipeline/tasks/nsp.rb', line 25

def analyze
  begin
    # This block iterates through each package name found and selects the unique nsp advisories
    # regardless of version, and builds a pipeline finding hash for each unique package/advisory combo.
    @results.uniq {|finding| finding['module']}.each do |package|
      @results.select {|f| f['module'] == package['module']}.uniq {|m| m['advisory']}.each do |unique_finding|
        description = "#{unique_finding['module']} - #{unique_finding['title']}"
        detail = "Upgrade to versions: #{unique_finding['patched_versions']}\n#{unique_finding['advisory']}"
        source = {
          :scanner => 'NodeSecurityProject',
          :file => "#{unique_finding['module']} - #{unique_finding['vulnerable_versions']}",
          :line => nil,
          :code => nil
        }
        report description, detail, source, 'medium', fingerprint("#{description}#{detail}#{source}")
      end
    end
  rescue Exception => e
    Pipeline.warn e.message
    Pipeline.warn e.backtrace
  end
end

#runObject



17
18
19
20
21
22
23
# File 'lib/pipeline/tasks/nsp.rb', line 17

def run
  Pipeline.notify "#{@name}"
  rootpath = @trigger.path
  Dir.chdir("#{rootpath}") do
    @results = JSON.parse `nsp check --output json 2>&1`
  end
end

#supported?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/pipeline/tasks/nsp.rb', line 48

def supported?
  supported=runsystem(true, "nsp", "--version")
  if supported =~ /command not found/
    Pipeline.notify "Install nodesecurity: 'npm install -g nsp'"
    return false
  else
    return true
  end
end