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
ff581862
Commit
ff581862
authored
Jul 23, 2019
by
Tetiana Chupryna
Committed by
Thong Kuah
Jul 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge vulnerabilities data to Dependency List report
parent
e0109d40
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
13 deletions
+74
-13
ee/changelogs/unreleased/12406-vulnerabilities-to-dependency-list.yml
...s/unreleased/12406-vulnerabilities-to-dependency-list.yml
+5
-0
ee/lib/gitlab/ci/parsers/security/dependency_list.rb
ee/lib/gitlab/ci/parsers/security/dependency_list.rb
+4
-2
ee/lib/gitlab/ci/parsers/security/formatters/dependency_list.rb
.../gitlab/ci/parsers/security/formatters/dependency_list.rb
+26
-2
ee/spec/lib/gitlab/ci/parsers/security/dependency_list_spec.rb
...ec/lib/gitlab/ci/parsers/security/dependency_list_spec.rb
+13
-0
ee/spec/lib/gitlab/ci/parsers/security/formatters/dependency_list_spec.rb
...ab/ci/parsers/security/formatters/dependency_list_spec.rb
+26
-9
No files found.
ee/changelogs/unreleased/12406-vulnerabilities-to-dependency-list.yml
0 → 100644
View file @
ff581862
---
title
:
Merge vulnerabilities data into Dependency List report
merge_request
:
14706
author
:
type
:
added
ee/lib/gitlab/ci/parsers/security/dependency_list.rb
View file @
ff581862
...
@@ -11,10 +11,12 @@ module Gitlab
...
@@ -11,10 +11,12 @@ module Gitlab
def
parse!
(
json_data
,
report
)
def
parse!
(
json_data
,
report
)
report_data
=
JSON
.
parse!
(
json_data
)
report_data
=
JSON
.
parse!
(
json_data
)
report_data
.
fetch
(
'dependency_files'
,
[]).
each
do
|
file
|
report_data
.
fetch
(
'dependency_files'
,
[]).
each
do
|
file
|
file
[
'dependencies'
].
each
do
|
dependency
|
file
[
'dependencies'
].
each
do
|
dependency
|
report
.
add_dependency
(
formatter
.
format
(
dependency
,
file
[
'package_manager'
],
file
[
'path'
]))
report
.
add_dependency
(
formatter
.
format
(
dependency
,
file
[
'package_manager'
],
file
[
'path'
],
report_data
[
'vulnerabilities'
]))
end
end
end
end
end
end
...
...
ee/lib/gitlab/ci/parsers/security/formatters/dependency_list.rb
View file @
ff581862
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
@commit_path
=
::
Gitlab
::
Routing
.
url_helpers
.
project_blob_path
(
project
,
sha
)
@commit_path
=
::
Gitlab
::
Routing
.
url_helpers
.
project_blob_path
(
project
,
sha
)
end
end
def
format
(
dependency
,
package_manager
,
file_path
)
def
format
(
dependency
,
package_manager
,
file_path
,
vulnerabilities
=
[]
)
{
{
name:
dependency
[
'package'
][
'name'
],
name:
dependency
[
'package'
][
'name'
],
packager:
packager
(
package_manager
),
packager:
packager
(
package_manager
),
...
@@ -19,7 +19,8 @@ module Gitlab
...
@@ -19,7 +19,8 @@ module Gitlab
blob_path:
blob_path
(
file_path
),
blob_path:
blob_path
(
file_path
),
path:
file_path
path:
file_path
},
},
version:
dependency
[
'version'
]
version:
dependency
[
'version'
],
vulnerabilities:
collect_vulnerabilities
(
vulnerabilities
,
dependency
,
file_path
)
}
}
end
end
...
@@ -31,6 +32,21 @@ module Gitlab
...
@@ -31,6 +32,21 @@ module Gitlab
"
#{
commit_path
}
/
#{
file_path
}
"
"
#{
commit_path
}
/
#{
file_path
}
"
end
end
# Dependency List report is generated by dependency_scanning job.
# This is how the location is generated there
# https://gitlab.com/gitlab-org/security-products/analyzers/common/blob/a0a5074c49f34332aa3948cd9d6dc2c054cdf3a7/issue/issue.go#L169
def
location
(
dependency
,
file_path
)
{
"file"
=>
file_path
,
'dependency'
=>
{
'package'
=>
{
'name'
=>
dependency
[
'package'
][
'name'
]
},
'version'
=>
dependency
[
'version'
]
}
}
end
def
packager
(
package_manager
)
def
packager
(
package_manager
)
case
package_manager
case
package_manager
when
'bundler'
when
'bundler'
...
@@ -49,6 +65,14 @@ module Gitlab
...
@@ -49,6 +65,14 @@ module Gitlab
package_manager
package_manager
end
end
end
end
def
collect_vulnerabilities
(
vulnerabilities
,
dependency
,
file_path
)
dependency_location
=
location
(
dependency
,
file_path
)
vulnerabilities
.
select
do
|
vulnerability
|
vulnerability
[
'location'
]
==
dependency_location
end
end
end
end
end
end
end
end
...
...
ee/spec/lib/gitlab/ci/parsers/security/dependency_list_spec.rb
View file @
ff581862
...
@@ -30,6 +30,19 @@ describe Gitlab::Ci::Parsers::Security::DependencyList do
...
@@ -30,6 +30,19 @@ describe Gitlab::Ci::Parsers::Security::DependencyList do
expect
(
report
.
dependencies
[
0
][
:location
][
:path
]).
to
eq
(
'rails/Gemfile.lock'
)
expect
(
report
.
dependencies
[
0
][
:location
][
:path
]).
to
eq
(
'rails/Gemfile.lock'
)
expect
(
report
.
dependencies
[
12
][
:location
][
:blob_path
]).
to
eq
(
blob_path
)
expect
(
report
.
dependencies
[
12
][
:location
][
:blob_path
]).
to
eq
(
blob_path
)
end
end
it
'merge vulnerabilities data'
do
vuln_nokogiri
=
report
.
dependencies
[
1
][
:vulnerabilities
]
vuln_debug
=
report
.
dependencies
[
4
][
:vulnerabilities
]
vuln_async
=
report
.
dependencies
[
3
][
:vulnerabilities
]
expect
(
vuln_nokogiri
.
size
).
to
eq
(
4
)
expect
(
vuln_nokogiri
[
0
][
'name'
]).
to
eq
(
'Vulnerabilities in libxml2'
)
expect
(
vuln_nokogiri
[
0
][
'severity'
]).
to
eq
(
'Unknown'
)
expect
(
vuln_debug
.
size
).
to
eq
(
1
)
expect
(
vuln_debug
[
0
][
'name'
]).
to
eq
(
'Regular Expression Denial of Service'
)
expect
(
vuln_async
.
size
).
to
eq
(
0
)
end
end
end
context
'with old dependency scanning artifact'
do
context
'with old dependency scanning artifact'
do
...
...
ee/spec/lib/gitlab/ci/parsers/security/formatters/dependency_list_spec.rb
View file @
ff581862
...
@@ -19,17 +19,34 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DependencyList do
...
@@ -19,17 +19,34 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DependencyList do
let
(
:dependency
)
{
parsed_report
[
'dependency_files'
][
0
][
'dependencies'
][
0
]
}
let
(
:dependency
)
{
parsed_report
[
'dependency_files'
][
0
][
'dependencies'
][
0
]
}
let
(
:package_manager
)
{
'bundler'
}
let
(
:package_manager
)
{
'bundler'
}
let
(
:file_path
)
{
'rails/Gemfile.lock'
}
let
(
:file_path
)
{
'rails/Gemfile.lock'
}
let
(
:data
)
{
formatter
.
format
(
dependency
,
package_manager
,
file_path
,
parsed_report
[
'vulnerabilities'
])
}
let
(
:blob_path
)
{
"/
#{
project
.
full_path
}
/blob/
#{
sha
}
/rails/Gemfile.lock"
}
it
'format report into a right format'
do
context
'with secure dependency'
do
data
=
formatter
.
format
(
dependency
,
package_manager
,
file_path
)
let
(
:dependency
)
{
parsed_report
[
'dependency_files'
][
0
][
'dependencies'
][
0
]
}
blob_path
=
"/
#{
project
.
full_path
}
/blob/
#{
sha
}
/rails/Gemfile.lock"
expect
(
data
[
:name
]).
to
eq
(
'mini_portile2'
)
it
'format report into a right format'
do
expect
(
data
[
:packager
]).
to
eq
(
'Ruby (Bundler)'
)
expect
(
data
[
:name
]).
to
eq
(
'mini_portile2'
)
expect
(
data
[
:package_manager
]).
to
eq
(
'bundler'
)
expect
(
data
[
:packager
]).
to
eq
(
'Ruby (Bundler)'
)
expect
(
data
[
:location
][
:blob_path
]).
to
eq
(
blob_path
)
expect
(
data
[
:package_manager
]).
to
eq
(
'bundler'
)
expect
(
data
[
:location
][
:path
]).
to
eq
(
'rails/Gemfile.lock'
)
expect
(
data
[
:location
][
:blob_path
]).
to
eq
(
blob_path
)
expect
(
data
[
:version
]).
to
eq
(
'2.2.0'
)
expect
(
data
[
:location
][
:path
]).
to
eq
(
'rails/Gemfile.lock'
)
expect
(
data
[
:version
]).
to
eq
(
'2.2.0'
)
expect
(
data
[
:vulnerabilities
]).
to
be_empty
end
end
context
'with vulnerable dependency'
do
let
(
:dependency
)
{
parsed_report
[
'dependency_files'
][
0
][
'dependencies'
][
1
]
}
it
'merge vulnerabilities data'
do
vulnerabilities
=
data
[
:vulnerabilities
]
expect
(
vulnerabilities
.
size
).
to
eq
(
4
)
expect
(
vulnerabilities
[
0
][
'name'
]).
to
eq
(
'Vulnerabilities in libxml2'
)
expect
(
vulnerabilities
[
3
][
'name'
]).
to
eq
(
'Bypass of a protection mechanism in libxslt'
)
expect
(
vulnerabilities
[
0
][
'severity'
]).
to
eq
(
'Unknown'
)
end
end
end
end
end
...
...
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