vulnerability_occurrences contains nil for location column

Summary

While verifying #338669 (closed), we found that there are many rows in vulnerability_occurrences table with nil value in location column. This makes filtering the vulnerabilities by image impossible.

Steps to reproduce

  1. Run container scanning job for a project following the documentation
  2. After the job is complete, in rails console:
Vulnerabilities::Finding.where(report_type: 2, location: nil).count

Example Project

What is the current bug behavior?

There will be records with nil value in location column

What is the expected correct behavior?

location column has to be populated with value from the json report

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

  • In StoreReportService, the location is accessed from the create_params hash as a symbol, but it has stringified keys.
diff --git a/ee/app/services/security/store_report_service.rb b/ee/app/services/security/store_report_service.rb
index a19365c2e8c..0305fd2f39b 100644
--- a/ee/app/services/security/store_report_service.rb
+++ b/ee/app/services/security/store_report_service.rb
@@ -118,7 +118,7 @@ def find_or_create_vulnerability_finding(finding, create_params)
         project.vulnerability_findings
           .create_with(create_params)
           .find_or_initialize_by(find_params).tap do |f|
-            f.location = create_params[:location]
+            f.location = create_params['location']
             f.uuid = finding.uuid
             f.save!
           end
  • We also need to migrate the existing data with nil location