How to fix: NuGet API key in source
NuGet API keys (oy2_*) allow pushing new package versions to nuget.org under the user's identity - direct supply-chain attack.
Why it matters
An exposed NuGet API key lets an attacker push malicious versions of your .NET packages to nuget.org, injecting backdoors into every project that adds or updates those packages, a supply-chain attack affecting .NET developers worldwide.
NuGet API keys (oy2_*) allow pushing new package versions to nuget.org under the user's identity - direct supply-chain attack.
How to fix it
- 1Revoke the key at nuget.org → Account → API Keys
- 2Audit recent package pushes for unauthorized versions
- 3Use scoped API keys tied to specific packages with push-only permissions
Code examples
GitHub Actions: use Trusted Publishing (OIDC, no key needed)
jobs:
publish:
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- run: dotnet pack -c Release
- uses: actions/setup-dotnet@v4
- run: dotnet nuget push '**/*.nupkg' --source https://api.nuget.org/v3/index.json
env:
# Only use API key if Trusted Publishing is not available
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}References
Detected automatically by VulnRadar. The check id is secret-nuget-api-key, stable across every scan so you can filter or diff on it.
More secrets checks
Questions
- How severe is NuGet API key in source?
- VulnRadar rates this critical severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id secret-nuget-api-key, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does NuGet API key in source map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.