-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLogForgingAsp.cs
More file actions
41 lines (37 loc) · 1019 Bytes
/
LogForgingAsp.cs
File metadata and controls
41 lines (37 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Headers;
using Microsoft.AspNetCore.Mvc;
public class AspController : ControllerBase
{
public void Action1(string username)
{
var logger = new ILogger();
// BAD: Logged as-is
logger.Warn(username + " logged in");
}
public void Action1(DateTime date)
{
var logger = new ILogger();
// GOOD: DateTime is a sanitizer.
logger.Warn($"Warning about the date: {date:yyyy-MM-dd}");
}
public void Action2(DateTime? date)
{
var logger = new ILogger();
if (date is not null)
{
// GOOD: DateTime? is a sanitizer.
logger.Warn($"Warning about the date: {date:yyyy-MM-dd}");
}
}
public void Action2(bool? b)
{
var logger = new ILogger();
if (b is not null)
{
// GOOD: Boolean? is a sanitizer.
logger.Warn($"Warning about the bool: {b}");
}
}
}