Bug with matching license policy names
Summary
When users enter in a license to mark it as denied or approved, GitLab is not trimming whitespace from the license name. This results in unexpected behavior as shown in the recording below:
Steps to reproduce
Example Project
What is the current bug behavior?
What is the expected correct behavior?
GitLab should ignore any whitespace before or after the name of the license when evaluating whether the license name matches or not.
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
-
Add input sanitization to the SoftwareLicensePolicies::CreateService so that it strips leading and trailing whitespace.
def create_software_license_policy policy = SoftwareLicense.create_policy_for!( project: project, name: params[:name].strip!, classification: params[:approval_status] ) RefreshLicenseComplianceChecksWorker.perform_async(project.id) policy end