File tree Expand file tree Collapse file tree
csharp/ql/test/query-tests/Security Features/CWE-089 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ namespace TestSqlite
44{
55 using System . Data ;
66 using System . Data . SQLite ;
7+ using System . IO ;
8+ using System . Text ;
79 using System . Web . UI . WebControls ;
810
911 class SqlInjection
@@ -42,6 +44,26 @@ public void InjectUntrustedData()
4244 adapter = new SQLiteDataAdapter ( cmd ) ;
4345 result = new DataSet ( ) ;
4446 adapter . Fill ( result ) ;
47+
48+ // BAD: untrusted data as filename is not sanitized.
49+ using ( FileStream fs = new FileStream ( untrustedData . Text , FileMode . Open ) )
50+ {
51+ using ( StreamReader sr = new StreamReader ( fs , Encoding . UTF8 ) )
52+ {
53+ var sql = String . Empty ;
54+ while ( ( sql = sr . ReadLine ( ) ) != null )
55+ {
56+ sql = sql . Trim ( ) ;
57+ if ( sql . StartsWith ( "--" ) )
58+ continue ;
59+ using ( var connection = new SQLiteConnection ( "" ) )
60+ {
61+ cmd = new SQLiteCommand ( sql , connection ) ;
62+ cmd . ExecuteScalar ( ) ;
63+ }
64+ }
65+ }
66+ }
4567 }
4668 }
4769}
You can’t perform that action at this time.
0 commit comments