Commit fd28ebb5 authored by Imre Farkas's avatar Imre Farkas

Merge branch '11024_add_scanned_resources_count_to_security_scan' into 'master'

Store the number of scanned URLs on security_scan

Closes #11024

See merge request gitlab-org/gitlab!27260
parents a6f2c19c 855e7228
# frozen_string_literal: true
class AddScannedResourcesCountToSecurityScan < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column :security_scans, :scanned_resources_count, :integer
end
def down
remove_column :security_scans, :scanned_resources_count
end
end
......@@ -5585,7 +5585,8 @@ CREATE TABLE public.security_scans (
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
build_id bigint NOT NULL,
scan_type smallint NOT NULL
scan_type smallint NOT NULL,
scanned_resources_count integer
);
CREATE SEQUENCE public.security_scans_id_seq
......@@ -12873,6 +12874,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200312163407
20200313101649
20200313123934
20200314060834
20200316111759
20200316162648
20200316173312
......
......@@ -11,12 +11,17 @@ module Security
security_reports = @build.job_artifacts.security_reports
scan_params = security_reports.map do |job_artifact|
{
build: @build,
scan_type: job_artifact.file_type,
scanned_resources_count: Gitlab::Ci::Parsers::Security::ScannedResources.new.scanned_resources_count(job_artifact)
}
end
ActiveRecord::Base.transaction do
security_reports.each do |report|
Security::Scan.safe_find_or_create_by!(
build: @build,
scan_type: report.file_type
)
scan_params.each do |param|
Security::Scan.safe_find_or_create_by!(param)
end
end
end
......
---
title: Add a count of the scanned resources to Security::Scan.
merge_request: 27260
author:
type: added
# frozen_string_literal: true
module Gitlab
module Ci
module Parsers
module Security
class ScannedResources
def scanned_resources_count(job_artifact)
scanned_resources_sum = 0
job_artifact.each_blob do |blob|
report_data = parse_report_json(blob)
scanned_resources_sum += report_data.fetch('scan', {}).fetch('scanned_resources', []).length
end
scanned_resources_sum
end
private
def parse_report_json(blob)
JSON.parse!(blob)
rescue JSON::ParserError
{}
end
end
end
end
end
end
......@@ -42,6 +42,11 @@ FactoryBot.define do
end
end
trait :dast_with_missing_file do
file_format { :raw }
file_type { :dast }
end
trait :dast_deprecated_no_spider do
file_format { :raw }
file_type { :dast }
......@@ -74,6 +79,26 @@ FactoryBot.define do
end
end
trait :dast_missing_scan_field do
file_format { :raw }
file_type { :dast }
after(:build) do |artifact, _|
artifact.file = fixture_file_upload(
Rails.root.join('ee/spec/fixtures/security_reports/master/gl-dast-missing-scan.json'), 'application/json')
end
end
trait :dast_missing_scanned_resources_field do
file_format { :raw }
file_type { :dast }
after(:build) do |artifact, _|
artifact.file = fixture_file_upload(
Rails.root.join('ee/spec/fixtures/security_reports/master/gl-dast-missing-scanned-resources.json'), 'application/json')
end
end
trait :low_severity_dast_report do
file_format { :raw }
file_type { :dast }
......
{
"@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/"
}
],
"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"
},
"version": "2.5",
"vulnerabilities": [
{
"category": "dast",
"confidence": "medium",
"cve": "20012",
"description": "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. CSRF attacks are effective in a number of situations, including: * The victim has an active session on the target site. * The victim is authenticated via HTTP auth on the target site. * The victim is on the same local network as the target site. 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.",
"identifiers": [
{
"name": "Anti CSRF Tokens Scanner",
"type": "ZAProxy_PluginId",
"url": "https://github.com/zaproxy/zaproxy/blob/w2019-01-14/docs/scanners.md",
"value": "20012"
},
{
"name": "CWE-352",
"type": "CWE",
"url": "https://cwe.mitre.org/data/definitions/352.html",
"value": "352"
},
{
"name": "WASC-9",
"type": "WASC",
"url": "https://projects.webappsec.org/Cross-Site-Request-Forgery",
"value": "9"
}
],
"links": [
{
"url": "http://projects.webappsec.org/Cross-Site-Request-Forgery"
},
{
"url": "http://cwe.mitre.org/data/definitions/352.html"
}
],
"location": {
"hostname": "http://goat:8080",
"method": "GET",
"param": "",
"path": "/WebGoat/login"
},
"message": "Anti CSRF Tokens Scanner",
"scanner": {
"id": "zaproxy",
"name": "ZAProxy"
},
"severity": "high",
"solution": "Phase: Architecture and Design Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, use anti-CSRF packages such as the OWASP CSRFGuard. Phase: Implementation Ensure that your application is free of cross-site scripting issues, because most CSRF defenses can be bypassed using attacker-controlled script. Phase: Architecture and Design 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). Note that this can be bypassed using XSS. 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. Note that this can be bypassed using XSS. Use the ESAPI Session Management control. This control includes a component for CSRF. Do not use the GET method for any request that triggers a state change. Phase: Implementation 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."
}
]
}
\ No newline at end of file
{
"@generated": "Fri, 13 Apr 2018 09:22:01",
"@version": "2.7.0",
"scan": {},
"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/"
}
],
"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"
},
"version": "2.5",
"vulnerabilities": [
{
"category": "dast",
"confidence": "medium",
"cve": "20012",
"description": "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. CSRF attacks are effective in a number of situations, including: * The victim has an active session on the target site. * The victim is authenticated via HTTP auth on the target site. * The victim is on the same local network as the target site. 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.",
"identifiers": [
{
"name": "Anti CSRF Tokens Scanner",
"type": "ZAProxy_PluginId",
"url": "https://github.com/zaproxy/zaproxy/blob/w2019-01-14/docs/scanners.md",
"value": "20012"
},
{
"name": "CWE-352",
"type": "CWE",
"url": "https://cwe.mitre.org/data/definitions/352.html",
"value": "352"
},
{
"name": "WASC-9",
"type": "WASC",
"url": "https://projects.webappsec.org/Cross-Site-Request-Forgery",
"value": "9"
}
],
"links": [
{
"url": "http://projects.webappsec.org/Cross-Site-Request-Forgery"
},
{
"url": "http://cwe.mitre.org/data/definitions/352.html"
}
],
"location": {
"hostname": "http://goat:8080",
"method": "GET",
"param": "",
"path": "/WebGoat/login"
},
"message": "Anti CSRF Tokens Scanner",
"scanner": {
"id": "zaproxy",
"name": "ZAProxy"
},
"severity": "high",
"solution": "Phase: Architecture and Design Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, use anti-CSRF packages such as the OWASP CSRFGuard. Phase: Implementation Ensure that your application is free of cross-site scripting issues, because most CSRF defenses can be bypassed using attacker-controlled script. Phase: Architecture and Design 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). Note that this can be bypassed using XSS. 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. Note that this can be bypassed using XSS. Use the ESAPI Session Management control. This control includes a component for CSRF. Do not use the GET method for any request that triggers a state change. Phase: Implementation 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."
}
]
}
\ No newline at end of file
{
"@generated": "Fri, 13 Apr 2018 09:22:01",
"@version": "2.7.0",
"scan": {
"scanned_resources": [
{
"method": "GET",
"type": "url",
"url": "http://api-server/"
},
{
"method": "GET",
"type": "url",
"url": "http://api-server/v1"
},
{
"method": "DELETE",
"type": "url",
"url": "http://api-server/v1/tree/10"
},
{
"method": "GET",
"type": "url",
"url": "http://api-server/v1/tree/10"
},
{
"method": "GET",
"type": "url",
"url": "http://api-server/v1/trees"
},
{
"method": "POST",
"type": "url",
"url": "http://api-server/v1/trees"
}
]
},
"site": [
{
"@host": "goat",
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Parsers::Security::ScannedResources do
describe '#scanned_resources_count' do
let(:parser) { described_class.new }
subject { parser.scanned_resources_count(artifact) }
context 'there are scanned resources' do
let(:artifact) { create(:ee_ci_job_artifact, :dast) }
it { is_expected.to be(6) }
end
context 'the scan key is missing' do
let(:artifact) { create(:ee_ci_job_artifact, :dast_missing_scan_field) }
it { is_expected.to be(0) }
end
context 'the scanned_resources key is missing' do
let(:artifact) { create(:ee_ci_job_artifact, :dast_missing_scanned_resources_field) }
it { is_expected.to be(0) }
end
context 'the json is invalid' do
let(:artifact) { create(:ee_ci_job_artifact, :dast_with_corrupted_data) }
it { is_expected.to be(0) }
end
end
end
......@@ -22,12 +22,22 @@ describe Security::StoreScansService do
expect(scans.sast.count).to be(1)
expect(scans.dast.count).to be(1)
end
it 'stores the scanned resources count on the scan' do
subject
sast_scan = Security::Scan.sast.find_by(build: build)
expect(sast_scan.scanned_resources_count).to be(0)
dast_scan = Security::Scan.dast.find_by(build: build)
expect(dast_scan.scanned_resources_count).to be(6)
end
end
context 'scan already exists' do
before do
create(:ee_ci_job_artifact, :dast, job: build)
create(:security_scan, build: build, scan_type: 'dast')
create(:security_scan, build: build, scan_type: 'dast', scanned_resources_count: 6)
end
it 'does not save' do
......@@ -36,4 +46,16 @@ describe Security::StoreScansService do
expect(Security::Scan.where(build: build).count).to be(1)
end
end
context 'artifact file does not exist' do
before do
create(:ee_ci_job_artifact, :dast_with_missing_file, job: build)
end
it 'stores 0 scanned resources on the scan' do
subject
scans = Security::Scan.where(build: build)
expect(scans.dast.first.scanned_resources_count).to be(0)
end
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