Skip to content

Commit db29228

Browse files
committed
Merge branch 'main' into impropnull
2 parents 904db78 + a27cb4b commit db29228

File tree

22 files changed

+613
-16
lines changed

22 files changed

+613
-16
lines changed
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# CodeQL CWE coverage
1+
CodeQL CWE coverage
2+
===================
23

3-
An overview of the coverage of MITRE's Common Weakness Enumeration (CWE) for the latest release of CodeQL.
4+
You can view the full coverage of MITRE's Common Weakness Enumeration (CWE) or coverage by language for the latest release of CodeQL.
45

5-
## About CWEs
6+
About CWEs
7+
##########
68

79
The CWE categorization contains several types of entity, collectively known as CWEs. The CWEs that we consider in this report are only those of the types:
810

@@ -11,15 +13,22 @@ The CWE categorization contains several types of entity, collectively known as C
1113
- Weakness Variant
1214
- Compound Element
1315

14-
Other types of CWE do not correspond directly to weaknesses, so are omitted.
16+
Other types of CWE that do not correspond directly to weaknesses are omitted.
1517

1618
The CWE categorization includes relationships between entities, in particular a parent-child relationship.
17-
These relationships are associated with Views (another kind of CWE entity). For the purposes of coverage claims, we use the "[Research View](https://cwe.mitre.org/data/definitions/1000.html)."
19+
These relationships are associated with Views (another kind of CWE entity). For the purposes of coverage claims, we use the "`Research View <https://cwe.mitre.org/data/definitions/1000.html>`_."
1820

1921
Every security query is associated with one or more CWEs, which are the most precise CWEs that are covered by that query.
2022
Overall coverage is claimed for the most-precise CWEs, as well as for any of their ancestors in the View.
2123

22-
## Overview
23-
24-
<!-- autogenerated CWE coverage table will be added below -->
25-
24+
.. toctree::
25+
:hidden:
26+
:titlesonly:
27+
28+
full-cwe
29+
cpp-cwe
30+
csharp-cwe
31+
go-cwe
32+
java-cwe
33+
javascript-cwe
34+
python-cwe

docs/codeql/query-help/cpp-cwe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CWE coverage for C and C++
2+
3+
An overview of CWE coverage for C and C++ in the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+

docs/codeql/query-help/csharp-cwe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CWE coverage for C#
2+
3+
An overview of CWE coverage for C# in the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+

docs/codeql/query-help/full-cwe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CodeQL full CWE coverage
2+
3+
An overview of the full coverage of MITRE's Common Weakness Enumeration (CWE) for the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+

docs/codeql/query-help/go-cwe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CWE coverage for Go
2+
3+
An overview of CWE coverage for Go in the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+

docs/codeql/query-help/java-cwe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CWE coverage for Java
2+
3+
An overview of CWE coverage for Java in the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CWE coverage for JavaScript
2+
3+
An overview of CWE coverage for JavaScript in the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+

docs/codeql/query-help/python-cwe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CWE coverage for Python
2+
3+
An overview of CWE coverage for Python in the latest release of CodeQL.
4+
5+
## Overview
6+
7+
<!-- autogenerated CWE coverage table will be added below -->
8+

docs/codeql/query-help/readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ CodeQL query help Sphinx documentation
22
--------------------------------------
33

44
This project supplies the configuration and some boiler plate
5-
index files for the CodeQL query help documentation.
5+
index files for the CodeQL query help and CWE coverage documentation.
66

77
The query help itself is automatically generated by the
8-
"Generate CodeQL query help documentation using Sphinx" workflow.
8+
"Generate CodeQL query help documentation using Sphinx" workflow.
9+
10+
The CWE coverage tables are generated and appended to pages by the "Docs generate query help" workflow in the `semmle-code` repository.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import java.lang.reflect.Method;
2+
import java.util.HashMap;
3+
import java.util.HashSet;
4+
import java.util.List;
5+
import java.util.Map;
6+
import javax.servlet.http.HttpServletRequest;
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.util.StringUtils;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.PathVariable;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RequestMethod;
14+
import org.springframework.web.multipart.MultipartFile;
15+
16+
@Controller
17+
public class UnsafeReflection {
18+
19+
@RequestMapping(value = {"/service/{beanIdOrClassName}/{methodName}"}, method = {RequestMethod.POST}, consumes = {"application/json"}, produces = {"application/json"})
20+
public Object bad1(@PathVariable("beanIdOrClassName") String beanIdOrClassName, @PathVariable("methodName") String methodName, @RequestBody Map<String, Object> body) throws Exception {
21+
List<Object> rawData = null;
22+
try {
23+
rawData = (List<Object>)body.get("methodInput");
24+
} catch (Exception e) {
25+
return e;
26+
}
27+
return invokeService(beanIdOrClassName, methodName, null, rawData);
28+
}
29+
30+
@GetMapping(value = "uf1")
31+
public void good1(HttpServletRequest request) throws Exception {
32+
HashSet<String> hashSet = new HashSet<>();
33+
hashSet.add("com.example.test1");
34+
hashSet.add("com.example.test2");
35+
String className = request.getParameter("className");
36+
String parameterValue = request.getParameter("parameterValue");
37+
if (!hashSet.contains(className)){
38+
throw new Exception("Class not valid: " + className);
39+
}
40+
try {
41+
Class clazz = Class.forName(className);
42+
Object object = clazz.getDeclaredConstructors()[0].newInstance(parameterValue); //good
43+
} catch (Exception e) {
44+
e.printStackTrace();
45+
}
46+
}
47+
48+
@GetMapping(value = "uf2")
49+
public void good2(HttpServletRequest request) throws Exception {
50+
String className = request.getParameter("className");
51+
String parameterValue = request.getParameter("parameterValue");
52+
if (!"com.example.test1".equals(className)){
53+
throw new Exception("Class not valid: " + className);
54+
}
55+
try {
56+
Class clazz = Class.forName(className);
57+
Object object = clazz.getDeclaredConstructors()[0].newInstance(parameterValue); //good
58+
} catch (Exception e) {
59+
e.printStackTrace();
60+
}
61+
}
62+
63+
private Object invokeService(String beanIdOrClassName, String methodName, MultipartFile[] files, List<Object> data) throws Exception {
64+
BeanFactory beanFactory = new BeanFactory();
65+
try {
66+
Object bean = null;
67+
Class<?> beanClass = Class.forName(beanIdOrClassName);
68+
bean = beanFactory.getBean(beanClass);
69+
byte b;
70+
int i;
71+
Method[] arrayOfMethod;
72+
for (i = (arrayOfMethod = bean.getClass().getMethods()).length, b = 0; b < i; ) {
73+
Method method = arrayOfMethod[b];
74+
if (!method.getName().equals(methodName)) {
75+
b++;
76+
continue;
77+
}
78+
Object result = method.invoke(bean, data);
79+
Map<String, Object> map = new HashMap<>();
80+
return map;
81+
}
82+
} catch (Exception e) {
83+
return e;
84+
}
85+
return null;
86+
}
87+
}
88+
89+
class BeanFactory {
90+
91+
private static HashMap<String, Object> classNameMap = new HashMap<>();
92+
93+
private static HashMap<Class<?>, Object> classMap = new HashMap<>();
94+
95+
static {
96+
classNameMap.put("xxxx", Runtime.getRuntime());
97+
classMap.put(Runtime.class, Runtime.getRuntime());
98+
}
99+
100+
public Object getBean(Class<?> clzz) {
101+
return classMap.get(clzz);
102+
}
103+
}

0 commit comments

Comments
 (0)