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
42
43
44
45
46
47
48
49
50
51
using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
// Negative fixture for the C# taint engine. Every method either uses a
// literal argument, has its taint killed by a sanitizer, or never lets the
// tainted value reach a sink. No csharp/taint-* rule may fire.
namespace SafeApp
{
public class SafeController
{
// NEAR MISS: literal argument to a command sink.
public void LiteralCommand()
{
Process.Start("notepad.exe");
}
// NEAR MISS: tainted value captured but the sink receives a literal.
public void TaintNeverReachesSink()
{
string unused = Request.QueryString["ignored"];
Response.Write("static content");
}
// NEAR MISS: HttpUtility.HtmlEncode sanitizes the flow before output.
public void SanitizedXss()
{
string raw = Request.QueryString["q"];
string safe = HttpUtility.HtmlEncode(raw);
Response.Write(safe);
}
// NEAR MISS: int.Parse collapses taint to clean before SQL concat.
public void NumericSqlSanitized()
{
string rawId = Request.QueryString["id"];
int safeId = int.Parse(rawId);
string sql = "SELECT * FROM Users WHERE Id = " + safeId;
var cmd = new SqlCommand(sql);
cmd.ExecuteReader();
}
// NEAR MISS: redirect to a fixed, allowlisted URL.
public void FixedRedirect()
{
Response.Redirect("/home");
}
}
}