@@ -21,23 +21,23 @@ class AllowListSanitizerWithJavaUtilSet {
21
21
public static final Set <String > goodAllowList2 = Collections .unmodifiableSet (new HashSet <String >(Arrays .asList ("allowed1" ,"allowed2" )));
22
22
public static final Set <String > goodAllowList3 ;
23
23
public static final Set <String > goodAllowList4 ;
24
+ public static final Set <String > goodAllowList5 ;
24
25
public static final Set <String > badAllowList1 = Set .of ("allowed1" , "allowed2" , getNonConstantString ());
25
26
public static final Set <String > badAllowList2 = Collections .unmodifiableSet (new HashSet <String >(Arrays .asList ("allowed1" , getNonConstantString ())));
26
27
public static final Set <String > badAllowList3 ;
27
28
public static final Set <String > badAllowList4 ;
28
- public static final Set <String > badAllowList5 ;
29
29
public static Set <String > badAllowList6 = Set .of ("allowed1" , "allowed2" , "allowed3" );
30
- public final Set <String > badAllowList7 = Set .of ("allowed1" , "allowed2" , "allowed3" );
30
+ public final Set <String > goodAllowList7 = Set .of ("allowed1" , "allowed2" , "allowed3" );
31
31
32
32
static {
33
33
goodAllowList3 = Set .of ("allowed1" , "allowed2" , "allowed3" );
34
34
goodAllowList4 = Collections .unmodifiableSet (new HashSet <String >(Arrays .asList ("allowed1" , "allowed2" )));
35
35
badAllowList3 = Set .of (getNonConstantString (), "allowed2" , "allowed3" );
36
36
badAllowList4 = Collections .unmodifiableSet (new HashSet <String >(Arrays .asList ("allowed1" , getNonConstantString ())));
37
- badAllowList5 = new HashSet <String >();
38
- badAllowList5 .add ("allowed1" );
39
- badAllowList5 .add ("allowed2" );
40
- badAllowList5 .add ("allowed3" );
37
+ goodAllowList5 = new HashSet <String >();
38
+ goodAllowList5 .add ("allowed1" );
39
+ goodAllowList5 .add ("allowed2" );
40
+ goodAllowList5 .add ("allowed3" );
41
41
}
42
42
43
43
public static String getNonConstantString () {
@@ -104,8 +104,8 @@ private static void testStaticFields(String[] args) throws IOException, SQLExcep
104
104
+ tainted + "' ORDER BY PRICE" ;
105
105
ResultSet results = connection .createStatement ().executeQuery (query );
106
106
}
107
- // BAD : an allowlist is used with constant strings
108
- if (badAllowList5 .contains (tainted )){
107
+ // GOOD : an allowlist is used with constant strings
108
+ if (goodAllowList5 .contains (tainted )){
109
109
String query = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
110
110
+ tainted + "' ORDER BY PRICE" ;
111
111
ResultSet results = connection .createStatement ().executeQuery (query );
@@ -120,8 +120,8 @@ private static void testStaticFields(String[] args) throws IOException, SQLExcep
120
120
121
121
private void testNonStaticFields (String [] args ) throws IOException , SQLException {
122
122
String tainted = args [1 ];
123
- // BAD : the allowlist is in a non-static field
124
- if (badAllowList7 .contains (tainted )){
123
+ // GOOD : the allowlist is in a non-static field
124
+ if (goodAllowList7 .contains (tainted )){
125
125
String query = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
126
126
+ tainted + "' ORDER BY PRICE" ;
127
127
ResultSet results = connection .createStatement ().executeQuery (query );
0 commit comments