SharpGuard 1.0.2
dotnet tool install --global SharpGuard --version 1.0.2
dotnet new tool-manifest
dotnet tool install --local SharpGuard --version 1.0.2
#tool dotnet:?package=SharpGuard&version=1.0.2
nuke :add-package SharpGuard --version 1.0.2
SharpGuard
.NET SAST/SCA vulnerability scanner powered by Roslyn.
SharpGuard analyzes C# code for security vulnerabilities (SAST, Static Application Security Testing) and scans NuGet dependencies for known CVEs (SCA, Software Composition Analysis). Findings are mapped to CWE and cover the OWASP Top 10. It ships in two flavors that share the same rule engine.
Features
- 10 SAST rules covering OWASP Top 10 (SQL injection, command injection, path traversal, insecure deserialization, hardcoded secrets, XXE, weak cryptography and more), each mapped to a CWE
- SCA via OSV.dev — NuGet dependency scanning for known vulnerabilities
- Two deployment modes:
- Standalone CLI (
dotnet tool) — full analysis with Console, JSON and SARIF output - Roslyn Analyzer — warnings/errors at build time, in the IDE and in
dotnet build
- Standalone CLI (
- SARIF 2.1.0 output for GitHub Code Scanning and Azure DevOps
- Shared rules — detection logic lives in
SharpGuard.Coreand is consumed by both the CLI and the Analyzer
Quick Start
CLI tool
# Install as a global dotnet tool
dotnet tool install --global SharpGuard
# Analyze a solution
SharpGuard analyze --path ./MySolution.sln --format sarif --output results.sarif
# Severity threshold and non-zero exit code for CI
SharpGuard analyze --path ./src --severity-threshold high --fail-on-findings
Roslyn Analyzer
Add to your .csproj:
<PackageReference Include="SharpGuard.Analyzers" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Warnings show up automatically in dotnet build, Visual Studio and Rider.
CLI options
| Option | Default | Description |
|---|---|---|
--path, -p |
(required) | Path to a .sln, .csproj or directory |
--format, -f |
console |
Output format: console, json, sarif |
--output, -o |
stdout | Output file |
--severity-threshold, -s |
(all) | Minimum severity: critical, high, medium, low, info |
--offline |
false |
Skip SCA network calls (cache only) |
--fail-on-findings |
false |
Exit with code 1 when findings are reported |
SAST rules
| ID | Name | CWE | Severity |
|---|---|---|---|
| SG0001 | SQL Injection | CWE-89 | High |
| SG0002 | Command Injection | CWE-78 | High |
| SG0003 | Path Traversal | CWE-22 | Medium |
| SG0004 | Insecure Deserialization | CWE-502 | Critical |
| SG0005 | Hardcoded Secrets | CWE-798 | Critical |
| SG0006 | Weak Cryptography | CWE-327 | High |
| SG0007 | Insecure Random | CWE-338 | Medium |
| SG0008 | XXE | CWE-611 | High |
| SG0009 | TLS Validation Disabled | CWE-295 | High |
| SG0010 | Sensitive Data Logging | CWE-532 | Medium |
Severity configuration (.editorconfig)
Rule severity is configurable through .editorconfig:
[*.cs]
# Treat SQL injection as an error
dotnet_diagnostic.SG0001.severity = error
# Disable the rule for tests
dotnet_diagnostic.SG0010.severity = none
CI integration
GitHub Code Scanning (SARIF)
- name: Run SharpGuard
run: |
dotnet tool install --global SharpGuard
SharpGuard analyze --path ./src --format sarif --output sharpguard.sarif --fail-on-findings
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sharpguard.sarif
Azure DevOps
- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: 'install --global SharpGuard'
- script: SharpGuard analyze --path $(Build.SourcesDirectory) --format sarif --output $(Build.ArtifactStagingDirectory)/sharpguard.sarif
Build from source
# Prerequisites: .NET 8 SDK
git clone https://github.com/Lupala-coder/SharpGuard.git
cd SharpGuard
dotnet build SharpGuard.sln
dotnet test SharpGuard.sln
# Pack the CLI tool
dotnet pack src/SharpGuard.Cli/SharpGuard.Cli.csproj -c Release
# Pack the Analyzer
dotnet pack src/SharpGuard.Analyzers/SharpGuard.Analyzers.csproj -c Release
Architecture
src/
SharpGuard.Core — Abstractions (ISecurityRule) and the 10 SAST rules. No I/O.
SharpGuard.Analyzers — DiagnosticAnalyzer + CodeFixProvider. NuGet packaging.
SharpGuard.Sca — OSV.dev client + cache. CLI only.
SharpGuard.Reporting — Console/JSON/SARIF reporters (Strategy pattern).
SharpGuard.Cli — CLI front-end built on System.CommandLine.
SharpGuard.Core (netstandard2.0) holds ISecurityRule, SecurityRuleBase and every rule. It does no network or filesystem I/O, only Roslyn analysis. Both the CLI and the Analyzer reference it and call RuleFactory.CreateAll().
SCA stays out of the Analyzer: it needs HTTP calls to api.osv.dev, .csproj parsing and a filesystem cache, while a Roslyn analyzer must be fast, deterministic and concurrent-safe.
Avoiding false positives
- No text matching: every rule resolves types and methods through
SemanticModel.GetSymbolInfo() - Context-aware: a string alone is not enough; it must reach a sensitive sink (e.g.
SqlCommand,Process.Start) - Best effort: projects that do not compile are analyzed as far as possible, skipping problematic nodes
Related tools
- OSV.dev — vulnerability database used for SCA
- SARIF — static analysis results format
- GitHub Code Scanning — consumes the SARIF output
License
MIT — see LICENSE.
Author
Paolino Salamone — https://lupala.com
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
Added OWASP/CWE-oriented package metadata, English README and package icon. No functional changes.