High severityC#Hardcoded SecretsMEDIUM confidence
Hardcoded Secret Assignment
A secret (password, API key, token, or private key) is assigned to a string literal in code (CWE-798).
Standards mapping
- OWASP ASVS
- V6.4.1 (L2)V2.10.4 (L2)
Vulnerable vs. safe
Flagged by this check
var apiSecret = "s3cr3t_value_9f8a7b6c5d4e";Passes - the safe pattern
var apiSecret = Environment.GetEnvironmentVariable("API_SECRET");Why it matters & how to fix it
A secret (password, API key, token, or private key) is assigned to a string literal in code (CWE-798). Committed secrets leak through source control and build artifacts and cannot be rotated cleanly. Read the value at runtime from configuration/environment or a secrets manager (Azure Key Vault, AWS Secrets Manager) and rotate anything already committed.
References
Rule ID integsec.csharp.secrets.hardcoded-secret-assignment - engine: Opengrep - license: MIT - Copyright (c) IntegSec Inc.
TurboPentest runs this check automatically
Connect a GitHub repo and this check runs on every white-box pentest - AI-validated and reported with proof, from $99 per target.
Start a pentestRelated checks
- JavaScript / TypeScript - Hardcoded SecretsBasic Auth Credentials In URL
- JavaScript / TypeScript - Hardcoded SecretsDB Connection String With Credentials
- JavaScript / TypeScript - Hardcoded SecretsHardcoded Credential String
- JavaScript / TypeScript - Hardcoded SecretsHardcoded Crypto Key Or IV
- Python - Hardcoded SecretsBasic Auth Credentials In URL
- Python - Hardcoded SecretsDB Connection String Credentials