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

Skip to content

Commit c5577cb

Browse files
committed
Fix the problem
1 parent f795d5e commit c5577cb

32 files changed

Lines changed: 1084 additions & 428 deletions

java/ql/src/Security/CWE/CWE-352/JsonpInjection.ql

Lines changed: 0 additions & 68 deletions
This file was deleted.

java/ql/src/Security/CWE/CWE-352/JsonpInjectionFilterLib.qll

Lines changed: 0 additions & 77 deletions
This file was deleted.

java/ql/src/Security/CWE/CWE-352/JsonpInjectionLib.qll

Lines changed: 0 additions & 155 deletions
This file was deleted.

java/ql/src/Security/CWE/CWE-352/JsonStringLib.qll renamed to java/ql/src/experimental/Security/CWE/CWE-352/JsonStringLib.qll

File renamed without changes.

java/ql/test/experimental/query-tests/security/CWE-352/JsonpInjection.java renamed to java/ql/src/experimental/Security/CWE/CWE-352/JsonpController.java

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
import com.google.gson.Gson;
44
import java.io.PrintWriter;
55
import java.util.HashMap;
6-
import java.util.Random;
76
import javax.servlet.http.HttpServletRequest;
87
import javax.servlet.http.HttpServletResponse;
98
import org.springframework.stereotype.Controller;
109
import org.springframework.web.bind.annotation.GetMapping;
11-
import org.springframework.web.bind.annotation.RequestMapping;
12-
import org.springframework.web.bind.annotation.RequestMethod;
1310
import org.springframework.web.bind.annotation.ResponseBody;
1411

1512
@Controller
16-
public class JsonpInjection {
13+
public class JsonpController {
1714
private static HashMap hashMap = new HashMap();
1815

1916
static {
@@ -96,54 +93,13 @@ public void bad6(HttpServletRequest request,
9693

9794
@GetMapping(value = "jsonp7")
9895
@ResponseBody
99-
public String good(HttpServletRequest request) {
100-
String resultStr = null;
101-
String jsonpCallback = request.getParameter("jsonpCallback");
102-
103-
String val = "";
104-
Random random = new Random();
105-
for (int i = 0; i < 10; i++) {
106-
val += String.valueOf(random.nextInt(10));
107-
}
108-
// good
109-
jsonpCallback = jsonpCallback + "_" + val;
110-
String jsonStr = getJsonStr(hashMap);
111-
resultStr = jsonpCallback + "(" + jsonStr + ")";
112-
return resultStr;
113-
}
114-
115-
@GetMapping(value = "jsonp8")
116-
@ResponseBody
11796
public String good1(HttpServletRequest request) {
11897
String resultStr = null;
119-
String jsonpCallback = request.getParameter("jsonpCallback");
12098

12199
String token = request.getParameter("token");
122100

123-
// good
124101
if (verifToken(token)){
125-
System.out.println(token);
126-
String jsonStr = getJsonStr(hashMap);
127-
resultStr = jsonpCallback + "(" + jsonStr + ")";
128-
return resultStr;
129-
}
130-
131-
return "error";
132-
}
133-
134-
@GetMapping(value = "jsonp9")
135-
@ResponseBody
136-
public String good2(HttpServletRequest request) {
137-
String resultStr = null;
138-
String jsonpCallback = request.getParameter("jsonpCallback");
139-
140-
String referer = request.getHeader("Referer");
141-
142-
boolean result = verifReferer(referer);
143-
144-
boolean test = result;
145-
// good
146-
if (test){
102+
String jsonpCallback = request.getParameter("jsonpCallback");
147103
String jsonStr = getJsonStr(hashMap);
148104
resultStr = jsonpCallback + "(" + jsonStr + ")";
149105
return resultStr;

java/ql/src/Security/CWE/CWE-352/JsonpInjection.java renamed to java/ql/src/experimental/Security/CWE/CWE-352/JsonpInjection.java

File renamed without changes.

java/ql/src/Security/CWE/CWE-352/JsonpInjection.qhelp renamed to java/ql/src/experimental/Security/CWE/CWE-352/JsonpInjection.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ there is a problem of sensitive information leakage.</p>
1616

1717
<p>The following example shows the case of no verification processing and verification processing for the external input function name.</p>
1818

19-
<sample src="JsonHijacking.java" />
19+
<sample src="JsonpInjection.java" />
2020

2121
</example>
2222
<references>

0 commit comments

Comments
 (0)