Ensure no sensitive information is being logged This product is not supported for your selected
Datadog site . (
).
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel,
n'hésitez pas à nous contacter .
TRY THIS RULE ID: csharp-security/ensure-secure-logging
Language: C#
Severity: Error
Category: Security
CWE : 778
Description No description found
Non-Compliant Code Examples using System.Web ;
using System.Web.Mvc ;
using NLog ;
public class UserController : Controller
{
private static readonly Logger _logger = LogManager . GetCurrentClassLogger ();
[HttpPost]
public ActionResult Register ( string username )
{
if (! string . IsNullOrEmpty ( username ))
{
_logger . Warn ( "Registration attempt for user: " + username ); // Noncompliant
}
return View ();
}
}
void main () {}
Compliant Code Examples public class UserController : Controller
{
private static readonly Logger _logger = LogManager . GetCurrentClassLogger ();
[HttpPost]
public ActionResult Register ( string username )
{
if (! string . IsNullOrEmpty ( username ))
{
string sanitized = username . Replace ( '\n' , ' ' ). Replace ( '\r' , ' ' ). Replace ( '\t' , ' ' );
_logger . Warn ( "Registration attempt for user: " + sanitized );
}
return View ();
}
}