Add vulnerability flag information in Vulnerability Findings API
What does this MR do?
This MR is related to this issue. We use Vulnerability Findings API to expose information about vulnerabilities.
With new capabilities of integrating VET to different analyzers, we need to expose false_positive information to Vulnerability Findings API. For now, we are just exposing false_positive as a boolean value that will be used by the frontend to render flags information in the UI.
Screenshots or Screencasts (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
- [-] I have included changelog trailers, or none are needed. (Does this MR need a changelog?)
- This change is behind feature_flag. That's why no changelog trailer has been included.
-
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
SQL query and plan
ee/app/finders/security/findings_finder.rb
and ee/app/finders/security/pipeline_vulnerabilities_finder.rb
produce similar queries. That's why SQL and query plan for only one finder has been given here.
project.vulnerability_findings
.by_uuid(security_findings.map(&:uuid))
.eager_load_vulnerability_flags
.each_with_object({}) { |elem, memo| memo[elem.uuid] = elem.vulnerability_flags }
SQL
[30] pry(main)> project.vulnerability_findings
.by_uuid(security_findings.map(&:uuid)), memo| memo[elem.uuid] = elem.vulnerability_flags }
.eager_load_vulnerability_flags
Vulnerabilities::Finding Load (0.7ms) SELECT "vulnerability_occurrences".* FROM "vulnerability_occurrences" WHERE "vulnerability_occurrences"."project_id" = 20 AND "vulnerability_occurrences"."uuid" IN ('44d007e0-e101-5040-ba38-bab5cec81c13', '92dffee8-5cb1-5198-9ceb-da027719e020', '28999f95-154b-53b2-b9ab-61a21512d49b', 'fee5ba18-1ccd-5ab7-815d-98875e7598b2', '44d007e0-e101-5040-ba38-bab5cec81c13', '92dffee8-5cb1-5198-9ceb-da027719e020', '06d0c4ed-fced-5630-ac8d-61e6a4cdedcb', '44d007e0-e101-5040-ba38-bab5cec81c13', '92dffee8-5cb1-5198-9ceb-da027719e020', '1ab93c90-828e-5bd1-ae11-a85f1831e049', '28999f95-154b-53b2-b9ab-61a21512d49b', '06d0c4ed-fced-5630-ac8d-61e6a4cdedcb', '33c12198-ae58-5811-85a4-f3ed462d1839', '44d007e0-e101-5040-ba38-bab5cec81c13', '758e24e2-68b8-50a8-9d9e-1eb26269b9bf', '92dffee8-5cb1-5198-9ceb-da027719e020', 'feab89e5-a207-5780-86e9-b27a6c2a2a87', 'feab89e5-a207-5780-86e9-b27a6c2a2a87') /*application:console,line:(pry):33:in `each_with_object'*/
Vulnerabilities::Flag Load (0.7ms) SELECT "vulnerability_flags".* FROM "vulnerability_flags" WHERE "vulnerability_flags"."vulnerability_occurrence_id" IN (128, 123, 122, 126, 127, 121, 129, 125, 124)
SQL with plan
SQL
select * from vulnerability_occurrences where project_id = 19392799 and uuid in (‘44d007e0-e101-5040-ba38-bab5cec81c13’, ‘92dffee8-5cb1-5198-9ceb-da027719e020’, ‘28999f95-154b-53b2-b9ab-61a21512d49b’, ‘fee5ba18-1ccd-5ab7-815d-98875e7598b2’, ‘44d007e0-e101-5040-ba38-bab5cec81c13’, ‘92dffee8-5cb1-5198-9ceb-da027719e020’, ‘06d0c4ed-fced-5630-ac8d-61e6a4cdedcb’, ‘44d007e0-e101-5040-ba38-bab5cec81c13’, ‘92dffee8-5cb1-5198-9ceb-da027719e020’, ‘1ab93c90-828e-5bd1-ae11-a85f1831e049’, ‘28999f95-154b-53b2-b9ab-61a21512d49b’, ‘06d0c4ed-fced-5630-ac8d-61e6a4cdedcb’, ‘33c12198-ae58-5811-85a4-f3ed462d1839’, ‘44d007e0-e101-5040-ba38-bab5cec81c13’, ‘758e24e2-68b8-50a8-9d9e-1eb26269b9bf’, ‘92dffee8-5cb1-5198-9ceb-da027719e020’, ‘feab89e5-a207-5780-86e9-b27a6c2a2a87’, ‘feab89e5-a207-5780-86e9-b27a6c2a2a87’);plan: https://explain.depesz.com/s/7KQb#html
SQL
SELECT * FROM vulnerability_flags WHERE vulnerability_occurrence_id IN (128, 123, 122, 126, 127, 121, 129, 125, 124)plan: https://explain.depesz.com/s/BLid
Test
API call
curl --header "PRIVATE-TOKEN: <PRIVATE TOKEN>" "http://localhost:3000/api/v4/projects/20/vulnerability_findings?pipeline_id=92" | jq
Snapshot
Following is a partial snapshot of the full JSON result
Result
Click this to see full response
[
{
"id": null,
"report_type": "secret_detection",
"name": "AWS detected; please remove and revoke it if this is a leak.",
"severity": "critical",
"confidence": "unknown",
"scanner": {
"external_id": "gitleaks",
"name": "Gitleaks",
"vendor": "GitLab"
},
"identifiers": [
{
"external_type": "gitleaks_rule_id",
"external_id": "AWS",
"name": "Gitleaks rule ID AWS",
"url": null
}
],
"project_fingerprint": "ebead88991926f57811ed7b7e47f7f0b2de6c198",
"uuid": "1ab93c90-828e-5bd1-ae11-a85f1831e049",
"create_jira_issue_url": null,
"false_positive": true,
"create_vulnerability_feedback_issue_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_merge_request_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_dismissal_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"project": {
"id": 20,
"name": "Demo Secret Detection",
"full_path": "/root/demo-secret-detection",
"full_name": "Administrator / Demo Secret Detection"
},
"dismissal_feedback": null,
"issue_feedback": null,
"merge_request_feedback": null,
"description": "AWS",
"links": [],
"location": {
"file": "aws-key.py",
"commit": {
"date": "0001-01-01T00:00:00Z",
"sha": "0000000"
},
"start_line": 12,
"end_line": 12
},
"remediations": [
null
],
"solution": null,
"evidence": null,
"request": null,
"response": null,
"evidence_source": null,
"supporting_messages": [],
"assets": [],
"details": {},
"state": "detected",
"scan": {
"type": "secret_detection",
"status": "success",
"start_time": "2021-05-19T18:36:35",
"end_time": "2021-05-19T18:36:35"
},
"blob_path": "/root/demo-secret-detection/-/blob/b2b6273eff5a28cf469f57ab5d6a7a0a2b7f42f6/aws-key.py#L12-12"
},
{
"id": null,
"report_type": "secret_detection",
"name": "AWS detected; please remove and revoke it if this is a leak.",
"severity": "critical",
"confidence": "unknown",
"scanner": {
"external_id": "gitleaks",
"name": "Gitleaks",
"vendor": "GitLab"
},
"identifiers": [
{
"external_type": "gitleaks_rule_id",
"external_id": "AWS",
"name": "Gitleaks rule ID AWS",
"url": null
}
],
"project_fingerprint": "e13e5afb6efa3d0a11ee6a4533a16b3d0db5292d",
"uuid": "28999f95-154b-53b2-b9ab-61a21512d49b",
"create_jira_issue_url": null,
"false_positive": true,
"create_vulnerability_feedback_issue_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_merge_request_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_dismissal_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"project": {
"id": 20,
"name": "Demo Secret Detection",
"full_path": "/root/demo-secret-detection",
"full_name": "Administrator / Demo Secret Detection"
},
"dismissal_feedback": null,
"issue_feedback": null,
"merge_request_feedback": null,
"description": "AWS",
"links": [],
"location": {
"file": "aws-key.py",
"commit": {
"date": "0001-01-01T00:00:00Z",
"sha": "0000000"
},
"start_line": 5,
"end_line": 5
},
"remediations": [
null
],
"solution": null,
"evidence": null,
"request": null,
"response": null,
"evidence_source": null,
"supporting_messages": [],
"assets": [],
"details": {},
"state": "detected",
"scan": {
"type": "secret_detection",
"status": "success",
"start_time": "2021-05-19T18:36:35",
"end_time": "2021-05-19T18:36:35"
},
"blob_path": "/root/demo-secret-detection/-/blob/b2b6273eff5a28cf469f57ab5d6a7a0a2b7f42f6/aws-key.py#L5-5"
},
{
"id": null,
"report_type": "sast",
"name": "Consider possible security implications associated with subprocess module.",
"severity": "low",
"confidence": "high",
"scanner": {
"external_id": "bandit",
"name": "Bandit",
"vendor": "GitLab"
},
"identifiers": [
{
"external_type": "bandit_test_id",
"external_id": "B404",
"name": "Bandit Test ID B404",
"url": null
}
],
"project_fingerprint": "99fc9db1747d96a620cbc7ceb4803ce7526c4d65",
"uuid": "06d0c4ed-fced-5630-ac8d-61e6a4cdedcb",
"create_jira_issue_url": null,
"false_positive": true,
"create_vulnerability_feedback_issue_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_merge_request_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_dismissal_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"project": {
"id": 20,
"name": "Demo Secret Detection",
"full_path": "/root/demo-secret-detection",
"full_name": "Administrator / Demo Secret Detection"
},
"dismissal_feedback": null,
"issue_feedback": null,
"merge_request_feedback": null,
"description": null,
"links": [],
"location": {
"file": "aws-key.py",
"start_line": 10,
"end_line": 10
},
"remediations": [
null
],
"solution": null,
"evidence": null,
"request": null,
"response": null,
"evidence_source": null,
"supporting_messages": [],
"assets": [],
"details": {},
"state": "detected",
"scan": {
"type": "sast",
"status": "success",
"start_time": "2021-05-19T18:36:44",
"end_time": "2021-05-19T18:36:44"
},
"blob_path": "/root/demo-secret-detection/-/blob/b2b6273eff5a28cf469f57ab5d6a7a0a2b7f42f6/aws-key.py#L10-10"
},
{
"id": null,
"report_type": "sast",
"name": "Consider possible security implications associated with pickle module.",
"severity": "low",
"confidence": "high",
"scanner": {
"external_id": "bandit",
"name": "Bandit",
"vendor": "GitLab"
},
"identifiers": [
{
"external_type": "bandit_test_id",
"external_id": "B403",
"name": "Bandit Test ID B403",
"url": null
}
],
"project_fingerprint": "a45e56972d9afa74bde58630c9934a22e25fc74c",
"uuid": "92dffee8-5cb1-5198-9ceb-da027719e020",
"create_jira_issue_url": null,
"false_positive": true,
"create_vulnerability_feedback_issue_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_merge_request_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_dismissal_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"project": {
"id": 20,
"name": "Demo Secret Detection",
"full_path": "/root/demo-secret-detection",
"full_name": "Administrator / Demo Secret Detection"
},
"dismissal_feedback": null,
"issue_feedback": null,
"merge_request_feedback": null,
"description": null,
"links": [],
"location": {
"file": "aws-key.py",
"start_line": 8,
"end_line": 8
},
"remediations": [
null
],
"solution": null,
"evidence": null,
"request": null,
"response": null,
"evidence_source": null,
"supporting_messages": [],
"assets": [],
"details": {},
"state": "detected",
"scan": {
"type": "sast",
"status": "success",
"start_time": "2021-05-19T18:36:44",
"end_time": "2021-05-19T18:36:44"
},
"blob_path": "/root/demo-secret-detection/-/blob/b2b6273eff5a28cf469f57ab5d6a7a0a2b7f42f6/aws-key.py#L8-8"
},
{
"id": null,
"report_type": "sast",
"name": "Possible hardcoded password: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'",
"severity": "low",
"confidence": "medium",
"scanner": {
"external_id": "bandit",
"name": "Bandit",
"vendor": "GitLab"
},
"identifiers": [
{
"external_type": "bandit_test_id",
"external_id": "B105",
"name": "Bandit Test ID B105",
"url": "https://bandit.readthedocs.io/en/latest/plugins/b105_hardcoded_password_string.html"
}
],
"project_fingerprint": "4a58654ce15bbaa98be01f6f34e470257d1d3388",
"uuid": "44d007e0-e101-5040-ba38-bab5cec81c13",
"create_jira_issue_url": null,
"false_positive": true,
"create_vulnerability_feedback_issue_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_merge_request_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"create_vulnerability_feedback_dismissal_path": "/root/demo-secret-detection/-/vulnerability_feedback",
"project": {
"id": 20,
"name": "Demo Secret Detection",
"full_path": "/root/demo-secret-detection",
"full_name": "Administrator / Demo Secret Detection"
},
"dismissal_feedback": null,
"issue_feedback": null,
"merge_request_feedback": null,
"description": null,
"links": [],
"location": {
"file": "aws-key.py",
"start_line": 6,
"end_line": 6
},
"remediations": [
null
],
"solution": null,
"evidence": null,
"request": null,
"response": null,
"evidence_source": null,
"supporting_messages": [],
"assets": [],
"details": {},
"state": "detected",
"scan": {
"type": "sast",
"status": "success",
"start_time": "2021-05-19T18:36:44",
"end_time": "2021-05-19T18:36:44"
},
"blob_path": "/root/demo-secret-detection/-/blob/b2b6273eff5a28cf469f57ab5d6a7a0a2b7f42f6/aws-key.py#L6-6"
}
]