1+ # Dependency Review Action
2+
3+ # PRs introducing NEW known-vulnerable packages will be blocked from merging.
4+ # This will output a GHAS comment in the PR with the details of the vulnerabilities.
5+ # and will also provide a comment on what to do next.
6+
7+ # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
8+ name : " Dependency review"
9+ on :
10+ pull_request :
11+ branches : ["master"]
12+
13+ permissions :
14+ contents : read
15+ pull-requests : write # Required for PR comments
16+
17+ jobs :
18+ dependency-review :
19+ runs-on : ubuntu-latest
20+ outputs :
21+ vulnerable-changes : ${{ steps.review.outputs.vulnerable-changes }}
22+ steps :
23+ - name : " Checkout repository"
24+ uses : actions/checkout@v4
25+ - name : " Dependency Review"
26+ id : review
27+ uses : actions/dependency-review-action@v4
28+ with :
29+ comment-summary-in-pr : always
30+ fail-on-severity : moderate
31+ # allow-ghsas: GHSA-q34m-jh98-gwm2,GHSA-f9vj-2wh5-fj8j EXAMPLE of how to whitelist!
32+
33+ dependency-review-failure-info :
34+ needs : dependency-review
35+ if : failure()
36+ runs-on : ubuntu-latest
37+ steps :
38+ - name : Add PR Comment
39+ uses : actions/github-script@v7
40+ env :
41+ VULN_OUTPUT : ${{ needs.dependency-review.outputs.vulnerable-changes }}
42+ with :
43+ script : |
44+ try {
45+ const vulnData = JSON.parse(process.env.VULN_OUTPUT || '[]');
46+ let details = '';
47+
48+ for (const pkg of vulnData) {
49+ details += `\n📦 **${pkg.name}@${pkg.version}**\n`;
50+ }
51+
52+ const comment = `⚠️ **Security Dependency Review Failed** ⚠️
53+
54+ This pull request introduces dependencies with security vulnerabilities of moderate severity or higher.
55+
56+ ### Vulnerable Dependencies:${details}
57+
58+ ### What to do next?
59+ 1. Review the vulnerability details in the Dependency Review Comment above, specifically the "Vulnerabilities" section
60+ 2. Click on the links in the "Vulnerability" section to see the details of the vulnerability
61+ 3. If multiple versions of the same package are vulnerable, please update to the common latest non-vulnerable version
62+ 4. If you are unsure about the vulnerability, please contact the security engineer
63+ 5. If the vulnerability cannot be avoided (can't upgrade, or need to keep), contact #security on slack to **get it added to the allowlist**
64+ \nSecurity Engineering contact: #security on slack`;
65+
66+ await github.rest.issues.createComment({
67+ issue_number: context.issue.number,
68+ owner: context.repo.owner,
69+ repo: context.repo.repo,
70+ body: comment
71+ });
72+ } catch (error) {
73+ console.error('Error processing vulnerability data:', error);
74+ throw error;
75+ }
0 commit comments