Secret detection links to wrong commit in vulnerability page

Summary

Secret Detection can detect tokens in the git history. When such token is detected, the vulnerability will have a description like:

Historic Password in URL secret has been found in commit abcdef123456.

The location link in the same page is linking to the file but with the latest commit, where the secret might not be present anymore.

Steps to reproduce

  • Create a project
  • Add a secret in a file, commit
  • Remove the secret, commit
  • Run secrets detection with full history

Example Project

https://gitlab.com/gitlab-org/gitaly

What is the current bug behavior?

https://gitlab.com/gitlab-org/gitaly/-/security/vulnerabilities/4822202 is linking to the latest version of the file.

What is the expected correct behavior?

Link to the file using the commit where the secret was detected. (also note that using the right commit with this location brings to an empty line:

it seems to be off by 1)

Relevant logs and/or screenshots

N/A.

Output of checks

This bug happens on GitLab.com

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

Use the metadata of the vulnerability to generate the correct link.

/cc @tmccaslin @twoodham for prioritization

Edited by Philippe Lafoucrière