3
3
import com .alibaba .fastjson .JSON ;
4
4
import com .alibaba .fastjson .JSONObject ;
5
5
6
+ import com .netflix .ribbon .proxy .annotation .Http ;
6
7
import org .joychou .security .SecurityUtil ;
7
8
import org .springframework .http .MediaType ;
8
9
import org .springframework .security .web .csrf .CsrfToken ;
9
10
import org .springframework .web .bind .annotation .*;
11
+ import org .springframework .web .servlet .ModelAndView ;
12
+ import org .springframework .web .servlet .view .json .MappingJackson2JsonView ;
10
13
11
14
import javax .servlet .http .HttpServletRequest ;
12
15
import java .security .Principal ;
@@ -27,7 +30,7 @@ public class JSONP {
27
30
28
31
29
32
// get current login username
30
- public static String getUserInfo (HttpServletRequest request ) {
33
+ public static String getUserInfo2JsonStr (HttpServletRequest request ) {
31
34
Principal principal = request .getUserPrincipal ();
32
35
33
36
String username = principal .getName ();
@@ -46,7 +49,7 @@ public static String getUserInfo(HttpServletRequest request) {
46
49
@ RequestMapping (value = "/referer" , produces = "application/javascript" )
47
50
private String referer (HttpServletRequest request ) {
48
51
String callback = request .getParameter ("callback" );
49
- return callback + "(" + getUserInfo (request ) + ")" ;
52
+ return callback + "(" + getUserInfo2JsonStr (request ) + ")" ;
50
53
}
51
54
52
55
/**
@@ -64,7 +67,7 @@ private String emptyReferer(HttpServletRequest request) {
64
67
}
65
68
66
69
String callback = request .getParameter ("callback" );
67
- return callback + "(" + getUserInfo (request ) + ")" ;
70
+ return callback + "(" + getUserInfo2JsonStr (request ) + ")" ;
68
71
}
69
72
70
73
/**
@@ -77,10 +80,26 @@ private String emptyReferer(HttpServletRequest request) {
77
80
*/
78
81
@ RequestMapping (value = "/advice" , produces = MediaType .APPLICATION_JSON_VALUE )
79
82
public JSONObject advice (HttpServletRequest request ) {
80
- return JSON .parseObject (getUserInfo (request ));
83
+ return JSON .parseObject (getUserInfo2JsonStr (request ));
84
+ }
85
+
81
86
87
+ /**
88
+ * http://localhost:8080/jsonp/mappingJackson2JsonView?callback=test
89
+ * Reference: https://p0sec.net/index.php/archives/122/ from p0
90
+ * Affected version: java-sec-code test case version: 4.3.6
91
+ * - Spring Framework 5.0 to 5.0.6
92
+ * - Spring Framework 4.1 to 4.3.17
93
+ */
94
+ @ RequestMapping (value = "/mappingJackson2JsonView" , produces = MediaType .APPLICATION_JSON_VALUE )
95
+ public ModelAndView mappingJackson2JsonView (HttpServletRequest req ) {
96
+ ModelAndView view = new ModelAndView (new MappingJackson2JsonView ());
97
+ Principal principal = req .getUserPrincipal ();
98
+ view .addObject ("username" , principal .getName () );
99
+ return view ;
82
100
}
83
101
102
+
84
103
/**
85
104
* Safe code.
86
105
* http://localhost:8080/jsonp/sec?callback=test
@@ -94,7 +113,7 @@ private String safecode(HttpServletRequest request) {
94
113
}
95
114
96
115
String callback = request .getParameter ("callback" );
97
- return callback + "(" + getUserInfo (request ) + ")" ;
116
+ return callback + "(" + getUserInfo2JsonStr (request ) + ")" ;
98
117
}
99
118
100
119
0 commit comments