Commit ec339d87 authored by Cameron Swords's avatar Cameron Swords Committed by Stan Hu

Verify deprecated DAST report format

Added specific DAST report examples
parent 17517bc8
......@@ -5,52 +5,17 @@ module Gitlab
module Parsers
module Security
class Dast < Common
FORMAT_VERSION = '2.0'.freeze
protected
def parse_report(json_data)
report = super
format_report(report)
end
private
return Formatters::Dast.new(report).format if Formatters::Dast.satisfies?(report)
def format_report(data)
{
'vulnerabilities' => extract_vulnerabilities_from(Array.wrap(data['site'])),
'version' => FORMAT_VERSION
}
report
end
# Log messages to be added here to track usage of legacy reports,
# parsing failures and any other scenarios: https://gitlab.com/gitlab-org/gitlab/issues/34668
def extract_vulnerabilities_from(sites = [])
return [] if sites.empty?
vulnerabilities = []
sites.each do |site|
site_report = Hash(site)
next if site_report.blank?
# If host is blank for legacy reports
host = site_report['@name']
site_report['alerts'].each do |vulnerability|
vulnerabilities += flatten_vulnerabilities(vulnerability, host)
end
end
vulnerabilities
end
def flatten_vulnerabilities(vulnerability, host)
vulnerability['instances'].map do |instance|
Formatters::Dast.new(vulnerability).format(instance, host)
end
end
private
def create_location(location_data)
::Gitlab::Ci::Reports::Security::Locations::Dast.new(
......
......@@ -6,11 +6,53 @@ module Gitlab
module Security
module Formatters
class Dast
def initialize(vulnerability)
@vulnerability = vulnerability
FORMAT_VERSION = '2.0'.freeze
def initialize(report)
@report = report
end
def self.satisfies?(report)
report.key?('site') && !report.key?('vulnerabilities')
end
def format(instance, hostname)
def format
{
'vulnerabilities' => extract_vulnerabilities_from(Array.wrap(@report['site'])),
'version' => FORMAT_VERSION
}
end
private
# Log messages to be added here to track usage of legacy reports,
# parsing failures and any other scenarios: https://gitlab.com/gitlab-org/gitlab/issues/34668
def extract_vulnerabilities_from(sites = [])
return [] if sites.empty?
vulnerabilities = []
sites.each do |site|
site_report = Hash(site)
next if site_report.blank?
# If host is blank for legacy reports
host = site_report['@name']
site_report['alerts'].each do |vulnerability|
vulnerabilities += flatten_vulnerabilities(vulnerability, host)
end
end
vulnerabilities
end
def flatten_vulnerabilities(vulnerability, host)
vulnerability['instances'].map { |instance| format_vulnerability(vulnerability, instance, host) }
end
def format_vulnerability(vulnerability, instance, hostname)
{
'category' => 'dast',
'message' => vulnerability['name'],
......@@ -50,10 +92,6 @@ module Gitlab
}
end
private
attr_reader :vulnerability
SEVERITY_MAPPING = %w{info low medium high}.freeze
CONFIDENCE_MAPPING = %w{ignore low medium high confirmed}.freeze
......
......@@ -42,13 +42,25 @@ FactoryBot.define do
end
end
trait :dast_deprecated do
trait :dast_deprecated_no_spider do
file_format { :raw }
file_type { :dast }
after(:build) do |artifact, _|
artifact.file = fixture_file_upload(
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-dast-report.json'), 'application/json')
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-dast-report-no-spider.json'), 'application/json')
end
end
trait :dast_deprecated_no_common_fields do
file_format { :raw }
file_type { :dast }
after(:build) do |artifact, _|
artifact.file = fixture_file_upload(
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-dast-report-no-common-fields.json'),
'application/json'
)
end
end
......
{
"@generated": "Fri, 13 Apr 2018 09:22:01",
"@version": "2.7.0",
"site": [
{
"@host": "goat",
"@name": "http://goat:8080",
"@port": "8080",
"@ssl": "false",
"alerts": [
{
"alert": "Anti CSRF Tokens Scanner",
"confidence": "2",
"count": "4",
"cweid": "352",
"desc": "<p>A cross-site request forgery is an attack that involves forcing a victim to send an HTTP request to a target destination without their knowledge or intent in order to perform an action as the victim. The underlying cause is application functionality using predictable URL/form actions in a repeatable way. The nature of the attack is that CSRF exploits the trust that a web site has for a user. By contrast, cross-site scripting (XSS) exploits the trust that a user has for a web site. Like XSS, CSRF attacks are not necessarily cross-site, but they can be. Cross-site request forgery is also known as CSRF, XSRF, one-click attack, session riding, confused deputy, and sea surf.</p><p></p><p>CSRF attacks are effective in a number of situations, including:</p><p> * The victim has an active session on the target site.</p><p> * The victim is authenticated via HTTP auth on the target site.</p><p> * The victim is on the same local network as the target site.</p><p></p><p>CSRF has primarily been used to perform an action against a target site using the victim's privileges, but recent techniques have been discovered to disclose information by gaining access to the response. The risk of information disclosure is dramatically increased when the target site is vulnerable to XSS, because XSS can be used as a platform for CSRF, allowing the attack to operate within the bounds of the same-origin policy.</p>",
"instances": [
{
"attack": "",
"evidence": "<form method=\"POST\" style=\"width: 200px;\" action=\"/WebGoat/login\">",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/login"
},
{
"attack": "",
"evidence": "<form method=\"POST\" style=\"width: 200px;\" action=\"/WebGoat/login\">",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/login?error"
},
{
"attack": "",
"evidence": "<form class=\"form-horizontal\" action=\"/WebGoat/register.mvc\" method=\"POST\">",
"method": "POST",
"param": "",
"uri": "http://goat:8080/WebGoat/register.mvc"
},
{
"attack": "",
"evidence": "<form class=\"form-horizontal\" action=\"/WebGoat/register.mvc\" method=\"POST\">",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/registration"
}
],
"name": "Anti CSRF Tokens Scanner",
"otherinfo": "",
"pluginid": "20012",
"reference": "<p>http://projects.webappsec.org/Cross-Site-Request-Forgery</p><p>http://cwe.mitre.org/data/definitions/352.html</p>",
"riskcode": "3",
"riskdesc": "High (Medium)",
"solution": "<p>Phase: Architecture and Design</p><p>Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.</p><p>For example, use anti-CSRF packages such as the OWASP CSRFGuard.</p><p></p><p>Phase: Implementation</p><p>Ensure that your application is free of cross-site scripting issues, because most CSRF defenses can be bypassed using attacker-controlled script.</p><p></p><p>Phase: Architecture and Design</p><p>Generate a unique nonce for each form, place the nonce into the form, and verify the nonce upon receipt of the form. Be sure that the nonce is not predictable (CWE-330).</p><p>Note that this can be bypassed using XSS.</p><p></p><p>Identify especially dangerous operations. When the user performs a dangerous operation, send a separate confirmation request to ensure that the user intended to perform that operation.</p><p>Note that this can be bypassed using XSS.</p><p></p><p>Use the ESAPI Session Management control.</p><p>This control includes a component for CSRF.</p><p></p><p>Do not use the GET method for any request that triggers a state change.</p><p></p><p>Phase: Implementation</p><p>Check the HTTP Referer header to see if the request originated from an expected page. This could break legitimate functionality, because users or proxies may have disabled sending the Referer for privacy reasons.</p>",
"sourceid": "1",
"wascid": "9"
},
{
"alert": "Absence of Anti-CSRF Tokens",
"confidence": "2",
"count": "4",
"cweid": "352",
"desc": "<p>No Anti-CSRF tokens were found in a HTML submission form.</p><p>A cross-site request forgery is an attack that involves forcing a victim to send an HTTP request to a target destination without their knowledge or intent in order to perform an action as the victim. The underlying cause is application functionality using predictable URL/form actions in a repeatable way. The nature of the attack is that CSRF exploits the trust that a web site has for a user. By contrast, cross-site scripting (XSS) exploits the trust that a user has for a web site. Like XSS, CSRF attacks are not necessarily cross-site, but they can be. Cross-site request forgery is also known as CSRF, XSRF, one-click attack, session riding, confused deputy, and sea surf.</p><p></p><p>CSRF attacks are effective in a number of situations, including:</p><p> * The victim has an active session on the target site.</p><p> * The victim is authenticated via HTTP auth on the target site.</p><p> * The victim is on the same local network as the target site.</p><p></p><p>CSRF has primarily been used to perform an action against a target site using the victim's privileges, but recent techniques have been discovered to disclose information by gaining access to the response. The risk of information disclosure is dramatically increased when the target site is vulnerable to XSS, because XSS can be used as a platform for CSRF, allowing the attack to operate within the bounds of the same-origin policy.</p>",
"instances": [
{
"attack": "",
"evidence": "<form method=\"POST\" style=\"width: 200px;\" action=\"/WebGoat/login\">",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/login"
},
{
"attack": "",
"evidence": "<form method=\"POST\" style=\"width: 200px;\" action=\"/WebGoat/login\">",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/login?error"
},
{
"attack": "",
"evidence": "<form class=\"form-horizontal\" action=\"/WebGoat/register.mvc\" method=\"POST\">",
"method": "POST",
"param": "",
"uri": "http://goat:8080/WebGoat/register.mvc"
},
{
"attack": "",
"evidence": "<form class=\"form-horizontal\" action=\"/WebGoat/register.mvc\" method=\"POST\">",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/registration"
}
],
"name": "Absence of Anti-CSRF Tokens",
"otherinfo": "<p>No known Anti-CSRF token [anticsrf, CSRFToken, __RequestVerificationToken, csrfmiddlewaretoken, authenticity_token, OWASP_CSRFTOKEN, anoncsrf, csrf_token, _csrf, _csrfSecret] was found in the following HTML form: [Form 1: \"exampleInputEmail1\" \"exampleInputPassword1\" ].</p>",
"pluginid": "10202",
"reference": "<p>http://projects.webappsec.org/Cross-Site-Request-Forgery</p><p>http://cwe.mitre.org/data/definitions/352.html</p>",
"riskcode": "1",
"riskdesc": "Low (Medium)",
"solution": "<p>Phase: Architecture and Design</p><p>Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.</p><p>For example, use anti-CSRF packages such as the OWASP CSRFGuard.</p><p></p><p>Phase: Implementation</p><p>Ensure that your application is free of cross-site scripting issues, because most CSRF defenses can be bypassed using attacker-controlled script.</p><p></p><p>Phase: Architecture and Design</p><p>Generate a unique nonce for each form, place the nonce into the form, and verify the nonce upon receipt of the form. Be sure that the nonce is not predictable (CWE-330).</p><p>Note that this can be bypassed using XSS.</p><p></p><p>Identify especially dangerous operations. When the user performs a dangerous operation, send a separate confirmation request to ensure that the user intended to perform that operation.</p><p>Note that this can be bypassed using XSS.</p><p></p><p>Use the ESAPI Session Management control.</p><p>This control includes a component for CSRF.</p><p></p><p>Do not use the GET method for any request that triggers a state change.</p><p></p><p>Phase: Implementation</p><p>Check the HTTP Referer header to see if the request originated from an expected page. This could break legitimate functionality, because users or proxies may have disabled sending the Referer for privacy reasons.</p>",
"sourceid": "3",
"wascid": "9"
},
{
"alert": "Cookie No HttpOnly Flag",
"confidence": "2",
"count": "2",
"cweid": "16",
"desc": "<p>A cookie has been set without the HttpOnly flag, which means that the cookie can be accessed by JavaScript. If a malicious script can be run on this page then the cookie will be accessible and can be transmitted to another site. If this is a session cookie then session hijacking may be possible.</p>",
"instances": [
{
"attack": "",
"evidence": "Set-Cookie: JSESSIONID",
"method": "GET",
"param": "JSESSIONID",
"uri": "http://goat:8080/WebGoat/login?logout"
},
{
"attack": "",
"evidence": "Set-Cookie: JSESSIONID",
"method": "GET",
"param": "JSESSIONID",
"uri": "http://goat:8080/WebGoat/logout"
}
],
"name": "Cookie No HttpOnly Flag",
"otherinfo": "",
"pluginid": "10010",
"reference": "<p>http://www.owasp.org/index.php/HttpOnly</p>",
"riskcode": "1",
"riskdesc": "Low (Medium)",
"solution": "<p>Ensure that the HttpOnly flag is set for all cookies.</p>",
"sourceid": "3",
"wascid": "13"
},
{
"alert": "Cookie Without SameSite Attribute",
"confidence": "2",
"count": "2",
"cweid": "16",
"desc": "<p>A cookie has been set without the SameSite attribute, which means that the cookie can be sent as a result of a 'cross-site' request. The SameSite attribute is an effective counter measure to cross-site request forgery, cross-site script inclusion, and timing attacks.</p>",
"instances": [
{
"attack": "",
"evidence": "Set-Cookie: JSESSIONID",
"method": "GET",
"param": "JSESSIONID",
"uri": "http://goat:8080/WebGoat/login?logout"
},
{
"attack": "",
"evidence": "Set-Cookie: JSESSIONID",
"method": "GET",
"param": "JSESSIONID",
"uri": "http://goat:8080/WebGoat/logout"
}
],
"name": "Cookie Without SameSite Attribute",
"otherinfo": "",
"pluginid": "10054",
"reference": "<p>https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site</p>",
"riskcode": "1",
"riskdesc": "Low (Medium)",
"solution": "<p>Ensure that the SameSite attribute is set to either 'lax' or ideally 'strict' for all cookies.</p>",
"sourceid": "3",
"wascid": "13"
},
{
"alert": "Charset Mismatch (Header Versus Meta Content-Type Charset)",
"confidence": "1",
"count": "1",
"cweid": "16",
"desc": "<p>This check identifies responses where the HTTP Content-Type header declares a charset different from the charset defined by the body of the HTML or XML. When there's a charset mismatch between the HTTP header and content body Web browsers can be forced into an undesirable content-sniffing mode to determine the content's correct character set.</p><p></p><p>An attacker could manipulate content on the page to be interpreted in an encoding of their choice. For example, if an attacker can control content at the beginning of the page, they could inject script using UTF-7 encoded text and manipulate some browsers into interpreting that text.</p>",
"instances": [
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/start.mvc"
}
],
"name": "Charset Mismatch (Header Versus Meta Content-Type Charset)",
"otherinfo": "<p>There was a charset mismatch between the HTTP Header and the META content-type encoding declarations: [UTF-8] and [ISO-8859-1] do not match.</p>",
"pluginid": "90011",
"reference": "<p>http://code.google.com/p/browsersec/wiki/Part2#Character_set_handling_and_detection</p>",
"riskcode": "0",
"riskdesc": "Informational (Low)",
"solution": "<p>Force UTF-8 for all text content in both the HTTP header and meta tags in HTML or encoding declarations in XML.</p>",
"sourceid": "3",
"wascid": "15"
},
{
"alert": "Information Disclosure - Suspicious Comments",
"confidence": "2",
"count": "4",
"cweid": "200",
"desc": "<p>The response appears to contain suspicious comments which may help an attacker.</p>",
"instances": [
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/js/html5shiv.js"
},
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/js/modernizr-2.6.2.min.js"
},
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/js/respond.min.js"
},
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/start.mvc"
}
],
"name": "Information Disclosure - Suspicious Comments",
"otherinfo": "<p><!--<button type=\"button\" id=\"admin-button\" class=\"btn btn-default right_nav_button\" title=\"Administrator\">--></p><p><!--<button type=\"button\" id=\"user-management\" class=\"btn btn-default right_nav_button\"--></p><p><!--title=\"User management\">--></p><p></p>",
"pluginid": "10027",
"reference": "<p></p>",
"riskcode": "0",
"riskdesc": "Informational (Medium)",
"solution": "<p>Remove all comments that return information that may help an attacker and fix any underlying problems they refer to.</p>",
"sourceid": "3",
"wascid": "13"
},
{
"alert": "Loosely Scoped Cookie",
"confidence": "1",
"count": "2",
"cweid": "565",
"desc": "<p>Cookies can be scoped by domain or path. This check is only concerned with domain scope.The domain scope applied to a cookie determines which domains can access it. For example, a cookie can be scoped strictly to a subdomain e.g. www.nottrusted.com, or loosely scoped to a parent domain e.g. nottrusted.com. In the latter case, any subdomain of nottrusted.com can access the cookie. Loosely scoped cookies are common in mega-applications like google.com and live.com. Cookies set from a subdomain like app.foo.bar are transmitted only to that domain by the browser. However, cookies scoped to a parent-level domain may be transmitted to the parent, or any subdomain of the parent.</p>",
"instances": [
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/login?logout"
},
{
"attack": "",
"evidence": "",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/logout"
}
],
"name": "Loosely Scoped Cookie",
"otherinfo": "<p>The origin domain used for comparison was: </p><p>goat</p><p>JSESSIONID=78EC2C9D7CE583610DCC7826EE416D7F</p><p></p>",
"pluginid": "90033",
"reference": "<p>https://tools.ietf.org/html/rfc6265#section-4.1</p><p>https://www.owasp.org/index.php/Testing_for_cookies_attributes_(OTG-SESS-002)</p><p>http://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_cookies</p>",
"riskcode": "0",
"riskdesc": "Informational (Low)",
"solution": "<p>Always scope cookies to a FQDN (Fully Qualified Domain Name).</p>",
"sourceid": "3",
"wascid": "15"
},
{
"alert": "Timestamp Disclosure - Unix",
"confidence": "1",
"count": "5",
"cweid": "200",
"desc": "<p>A timestamp was disclosed by the application/web server - Unix</p>",
"instances": [
{
"attack": "",
"evidence": "00000000",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/plugins/bootstrap/css/bootstrap.min.css"
},
{
"attack": "",
"evidence": "33333333",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/plugins/bootstrap/css/bootstrap.min.css"
},
{
"attack": "",
"evidence": "42857143",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/plugins/bootstrap/css/bootstrap.min.css"
},
{
"attack": "",
"evidence": "80000000",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/plugins/bootstrap/css/bootstrap.min.css"
},
{
"attack": "",
"evidence": "66666667",
"method": "GET",
"param": "",
"uri": "http://goat:8080/WebGoat/plugins/bootstrap/css/bootstrap.min.css"
}
],
"name": "Timestamp Disclosure - Unix",
"otherinfo": "<p>00000000, which evaluates to: 1970-01-01 00:00:00</p>",
"pluginid": "10096",
"reference": "<p>https://www.owasp.org/index.php/Top_10_2013-A6-Sensitive_Data_Exposure</p><p>http://projects.webappsec.org/w/page/13246936/Information%20Leakage</p>",
"riskcode": "0",
"riskdesc": "Informational (Low)",
"solution": "<p>Manually confirm that the timestamp data is not sensitive, and that the data cannot be aggregated to disclose exploitable patterns.</p>",
"sourceid": "3",
"wascid": "13"
}
]
}
],
"spider": {
"progress": "100",
"result": {
"urlsInScope": [
{
"method": "GET",
"processed": "false",
"reasonNotProcessed": "Not Text",
"statusCode": "404",
"statusReason": "",
"url": "http://goat:8080/"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat/"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat/attack"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/css/animate.css"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/css/coderay.css"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/css/font-awesome.min.css"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/css/lessons.css"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/css/main.css"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "404",
"statusReason": "",
"url": "http://goat:8080/WebGoat/images/favicon.ico"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/js/html5shiv.js"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/js/libs/require.min.js"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/js/modernizr-2.6.2.min.js"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/js/respond.min.js"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/login"
},
{
"method": "POST",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat/login"
},
{
"method": "GET",
"processed": "false",
"reasonNotProcessed": "Max Depth",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/login?error"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat/login?logout"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat/logout"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/plugins/bootstrap/css/bootstrap.min.css"
},
{
"method": "POST",
"processed": "false",
"reasonNotProcessed": "Max Depth",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/register.mvc"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/registration"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "200",
"statusReason": "",
"url": "http://goat:8080/WebGoat/start.mvc"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat/welcome.mvc"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "302",
"statusReason": "",
"url": "http://goat:8080/WebGoat"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "404",
"statusReason": "",
"url": "http://goat:8080/robots.txt"
},
{
"method": "GET",
"processed": "true",
"reasonNotProcessed": "",
"statusCode": "404",
"statusReason": "",
"url": "http://goat:8080/sitemap.xml"
},
{
"method": "GET",
"processed": "false",
"reasonNotProcessed": "Not Text",
"statusCode": "404",
"statusReason": "",
"url": "http://goat:8080"
}
],
"urlsIoError": [],
"urlsOutOfScope": [
"http://daneden.me/animate",
"http://fontawesome.io/",
"http://fontawesome.io/license",
"http://getbootstrap.com/",
"https://github.com/nickpettit/glide",
"https://github.com/twbs/bootstrap/blob/master/LICENSE"
]
},
"state": "FINISHED"
}
}
......@@ -21,9 +21,10 @@ describe Gitlab::Ci::Parsers::Security::Dast do
:last_occurrence_path,
:last_occurrence_severity,
:last_occurrence_confidence) do
:dast | 24 | 15 | 1 | 'http://goat:8080' | 'GET' | '/WebGoat/plugins/bootstrap/css/bootstrap.min.css' | 'info' | 'low'
:dast_multiple_sites | 25 | 15 | 1 | 'https://goat:8080' | 'GET' | '/WebGoat/registration' | 'high' | 'medium'
:dast_deprecated | 2 | 3 | 1 | 'http://bikebilly-spring-auto-devops-review-feature-br-3y2gpb.35.192.176.43.xip.io' | 'GET' | '/' | 'low' | 'medium'
:dast | 24 | 15 | 1 | 'http://goat:8080' | 'GET' | '/WebGoat/plugins/bootstrap/css/bootstrap.min.css' | 'info' | 'low'
:dast_multiple_sites | 25 | 15 | 1 | 'http://goat:8080' | 'GET' | '/WebGoat/plugins/bootstrap/css/bootstrap.min.css' | 'info' | 'low'
:dast_deprecated_no_spider | 2 | 3 | 1 | 'http://bikebilly-spring-auto-devops-review-feature-br-3y2gpb.35.192.176.43.xip.io' | 'GET' | '/' | 'low' | 'medium'
:dast_deprecated_no_common_fields | 24 | 15 | 1 | 'http://goat:8080' | 'GET' | '/WebGoat/plugins/bootstrap/css/bootstrap.min.css' | 'info' | 'low'
end
with_them do
......
......@@ -3,61 +3,63 @@
require 'spec_helper'
describe Gitlab::Ci::Parsers::Security::Formatters::Dast do
let(:formatter) { described_class.new(file_vulnerability) }
let(:file_vulnerability) { parsed_report['site'].first['alerts'][0] }
let(:formatter) { described_class.new(parsed_report) }
let(:parsed_report) do
JSON.parse!(
File.read(
Rails.root.join('ee/spec/fixtures/security_reports/master/gl-dast-report.json')
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-dast-report-no-common-fields.json')
)
)
end
describe '#format_vulnerability' do
let(:instance) { file_vulnerability['instances'][0] }
let(:hostname) { 'http://goat:8080' }
let(:file_vulnerability) { parsed_report['site'].first['alerts'][0] }
let(:sanitized_desc) { file_vulnerability['desc'].gsub('<p>', '').gsub('</p>', '') }
let(:sanitized_solution) { file_vulnerability['solution'].gsub('<p>', '').gsub('</p>', '') }
let(:version) { parsed_report['@version'] }
it 'format ZAProxy vulnerability into common format' do
data = formatter.format(instance, hostname)
data = formatter.format
expect(data['category']).to eq('dast')
expect(data['message']).to eq('Anti CSRF Tokens Scanner')
expect(data['description']).to eq(sanitized_desc)
expect(data['cve']).to eq('20012')
expect(data['severity']).to eq('high')
expect(data['confidence']).to eq('medium')
expect(data['solution']).to eq(sanitized_solution)
expect(data['scanner']).to eq({ 'id' => 'zaproxy', 'name' => 'ZAProxy' })
expect(data['links']).to eq([{ 'url' => 'http://projects.webappsec.org/Cross-Site-Request-Forgery' },
{ 'url' => 'http://cwe.mitre.org/data/definitions/352.html' }])
expect(data['identifiers'][0]).to eq({
'type' => 'ZAProxy_PluginId',
'name' => 'Anti CSRF Tokens Scanner',
'value' => '20012',
'url' => "https://github.com/zaproxy/zaproxy/blob/w2019-01-14/docs/scanners.md"
})
expect(data['identifiers'][1]).to eq({
'type' => 'CWE',
'name' => "CWE-352",
'value' => '352',
'url' => "https://cwe.mitre.org/data/definitions/352.html"
})
expect(data['identifiers'][2]).to eq({
'type' => 'WASC',
'name' => "WASC-9",
'value' => '9',
'url' => "http://projects.webappsec.org/w/page/13246974/Threat%20Classification%20Reference%20Grid"
})
expect(data['location']).to eq({
'param' => '',
'method' => 'GET',
'hostname' => hostname,
'path' => '/WebGoat/login'
})
expect(data['vulnerabilities'].size).to eq(24)
vulnerability = data['vulnerabilities'][0]
expect(vulnerability['category']).to eq('dast')
expect(vulnerability['message']).to eq('Anti CSRF Tokens Scanner')
expect(vulnerability['description']).to eq(sanitized_desc)
expect(vulnerability['cve']).to eq('20012')
expect(vulnerability['severity']).to eq('high')
expect(vulnerability['confidence']).to eq('medium')
expect(vulnerability['solution']).to eq(sanitized_solution)
expect(vulnerability['scanner']).to eq({ 'id' => 'zaproxy', 'name' => 'ZAProxy' })
expect(vulnerability['links']).to eq([{ 'url' => 'http://projects.webappsec.org/Cross-Site-Request-Forgery' },
{ 'url' => 'http://cwe.mitre.org/data/definitions/352.html' }])
expect(vulnerability['identifiers'][0]).to eq({
'type' => 'ZAProxy_PluginId',
'name' => 'Anti CSRF Tokens Scanner',
'value' => '20012',
'url' => "https://github.com/zaproxy/zaproxy/blob/w2019-01-14/docs/scanners.md"
})
expect(vulnerability['identifiers'][1]).to eq({
'type' => 'CWE',
'name' => "CWE-352",
'value' => '352',
'url' => "https://cwe.mitre.org/data/definitions/352.html"
})
expect(vulnerability['identifiers'][2]).to eq({
'type' => 'WASC',
'name' => "WASC-9",
'value' => '9',
'url' => "http://projects.webappsec.org/w/page/13246974/Threat%20Classification%20Reference%20Grid"
})
expect(vulnerability['location']).to eq({
'param' => '',
'method' => 'GET',
'hostname' => hostname,
'path' => '/WebGoat/login'
})
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment