1313import org .joychou .security .SecurityUtil ;
1414
1515/**
16- * @author JoyChou ([email protected] ) 17- * @date 2017.12.28
18- * @desc Java url redirect.
19- * @fix Check redirect url whitelist.
16+ * The vulnerability code and security code of Java url redirect.
17+ * The security code is checking whitelist of url redirect.
18+ *
19+ * @author JoyChou ([email protected] ) 20+ * @version 2017.12.28
2021 */
2122
22-
2323@ Controller
2424@ RequestMapping ("/urlRedirect" )
2525public class URLRedirect {
2626
2727 /**
28- * usage: http://localhost:8080/urlRedirect/redirect?url=http://www.baidu.com
29- *
28+ * http://localhost:8080/urlRedirect/redirect?url=http://www.baidu.com
3029 */
3130 @ GetMapping ("/redirect" )
3231 public String redirect (@ RequestParam ("url" ) String url ) {
3332 return "redirect:" + url ;
3433 }
3534
35+
3636 /**
37- * usage: http://localhost:8080/urlRedirect/setHeader?url=http://www.baidu.com
38- *
37+ * http://localhost:8080/urlRedirect/setHeader?url=http://www.baidu.com
3938 */
4039 @ RequestMapping ("/setHeader" )
4140 @ ResponseBody
@@ -45,9 +44,9 @@ public static void setHeader(HttpServletRequest request, HttpServletResponse res
4544 response .setHeader ("Location" , url );
4645 }
4746
47+
4848 /**
49- * usage: http://localhost:8080/urlRedirect/sendRedirect?url=http://www.baidu.com
50- *
49+ * http://localhost:8080/urlRedirect/sendRedirect?url=http://www.baidu.com
5150 */
5251 @ RequestMapping ("/sendRedirect" )
5352 @ ResponseBody
@@ -58,13 +57,12 @@ public static void sendRedirect(HttpServletRequest request, HttpServletResponse
5857
5958
6059 /**
61- * desc: security code.Because it can only jump according to the path, it cannot jump according to other urls.
62- * usage: http://localhost:8080/urlRedirect/forward?url=/urlRedirect/test
63- *
60+ * Safe code. Because it can only jump according to the path, it cannot jump according to other urls.
61+ * http://localhost:8080/urlRedirect/forward?url=/urlRedirect/test
6462 */
6563 @ RequestMapping ("/forward" )
6664 @ ResponseBody
67- public static void forward (HttpServletRequest request , HttpServletResponse response ) throws IOException {
65+ public static void forward (HttpServletRequest request , HttpServletResponse response ) {
6866 String url = request .getParameter ("url" );
6967 RequestDispatcher rd =request .getRequestDispatcher (url );
7068 try {
@@ -74,10 +72,10 @@ public static void forward(HttpServletRequest request, HttpServletResponse respo
7472 }
7573 }
7674
75+
7776 /**
78- * desc: sendRedirect security code
79- * usage: http://localhost:8080/urlRedirect/sendRedirect_seccode?url=http://www.baidu.com
80- *
77+ * Safe code of sendRedirect.
78+ * http://localhost:8080/urlRedirect/sendRedirect_seccode?url=http://www.baidu.com
8179 */
8280 @ RequestMapping ("/sendRedirect_seccode" )
8381 @ ResponseBody
0 commit comments