33import com .alibaba .fastjson .JSON ;
44import com .alibaba .fastjson .JSONObject ;
55
6+ import com .netflix .ribbon .proxy .annotation .Http ;
67import org .joychou .security .SecurityUtil ;
78import org .springframework .http .MediaType ;
89import org .springframework .security .web .csrf .CsrfToken ;
910import org .springframework .web .bind .annotation .*;
11+ import org .springframework .web .servlet .ModelAndView ;
12+ import org .springframework .web .servlet .view .json .MappingJackson2JsonView ;
1013
1114import javax .servlet .http .HttpServletRequest ;
1215import java .security .Principal ;
@@ -27,7 +30,7 @@ public class JSONP {
2730
2831
2932 // get current login username
30- public static String getUserInfo (HttpServletRequest request ) {
33+ public static String getUserInfo2JsonStr (HttpServletRequest request ) {
3134 Principal principal = request .getUserPrincipal ();
3235
3336 String username = principal .getName ();
@@ -46,7 +49,7 @@ public static String getUserInfo(HttpServletRequest request) {
4649 @ RequestMapping (value = "/referer" , produces = "application/javascript" )
4750 private String referer (HttpServletRequest request ) {
4851 String callback = request .getParameter ("callback" );
49- return callback + "(" + getUserInfo (request ) + ")" ;
52+ return callback + "(" + getUserInfo2JsonStr (request ) + ")" ;
5053 }
5154
5255 /**
@@ -64,7 +67,7 @@ private String emptyReferer(HttpServletRequest request) {
6467 }
6568
6669 String callback = request .getParameter ("callback" );
67- return callback + "(" + getUserInfo (request ) + ")" ;
70+ return callback + "(" + getUserInfo2JsonStr (request ) + ")" ;
6871 }
6972
7073 /**
@@ -77,10 +80,26 @@ private String emptyReferer(HttpServletRequest request) {
7780 */
7881 @ RequestMapping (value = "/advice" , produces = MediaType .APPLICATION_JSON_VALUE )
7982 public JSONObject advice (HttpServletRequest request ) {
80- return JSON .parseObject (getUserInfo (request ));
83+ return JSON .parseObject (getUserInfo2JsonStr (request ));
84+ }
85+
8186
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 ;
82100 }
83101
102+
84103 /**
85104 * Safe code.
86105 * http://localhost:8080/jsonp/sec?callback=test
@@ -94,7 +113,7 @@ private String safecode(HttpServletRequest request) {
94113 }
95114
96115 String callback = request .getParameter ("callback" );
97- return callback + "(" + getUserInfo (request ) + ")" ;
116+ return callback + "(" + getUserInfo2JsonStr (request ) + ")" ;
98117 }
99118
100119
0 commit comments