-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLogForging.cs
More file actions
36 lines (32 loc) · 872 Bytes
/
LogForging.cs
File metadata and controls
36 lines (32 loc) · 872 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
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Web;
class ILogger
{
public void Warn(string message) { }
}
public class LogForgingHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
String username = ctx.Request.QueryString["username"];
ILogger logger = new ILogger();
// BAD: Logged as-is
logger.Warn(username + " logged in");
// GOOD: New-lines removed
logger.Warn(username.Replace(Environment.NewLine, "") + " logged in");
// GOOD: Html encoded
logger.Warn(WebUtility.HtmlEncode(username) + " logged in");
// BAD: Logged as-is to TraceSource
new TraceSource("Test").TraceInformation(username + " logged in");
}
public bool IsReusable
{
get
{
return true;
}
}
}