11name : Windows Server 2025
22
33on :
4+ workflow_dispatch :
5+ inputs :
6+ run_binskim :
7+ description : ' Run BinSkim security hardening check'
8+ type : boolean
9+ default : true
410 pull_request :
511 types : [synchronize, opened]
612 push :
@@ -173,6 +179,43 @@ jobs:
173179 cd ${env:GITHUB_WORKSPACE}\test\OpenCvSharp.Tests.Windows
174180 dotnet test -c Release -f net48 --runtime win-x64
175181
182+ - name : Verify security hardening with BinSkim
183+ if : inputs.run_binskim == true
184+ shell : powershell
185+ run : |
186+ # Official install: download .nupkg from NuGet, unzip, run exe from tools/
187+ $dest = "$env:TEMP\binskim"
188+ Invoke-WebRequest "https://www.nuget.org/api/v2/package/Microsoft.CodeAnalysis.BinSkim" -OutFile "$dest.zip"
189+ Expand-Archive "$dest.zip" $dest -Force
190+ $binskimExe = Get-ChildItem "$dest\tools\net*\win-x64\binskim.exe" | Select-Object -Last 1 -ExpandProperty FullName
191+ if (-not $binskimExe) { throw "binskim.exe not found" }
192+
193+ # Scan OpenCvSharpExtern.dll only.
194+ # opencv_videoio_ffmpeg*.dll is a pre-built binary from opencv_3rdparty
195+ # and cannot be recompiled with different flags (see opencv/3rdparty/ffmpeg/ffmpeg.cmake).
196+ $dll = "$env:GITHUB_WORKSPACE\src\build\OpenCvSharpExtern\Release\OpenCvSharpExtern.dll"
197+ if (-not (Test-Path $dll)) { throw "OpenCvSharpExtern.dll not found: $dll" }
198+
199+ $sarifFile = "$env:TEMP\binskim.sarif"
200+ & $binskimExe analyze $dll --output $sarifFile
201+ # Ignore BinSkim's own exit code (it returns 1 on PDB load failures etc.);
202+ # rely solely on SARIF result filtering below.
203+ $LASTEXITCODE = 0
204+
205+ # Ignore findings we cannot address:
206+ # ERR997 - PDB unavailable (Release builds have no PDB by default)
207+ # BA2007 - compiler warning level violations in vcpkg static libs (tesseract, tiff, etc.)
208+ if (-not (Test-Path $sarifFile)) { Write-Warning "No SARIF output produced."; exit 0 }
209+ $failures = (Get-Content $sarifFile | ConvertFrom-Json).runs[0].results | Where-Object {
210+ $ruleId = ($_.ruleId -split "/")[0]
211+ $_.level -eq "error" -and $ruleId -notmatch "^ERR997" -and $ruleId -ne "BA2007"
212+ }
213+ if ($failures) {
214+ $failures | ForEach-Object { Write-Host "FAIL $($_.ruleId): $(($_.message.text -split "`n")[0])" }
215+ exit 1
216+ }
217+ Write-Host "Security hardening verified: no actionable failures."
218+
176219 - name : Pack NuGet packages
177220 shell : powershell
178221 run : |
@@ -208,4 +251,4 @@ jobs:
208251 uses : actions/upload-artifact@v6
209252 with :
210253 name : packages_windows
211- path : ${{ github.workspace }}\artifacts
254+ path : ${{ github.workspace }}\artifacts
0 commit comments