|
7 | 7 | import javax.servlet.http.HttpServletRequest;
|
8 | 8 | import javax.servlet.http.HttpServletResponse;
|
9 | 9 | import javax.servlet.http.Cookie;
|
| 10 | +import org.apache.commons.lang3.RandomStringUtils; |
10 | 11 |
|
11 | 12 | public class WeakRandomCookies extends HttpServlet {
|
12 | 13 | HttpServletResponse response;
|
@@ -42,5 +43,26 @@ public void doGet() {
|
42 | 43 |
|
43 | 44 | Cookie cookie5 = new Cookie("name", Integer.toString(tlr.nextInt()));
|
44 | 45 | response.addCookie(cookie5); // $hasWeakRandomFlow
|
| 46 | + |
| 47 | + Cookie cookie6 = new Cookie("name", RandomStringUtils.random(10)); |
| 48 | + response.addCookie(cookie6); // $hasWeakRandomFlow |
| 49 | + |
| 50 | + Cookie cookie7 = new Cookie("name", RandomStringUtils.randomAscii(10)); |
| 51 | + response.addCookie(cookie7); // $hasWeakRandomFlow |
| 52 | + |
| 53 | + long c3 = r.nextLong(); |
| 54 | + // BAD: The cookie value may be predictable. |
| 55 | + Cookie cookie8 = new Cookie("name", Long.toString(c3 * 5)); |
| 56 | + response.addCookie(cookie8); // $hasWeakRandomFlow |
| 57 | + |
| 58 | + double c4 = Math.random(); |
| 59 | + // BAD: The cookie value may be predictable. |
| 60 | + Cookie cookie9 = new Cookie("name", Double.toString(c4)); |
| 61 | + response.addCookie(cookie9); // $hasWeakRandomFlow |
| 62 | + |
| 63 | + double c5 = Math.random(); |
| 64 | + // BAD: The cookie value may be predictable. |
| 65 | + Cookie cookie10 = new Cookie("name", Double.toString(++c5)); |
| 66 | + response.addCookie(cookie10); // $hasWeakRandomFlow |
45 | 67 | }
|
46 | 68 | }
|
0 commit comments