Class: Dradis::Plugins::Nipper::Importer

Inherits:
Upload::Importer
  • Object
show all
Defined in:
lib/dradis/plugins/nipper/importer.rb

Constant Summary collapse

SECURITY_SECTIONS =
%w{
  SECURITY.INTRODUCTION
  SECURITY.FINDINGS.SUMMARY
  SECURITY.CONCLUSIONS
  SECURITY.RECOMMENDATIONS
  SECURITY.MITIGATIONS
  SECURITY.CLASSIFICATIONS
}

Instance Method Summary collapse

Instance Method Details

#import(params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dradis/plugins/nipper/importer.rb', line 12

def import(params = {})
  file_content = File.read(params[:file])

  logger.info { 'Parsing Nipper output file...' }
  doc = Nokogiri::XML(file_content)
  logger.info { 'Done.' }

  if doc.xpath('//document[@nipperstudio]').empty?
    error = 'No reports were detected in the uploaded file (/report). '\
    'Ensure you uploaded a Nipper XML report.'

    logger.fatal { error }
    content_service.create_note text: error

    return false
  end

  doc.xpath('//document[@nipperstudio]').each do |root|
    logger.info { 'Processing report...' }

    process_node(root)

    root.xpath('./report/part[@ref="SECURITYAUDIT"]/section').each do |report|
      next if SECURITY_SECTIONS.include?(report.attr('ref'))

      process_issue(report)
    end

    logger.info { 'Report processed...' }
  end

  true
end