Skip to content

Commit 38eb3e4

Browse files
committed
Java: Adjust expected output.
1 parent 2ff2d25 commit 38eb3e4

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

java/ql/test/query-tests/security/CWE-089/semmle/examples/AllowListSanitizerWithJavaUtilList.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ class AllowListSanitizerWithJavaUtilList {
2222
public static final List<String> goodAllowList2 = Collections.unmodifiableList(Arrays.asList("allowed1"));
2323
public static final List<String> goodAllowList3;
2424
public static final List<String> goodAllowList4;
25+
public static final List<String> goodAllowList5;
2526
public static final List<String> badAllowList1 = List.of("allowed1", "allowed2", getNonConstantString());
2627
public static final List<String> badAllowList2 = Collections.unmodifiableList(Arrays.asList("allowed1", getNonConstantString()));
2728
public static final List<String> badAllowList3;
2829
public static final List<String> badAllowList4;
29-
public static final List<String> badAllowList5;
3030
public static List<String> badAllowList6 = List.of("allowed1", "allowed2", "allowed3");
31-
public final List<String> badAllowList7 = List.of("allowed1", "allowed2", "allowed3");
31+
public final List<String> goodAllowList7 = List.of("allowed1", "allowed2", "allowed3");
3232

3333
static {
3434
goodAllowList3 = List.of("allowed1", "allowed2", "allowed3");
3535
goodAllowList4 = Collections.unmodifiableList(Arrays.asList("allowed1", "allowed2"));
3636
badAllowList3 = List.of(getNonConstantString(), "allowed2", "allowed3");
3737
badAllowList4 = Collections.unmodifiableList(Arrays.asList("allowed1", getNonConstantString()));
38-
badAllowList5 = new ArrayList<String>();
39-
badAllowList5.add("allowed1");
40-
badAllowList5.add("allowed2");
41-
badAllowList5.add("allowed3");
38+
goodAllowList5 = new ArrayList<String>();
39+
goodAllowList5.add("allowed1");
40+
goodAllowList5.add("allowed2");
41+
goodAllowList5.add("allowed3");
4242
}
4343

4444
public static String getNonConstantString() {
@@ -105,8 +105,8 @@ private static void testStaticFields(String[] args) throws IOException, SQLExcep
105105
+ tainted + "' ORDER BY PRICE";
106106
ResultSet results = connection.createStatement().executeQuery(query);
107107
}
108-
// BAD: an allowlist is used with constant strings
109-
if(badAllowList5.contains(tainted)){
108+
// GOOD: an allowlist is used with constant strings
109+
if(goodAllowList5.contains(tainted)){
110110
String query = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
111111
+ tainted + "' ORDER BY PRICE";
112112
ResultSet results = connection.createStatement().executeQuery(query);
@@ -121,8 +121,8 @@ private static void testStaticFields(String[] args) throws IOException, SQLExcep
121121

122122
private void testNonStaticFields(String[] args) throws IOException, SQLException {
123123
String tainted = args[0];
124-
// BAD: the allowlist is in a non-static field
125-
if(badAllowList7.contains(tainted)){
124+
// GOOD: the allowlist is in a non-static field
125+
if(goodAllowList7.contains(tainted)){
126126
String query = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
127127
+ tainted + "' ORDER BY PRICE";
128128
ResultSet results = connection.createStatement().executeQuery(query);

java/ql/test/query-tests/security/CWE-089/semmle/examples/AllowListSanitizerWithJavaUtilSet.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ class AllowListSanitizerWithJavaUtilSet {
2121
public static final Set<String> goodAllowList2 = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("allowed1","allowed2")));
2222
public static final Set<String> goodAllowList3;
2323
public static final Set<String> goodAllowList4;
24+
public static final Set<String> goodAllowList5;
2425
public static final Set<String> badAllowList1 = Set.of("allowed1", "allowed2", getNonConstantString());
2526
public static final Set<String> badAllowList2 = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("allowed1", getNonConstantString())));
2627
public static final Set<String> badAllowList3;
2728
public static final Set<String> badAllowList4;
28-
public static final Set<String> badAllowList5;
2929
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");
3131

3232
static {
3333
goodAllowList3 = Set.of("allowed1", "allowed2", "allowed3");
3434
goodAllowList4 = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("allowed1", "allowed2")));
3535
badAllowList3 = Set.of(getNonConstantString(), "allowed2", "allowed3");
3636
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");
4141
}
4242

4343
public static String getNonConstantString() {
@@ -104,8 +104,8 @@ private static void testStaticFields(String[] args) throws IOException, SQLExcep
104104
+ tainted + "' ORDER BY PRICE";
105105
ResultSet results = connection.createStatement().executeQuery(query);
106106
}
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)){
109109
String query = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
110110
+ tainted + "' ORDER BY PRICE";
111111
ResultSet results = connection.createStatement().executeQuery(query);
@@ -120,8 +120,8 @@ private static void testStaticFields(String[] args) throws IOException, SQLExcep
120120

121121
private void testNonStaticFields(String[] args) throws IOException, SQLException {
122122
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)){
125125
String query = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
126126
+ tainted + "' ORDER BY PRICE";
127127
ResultSet results = connection.createStatement().executeQuery(query);

0 commit comments

Comments
 (0)