首页 > 代码库 > 防止连接字符串注入式攻击

防止连接字符串注入式攻击

 

使用sqlConnectionStringBuilder来处理 Initial Catalog 设置插入的额外值

1 System.Data.SqlClient.SqlConnectionStringBuilder builder 
  = new System.Data.SqlClient.SqlConnectionStringBuilder();2 builder["Data Source"] = "(local)";3 builder["integrated Security"] = true;4 builder["Initial Catalog"] = "AdventureWorks;NewValue=http://www.mamicode.com/Bad";5 string connectionString = builder.ConnectionString;

其中,;NewValue=http://www.mamicode.com/Bad就是注入的其他字符串,如果不加处理直接运行,会出错。这种情况下,就可以使用builder构造链接字符串。

 

防止连接字符串注入式攻击