Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e8bd79d5
Commit
e8bd79d5
authored
Nov 30, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attach remediations to Repor::Security::Finding entities
parent
3d8eb2da
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
1 deletion
+20
-1
ee/lib/gitlab/ci/parsers/security/common.rb
ee/lib/gitlab/ci/parsers/security/common.rb
+8
-0
ee/lib/gitlab/ci/reports/security/finding.rb
ee/lib/gitlab/ci/reports/security/finding.rb
+3
-1
ee/spec/lib/gitlab/ci/parsers/security/common_spec.rb
ee/spec/lib/gitlab/ci/parsers/security/common_spec.rb
+6
-0
ee/spec/lib/gitlab/ci/reports/security/finding_spec.rb
ee/spec/lib/gitlab/ci/reports/security/finding_spec.rb
+3
-0
No files found.
ee/lib/gitlab/ci/parsers/security/common.rb
View file @
e8bd79d5
...
...
@@ -57,6 +57,7 @@ module Gitlab
identifiers
=
create_identifiers
(
report
,
data
[
'identifiers'
])
links
=
create_links
(
report
,
data
[
'links'
])
location
=
create_location
(
data
[
'location'
]
||
{})
remediations
=
create_remediations
(
data
[
'remediations'
])
report
.
add_finding
(
::
Gitlab
::
Ci
::
Reports
::
Security
::
Finding
.
new
(
...
...
@@ -71,6 +72,7 @@ module Gitlab
scan:
report
&
.
scan
,
identifiers:
identifiers
,
links:
links
,
remediations:
remediations
,
raw_metadata:
data
.
to_json
,
metadata_version:
version
))
end
...
...
@@ -126,6 +128,12 @@ module Gitlab
url:
link
[
'url'
])
end
def
create_remediations
(
remediations_data
)
remediations_data
.
to_a
.
compact
.
map
do
|
remediation_data
|
::
Gitlab
::
Ci
::
Reports
::
Security
::
Remediation
.
new
(
remediation_data
[
'summary'
],
remediation_data
[
'diff'
])
end
end
def
parse_severity_level
(
input
)
return
input
if
::
Vulnerabilities
::
Finding
::
SEVERITY_LEVELS
.
key?
(
input
)
...
...
ee/lib/gitlab/ci/reports/security/finding.rb
View file @
e8bd79d5
...
...
@@ -22,10 +22,11 @@ module Gitlab
attr_reader
:scan
attr_reader
:severity
attr_reader
:uuid
attr_reader
:remediations
delegate
:file_path
,
:start_line
,
:end_line
,
to: :location
def
initialize
(
compare_key
:,
identifiers
:,
links:
[],
location
:,
metadata_version
:,
name
:,
raw_metadata
:,
report_type
:,
scanner
:,
scan
:,
uuid
:,
confidence:
nil
,
severity:
nil
)
# rubocop:disable Metrics/ParameterLists
def
initialize
(
compare_key
:,
identifiers
:,
links:
[],
remediations:
[],
location
:,
metadata_version
:,
name
:,
raw_metadata
:,
report_type
:,
scanner
:,
scan
:,
uuid
:,
confidence:
nil
,
severity:
nil
)
# rubocop:disable Metrics/ParameterLists
@compare_key
=
compare_key
@confidence
=
confidence
@identifiers
=
identifiers
...
...
@@ -39,6 +40,7 @@ module Gitlab
@scan
=
scan
@severity
=
severity
@uuid
=
uuid
@remediations
=
remediations
@project_fingerprint
=
generate_project_fingerprint
end
...
...
ee/spec/lib/gitlab/ci/parsers/security/common_spec.rb
View file @
e8bd79d5
...
...
@@ -66,16 +66,22 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
end
context
'parsing remediations'
do
let
(
:expected_remediation
)
{
create
(
:ci_reports_security_remediation
,
diff:
''
)
}
it
'finds remediation with same cve'
do
vulnerability
=
report
.
findings
.
find
{
|
x
|
x
.
compare_key
==
"CVE-1020"
}
remediation
=
{
'fixes'
=>
[{
'cve'
=>
'CVE-1020'
}],
'summary'
=>
''
,
'diff'
=>
''
}
expect
(
Gitlab
::
Json
.
parse
(
vulnerability
.
raw_metadata
).
dig
(
'remediations'
).
first
).
to
include
remediation
expect
(
vulnerability
.
remediations
.
first
.
checksum
).
to
eq
(
expected_remediation
.
checksum
)
end
it
'finds remediation with same id'
do
vulnerability
=
report
.
findings
.
find
{
|
x
|
x
.
compare_key
==
"CVE-1030"
}
remediation
=
{
'fixes'
=>
[{
'cve'
=>
'CVE'
,
'id'
=>
'bb2fbeb1b71ea360ce3f86f001d4e84823c3ffe1a1f7d41ba7466b14cfa953d3'
}],
'summary'
=>
''
,
'diff'
=>
''
}
expect
(
Gitlab
::
Json
.
parse
(
vulnerability
.
raw_metadata
).
dig
(
'remediations'
).
first
).
to
include
remediation
expect
(
vulnerability
.
remediations
.
first
.
checksum
).
to
eq
(
expected_remediation
.
checksum
)
end
it
'does not find remediation with different id'
do
...
...
ee/spec/lib/gitlab/ci/reports/security/finding_spec.rb
View file @
e8bd79d5
...
...
@@ -13,6 +13,7 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do
let
(
:link
)
{
create
(
:ci_reports_security_link
)
}
let
(
:scanner
)
{
create
(
:ci_reports_security_scanner
)
}
let
(
:location
)
{
create
(
:ci_reports_security_locations_sast
)
}
let
(
:remediation
)
{
create
(
:ci_reports_security_remediation
)
}
let
(
:params
)
do
{
...
...
@@ -20,6 +21,7 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do
confidence: :medium
,
identifiers:
[
primary_identifier
,
other_identifier
],
links:
[
link
],
remediations:
[
remediation
],
location:
location
,
metadata_version:
'sast:1.0'
,
name:
'Cipher with no integrity'
,
...
...
@@ -42,6 +44,7 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do
project_fingerprint:
'9a73f32d58d87d94e3dc61c4c1a94803f6014258'
,
identifiers:
[
primary_identifier
,
other_identifier
],
links:
[
link
],
remediations:
[
remediation
],
location:
location
,
metadata_version:
'sast:1.0'
,
name:
'Cipher with no integrity'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment