Este producto no es compatible con el sitio Datadog seleccionado. ().
Esta página aún no está disponible en español. Estamos trabajando en su traducción. Si tienes alguna pregunta o comentario sobre nuestro actual proyecto de traducción, no dudes en ponerte en contacto con nosotros.
This rule ensures that no sensitive information, such as passwords, personal identifiers, or confidential data, is written to logs. Logging sensitive data can lead to serious security vulnerabilities, including unauthorized access and data leaks, which can compromise user privacy and violate compliance requirements.
It is important to treat logs as potentially accessible by various parties, including developers, administrators, or attackers who gain access to the system. Therefore, sensitive information should never be recorded in logs in plaintext or any identifiable form.
To comply with this rule, developers should carefully review logging statements and avoid including sensitive parameters directly and sanitize information being logged. Log only non-sensitive metadata or sanitized information. For example, rather than logging password or full usernames, consider logging the occurrence of an event without sensitive details or use masking and sanitization techniques before logging.
By following these practices, you reduce the risk of sensitive data exposure while still maintaining useful logs for debugging and monitoring application behavior.
Non-Compliant Code Examples
usingMicrosoft.AspNetCore.Mvc;usingMicrosoft.Extensions.Logging;publicclassAccountController:Controller{privatereadonlyILogger<AccountController>_logger;publicAccountController(ILogger<AccountController>logger){_logger=logger;} [HttpPost]publicIActionResultLogin(stringusername,stringpassword){_logger.LogInformation("User {username} attempting to log in",username);// authentication logic...returnOk();}}
usingSystem.Web;usingSystem.Web.Mvc;usingNLog;publicclassUserController:Controller{privatestaticreadonlyLogger_logger=LogManager.GetCurrentClassLogger(); [HttpPost]publicActionResultRegister(stringusername){if(!string.IsNullOrEmpty(username)){_logger.Warn("Registration attempt for user: "+username);// Noncompliant}returnView();}}voidmain(){}
Compliant Code Examples
publicclassUserController:Controller{privatestaticreadonlyLogger_logger=LogManager.GetCurrentClassLogger(); [HttpPost]publicActionResultRegister(stringusername){if(!string.IsNullOrEmpty(username)){stringsanitized=username.Replace('\n',' ').Replace('\r',' ').Replace('\t',' ');_logger.Warn("Registration attempt for user: "+sanitized);}returnView();}}
Integraciones sin problemas. Prueba Datadog Code Security
Datadog Code Security
Prueba esta regla y analiza tu código con Datadog Code Security
Cómo usar esta regla
1
2
rulesets:- csharp-security # Rules to enforce C# security.
Crea un static-analysis.datadog.yml con el contenido anterior en la raíz de tu repositorio
Utiliza nuestros complementos del IDE gratuitos o añade análisis de Code Security a tus pipelines de CI.