Ensure no sensitive information is being logged
This product is not supported for your selected
Datadog site. (
).
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、
お気軽にご連絡ください。
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();
}
}
シームレスな統合。 Datadog Code Security をお試しください