-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (77 loc) · 2.89 KB
/
Copy pathdependency-audit.yml
File metadata and controls
92 lines (77 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Dependency Audit
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: "45 2 * * 1"
permissions:
contents: read
jobs:
audit:
name: Audit NuGet packages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Restore solution
run: dotnet restore ShopInventory.sln
- name: Check vulnerable packages
shell: pwsh
run: |
function Get-Items {
param($InputObject)
if ($null -eq $InputObject) {
return @()
}
return @($InputObject | Where-Object { $null -ne $_ })
}
$reportPath = Join-Path $env:RUNNER_TEMP "nuget-vulnerabilities.json"
dotnet list ShopInventory.sln package --vulnerable --include-transitive --format json --output-version 1 | Set-Content -LiteralPath $reportPath
$report = Get-Content -LiteralPath $reportPath -Raw | ConvertFrom-Json
$vulnerabilities = @()
foreach ($project in Get-Items $report.projects) {
foreach ($framework in Get-Items $project.frameworks) {
foreach ($package in Get-Items $framework.topLevelPackages) {
foreach ($vulnerability in Get-Items $package.vulnerabilities) {
$vulnerabilities += [PSCustomObject]@{
Project = $project.path
Framework = $framework.framework
Package = $package.id
Version = $package.resolvedVersion
Severity = $vulnerability.severity
Advisory = $vulnerability.advisoryurl
Type = "TopLevel"
}
}
}
foreach ($package in Get-Items $framework.transitivePackages) {
foreach ($vulnerability in Get-Items $package.vulnerabilities) {
$vulnerabilities += [PSCustomObject]@{
Project = $project.path
Framework = $framework.framework
Package = $package.id
Version = $package.resolvedVersion
Severity = $vulnerability.severity
Advisory = $vulnerability.advisoryurl
Type = "Transitive"
}
}
}
}
}
if ($vulnerabilities.Count -gt 0) {
Write-Host "Detected vulnerable packages:"
$vulnerabilities | Sort-Object Severity, Package | Format-Table -AutoSize | Out-String | Write-Host
throw "Dependency audit failed because vulnerable NuGet packages were found."
}
Write-Host "No vulnerable NuGet packages were detected."