Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d47fced

Browse files
committed
Add tests
1 parent 158366a commit d47fced

10 files changed

Lines changed: 382 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import org.apache.ibatis.annotations.Param;
2+
import org.apache.ibatis.jdbc.SQL;
3+
4+
public class MyBatisProvider {
5+
public String badSelect(@Param("input") final String input) {
6+
String s = (new SQL() {
7+
{
8+
this.SELECT("password");
9+
this.FROM("users");
10+
this.WHERE("username = '" + input + "'");
11+
}
12+
}).toString();
13+
return s;
14+
}
15+
16+
public String badDelete(@Param("input") final String input) {
17+
return "DELETE FROM users WHERE username = '" + input + "';";
18+
}
19+
20+
public String badUpdate(@Param("input") final String input) {
21+
String s = (new SQL() {
22+
{
23+
this.UPDATE("users");
24+
this.SET("balance = 0");
25+
this.WHERE("username = '" + input + "'");
26+
}
27+
}).toString();
28+
return s;
29+
}
30+
31+
public String badInsert(@Param("input") final String input) {
32+
return "INSERT INTO users VALUES (1, '" + input + "', 'hunter2');";
33+
}
34+
}
35+

java/ql/test/experimental/query-tests/security/CWE-089/src/main/MybatisSqlInjection.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,25 @@ public List<Test> good1(Integer id) {
6868
List<Test> result = mybatisSqlInjectionService.good1(id);
6969
return result;
7070
}
71+
72+
// using providers
73+
@GetMapping(value = "badSelect")
74+
public String badSelect(@RequestParam String name) {
75+
return mybatisSqlInjectionService.badSelect(name);
76+
}
77+
78+
@GetMapping(value = "badDelete")
79+
public void badDelete(@RequestParam String name) {
80+
mybatisSqlInjectionService.badDelete(name);
81+
}
82+
83+
@GetMapping(value = "badUpdate")
84+
public void badUpdate(@RequestParam String name) {
85+
mybatisSqlInjectionService.badUpdate(name);
86+
}
87+
88+
@GetMapping(value = "badInsert")
89+
public void badInsert(@RequestParam String name) {
90+
mybatisSqlInjectionService.badInsert(name);
91+
}
7192
}

java/ql/test/experimental/query-tests/security/CWE-089/src/main/MybatisSqlInjectionService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,21 @@ public List<Test> good1(Integer id) {
5555
List<Test> result = sqlInjectionMapper.good1(id);
5656
return result;
5757
}
58+
59+
// using providers
60+
public String badSelect(String input) {
61+
return sqlInjectionMapper.badSelect(input);
62+
}
63+
64+
public void badDelete(String input) {
65+
sqlInjectionMapper.badDelete(input);
66+
}
67+
68+
public void badUpdate(String input) {
69+
sqlInjectionMapper.badUpdate(input);
70+
}
71+
72+
public void badInsert(String input) {
73+
sqlInjectionMapper.badInsert(input);
74+
}
5875
}

java/ql/test/experimental/query-tests/security/CWE-089/src/main/SqlInjectionMapper.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import org.apache.ibatis.annotations.Param;
66
import org.springframework.stereotype.Repository;
77
import org.apache.ibatis.annotations.Select;
8+
import org.apache.ibatis.annotations.SelectProvider;
9+
import org.apache.ibatis.annotations.DeleteProvider;
10+
import org.apache.ibatis.annotations.UpdateProvider;
11+
import org.apache.ibatis.annotations.InsertProvider;
812

913
@Mapper
1014
@Repository
@@ -30,4 +34,29 @@ public interface SqlInjectionMapper {
3034
public Test bad9(HashMap<String, Object> map);
3135

3236
List<Test> good1(Integer id);
37+
38+
//using providers
39+
@SelectProvider(
40+
type = MyBatisProvider.class,
41+
method = "badSelect"
42+
)
43+
String badSelect(String input);
44+
45+
@DeleteProvider(
46+
type = MyBatisProvider.class,
47+
method = "badDelete"
48+
)
49+
void badDelete(String input);
50+
51+
@UpdateProvider(
52+
type = MyBatisProvider.class,
53+
method = "badUpdate"
54+
)
55+
void badUpdate(String input);
56+
57+
@InsertProvider(
58+
type = MyBatisProvider.class,
59+
method = "badInsert"
60+
)
61+
void badInsert(String input);
3362
}

java/ql/test/stubs/org.mybatis-3.5.4/org/apache/ibatis/annotations/DeleteProvider.java

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/org.mybatis-3.5.4/org/apache/ibatis/annotations/InsertProvider.java

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/org.mybatis-3.5.4/org/apache/ibatis/annotations/SelectProvider.java

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/org.mybatis-3.5.4/org/apache/ibatis/annotations/UpdateProvider.java

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)