With Dependency Review enabled and configured, we want to block vulnerable packages from entering the codebase. We can define a repository ruleset to enforce this as well!
This lab covers parts of the following exam domains:
- Domain 3: Configure and use dependency management
- Domain 6: Describe GitHub Advanced Security best practices
First, let's add the dependency review action workflow.
- In the repository, click on the Actions tab.
- Click on the New workflow button in the upper left.
- Search for "dependency" and click enter on your keyboard.
- Under the Dependency Review workflow, click Configure.
- Review the action and its defaults on line 32-39. This action can also block specific open source license types.
- In the upper right, click on Commit changes...
- Since we have a ruleset, we have to create a branch and merge this to main via pull request. Create a branch and commit (Propose changes) the changes.
- On the next screen, use the Copilot icon in the formatting bar to generate a pull request description.
- Click Create pull request.
- Wait for the code scanning job to finish. It will take a few minutes to run.
- You will notice that the Dependency Review workflow ran against this PR and didn't report any issues.
- Merge the PR once the code scanning completes.
- Navigate to Settings of the repo.
- Navigate to Rules --> Rulesets.
- Click on the name of the ruleset you created in lab 3 to modify it.
- Under the Require status checks to pass, click on the Show additional settings button.
- Click on Add checks.
- Search for
dependency-review
and add it (it should show up under suggestions).
- Save the changes to the ruleset.
Now, let's attempt to add a vulnerable dependency to the codebase and test out the dependency review feature.
- Navigate back to the Code tab in the repo.
- Click the package.json file in the root of the repository to open it.
- Click the pencil ✏️ icon at the top right of the file to go into edit mode.
- Go to the end of line 181 and hit Enter to create a blank line for line 182.
- Add the following code to line 182, making sure to include the comma at the end of the line:
"tar": "2.2.2",
- Click the Commit changes button.
- Change the branch name to lab4/dependency-vulnerability and click Propose changes to start a pull request.
- Use the Copilot button in the formatting bar to generate a PR summary for you.
- Click the Create pull request button.
- Wait for the dependency review job to finish.
- It should make a comment to the pull request with a note that it found a vulnerable package dependency. In fact, adding this one package would introduce 3 new vulnerabilities to our codebase.
- Also, the status check will be marked as failed, preventing the pull request from being merged.
Celebrate 🎉! We just prevented a security vulnerability from entering our codebase! Without dependency review, if a pull request from this branch was opened to main, nothing would prevent the vulnerability from being introduced.
In the next lab, we are going to go hands-on with secret scanning, and see how we can use push protection to stop secrets from being pushed to GitHub.
➡️ Head back to the labs page to continue on to the next lab.