Skip to content

Commit 9821216

Browse files
committed
add xxe return back filecontent
1 parent 05ae55e commit 9821216

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.joychou.controller;
2+
3+
import org.springframework.web.bind.annotation.CookieValue;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
6+
import javax.servlet.http.Cookie;
7+
import javax.servlet.http.HttpServletRequest;
8+
import org.joychou.util.WebUtils;
9+
import org.springframework.web.bind.annotation.RestController;
10+
import static org.springframework.web.util.WebUtils.getCookie;
11+
12+
@RestController
13+
@RequestMapping("/cookie")
14+
public class Cookies {
15+
16+
private static String NICK = "nick";
17+
18+
@RequestMapping(value = "/vuln01")
19+
private String vuln01(HttpServletRequest req) {
20+
String nick = WebUtils.getCookieValueByName(req, NICK); // key code
21+
return "Cookie nick: " + nick;
22+
}
23+
24+
25+
@RequestMapping(value = "/vuln02")
26+
private String vuln02(HttpServletRequest req) {
27+
String nick = null;
28+
Cookie[] cookie = req.getCookies();
29+
30+
if (cookie != null) {
31+
nick = getCookie(req, NICK).getValue(); // key code
32+
}
33+
34+
return "Cookie nick: " + nick;
35+
}
36+
37+
38+
@RequestMapping(value = "/vuln03")
39+
private String vuln03(HttpServletRequest req) {
40+
String nick = null;
41+
Cookie cookies[] = req.getCookies();
42+
if (cookies != null) {
43+
for (Cookie cookie : cookies) {
44+
// key code. Equals can also be equalsIgnoreCase.
45+
if (NICK.equals(cookie.getName())) {
46+
nick = cookie.getValue();
47+
}
48+
}
49+
}
50+
return "Cookie nick: " + nick;
51+
}
52+
53+
54+
@RequestMapping(value = "/vuln04")
55+
private String vuln04(HttpServletRequest req) {
56+
String nick = null;
57+
Cookie cookies[] = req.getCookies();
58+
if (cookies != null) {
59+
for (Cookie cookie : cookies) {
60+
if (cookie.getName().equalsIgnoreCase(NICK)) { // key code
61+
nick = cookie.getValue();
62+
}
63+
}
64+
}
65+
return "Cookie nick: " + nick;
66+
}
67+
68+
69+
70+
@RequestMapping(value = "/vuln05")
71+
private String vuln05(@CookieValue("nick") String nick) {
72+
return "Cookie nick: " + nick;
73+
}
74+
75+
76+
@RequestMapping(value = "/vuln06")
77+
private String vuln06(@CookieValue(value = "nick") String nick) {
78+
return "Cookie nick: " + nick;
79+
}
80+
81+
}

src/main/java/org/joychou/controller/jsonp/JSONPAdvice.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import org.springframework.web.bind.annotation.ControllerAdvice;
55
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;
66

7-
7+
// AbstractJsonpResponseBodyAdvice will be removed as of Spring Framework 5.1, use CORS instead.
8+
// Since Spring Framework 4.1
9+
// Springboot 2.1.0 RELEASE use spring framework 5.1.2
810
@ControllerAdvice
911
public class JSONPAdvice extends AbstractJsonpResponseBodyAdvice {
1012

src/main/java/org/joychou/util/WebUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.joychou.util;
22

3+
import javax.servlet.http.Cookie;
34
import javax.servlet.http.HttpServletRequest;
45
import java.io.IOException;
56
import java.io.InputStream;
@@ -17,4 +18,9 @@ public static String convertStreamToString(java.io.InputStream is) {
1718
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
1819
return s.hasNext() ? s.next() : "";
1920
}
21+
22+
public static String getCookieValueByName(HttpServletRequest request, String cookieName) {
23+
Cookie cookie = org.springframework.web.util.WebUtils.getCookie(request, cookieName);
24+
return cookie == null ? null : cookie.getValue();
25+
}
2026
}

0 commit comments

Comments
 (0)