File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
csharp/ql/test/query-tests/Security Features/CWE-089-2 Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace System . Web . UI . WebControls
4+ {
5+ public class TextBox { public string Text { get ; set ; } }
6+ }
7+
8+ namespace Test
9+ {
10+ using Microsoft . Data ;
11+ using Microsoft . Data . SqlClient ;
12+ using System . Web . UI . WebControls ;
13+
14+ class SqlInjection
15+ {
16+ TextBox categoryTextBox ;
17+ string connectionString ;
18+
19+ public void MakeSqlCommand ( )
20+ {
21+ // BAD: Text from a local textbox
22+ using ( var connection = new SqlConnection ( connectionString ) )
23+ {
24+ var queryString = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
25+ + box1 . Text + "' ORDER BY PRICE" ; // $ Source[cs/sql-injection]
26+ var cmd = new SqlCommand ( queryString ) ; // $ Alert[cs/sql-injection]
27+ var adapter = new SqlDataAdapter ( cmd ) ; // $ Alert[cs/sql-injection]
28+ }
29+
30+ // BAD: Input from the command line.
31+ using ( var connection = new SqlConnection ( connectionString ) )
32+ {
33+ var queryString = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
34+ + Console . ReadLine ( ) + "' ORDER BY PRICE" ; // $ Source[cs/sql-injection]
35+ var cmd = new SqlCommand ( queryString ) ; // $ Alert[cs/sql-injection]
36+ var adapter = new SqlDataAdapter ( cmd ) ; // $ Alert[cs/sql-injection]
37+ }
38+ }
39+
40+ System . Windows . Forms . TextBox box1 ;
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ extensions :
2+
3+ - addsTo :
4+ pack : codeql/threat-models
5+ extensible : threatModelConfiguration
6+ data :
7+ - ["local", true, 0]
Original file line number Diff line number Diff line change 1+ query: Security Features/CWE-089/SqlInjection.ql
2+ postprocess:
3+ - utils/test/PrettyPrintModels.ql
4+ - utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change 1+ semmle-extractor-options: /nostdlib /noconfig
2+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/Microsoft.Data.SqlClient/6.0.2/Microsoft.Data.SqlClient.csproj
3+ semmle-extractor-options: ${testdir}/../../../resources/stubs/System.Windows.cs
4+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj
You can’t perform that action at this time.
0 commit comments