-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathResourceInjection.cs
More file actions
29 lines (27 loc) · 1.04 KB
/
ResourceInjection.cs
File metadata and controls
29 lines (27 loc) · 1.04 KB
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
using System.Data.SqlClient;
using System.Web;
public class ResourceInjectionHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
string userName = ctx.Request.QueryString["userName"];
string connectionString = "server=(local);user id=" + userName + ";password= pass;";
// BAD: Direct use of user input in a connection string for the constructor
SqlConnection sqlConnection = new SqlConnection(connectionString);
// BAD: Direct use of user input assigned to a connection string property
sqlConnection.ConnectionString = connectionString;
// GOOD: Use SqlConnectionStringBuilder
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder["Data Source"] = "(local)";
builder["integrated Security"] = true;
builder["user id"] = userName;
SqlConnection sqlConnectionGood = new SqlConnection(builder.ConnectionString);
}
public bool IsReusable
{
get
{
return true;
}
}
}