|
| 1 | +/** |
| 2 | + * OWASP Benchmark Project v1.2 |
| 3 | + * |
| 4 | + * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For |
| 5 | + * details, please see <a |
| 6 | + * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>. |
| 7 | + * |
| 8 | + * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms |
| 9 | + * of the GNU General Public License as published by the Free Software Foundation, version 2. |
| 10 | + * |
| 11 | + * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 13 | + * PURPOSE. See the GNU General Public License for more details. |
| 14 | + * |
| 15 | + * @author Dave Wichers |
| 16 | + * @created 2015 |
| 17 | + */ |
| 18 | +package org.owasp.benchmark.testcode; |
| 19 | + |
| 20 | +import java.io.IOException; |
| 21 | +import javax.servlet.ServletException; |
| 22 | +import javax.servlet.annotation.WebServlet; |
| 23 | +import javax.servlet.http.HttpServlet; |
| 24 | +import javax.servlet.http.HttpServletRequest; |
| 25 | +import javax.servlet.http.HttpServletResponse; |
| 26 | + |
| 27 | +@WebServlet(value = "/trustbound-00/Benchmark00994") |
| 28 | +public class Benchmark00994 extends HttpServlet { |
| 29 | + |
| 30 | + private static final long serialVersionUID = 1L; |
| 31 | + |
| 32 | + @Override |
| 33 | + public void doGet(HttpServletRequest request, HttpServletResponse response) |
| 34 | + throws ServletException, IOException { |
| 35 | + response.setContentType("text/html;charset=UTF-8"); |
| 36 | + javax.servlet.http.Cookie userCookie = |
| 37 | + new javax.servlet.http.Cookie("Benchmark00994", "my_user_id"); |
| 38 | + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes |
| 39 | + userCookie.setSecure(true); |
| 40 | + userCookie.setPath(request.getRequestURI()); |
| 41 | + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); |
| 42 | + response.addCookie(userCookie); |
| 43 | + javax.servlet.RequestDispatcher rd = |
| 44 | + request.getRequestDispatcher("/trustbound-00/Benchmark00994.html"); |
| 45 | + rd.include(request, response); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void doPost(HttpServletRequest request, HttpServletResponse response) |
| 50 | + throws ServletException, IOException { |
| 51 | + response.setContentType("text/html;charset=UTF-8"); |
| 52 | + |
| 53 | + javax.servlet.http.Cookie[] theCookies = request.getCookies(); |
| 54 | + |
| 55 | + String param = "noCookieValueSupplied"; |
| 56 | + if (theCookies != null) { |
| 57 | + for (javax.servlet.http.Cookie theCookie : theCookies) { |
| 58 | + if (theCookie.getName().equals("Benchmark00994")) { |
| 59 | + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); |
| 60 | + break; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + String bar = new Test().doSomething(request, param); |
| 66 | + |
| 67 | + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) |
| 68 | + request.getSession().putValue("userid", bar); |
| 69 | + |
| 70 | + response.getWriter() |
| 71 | + .println( |
| 72 | + "Item: 'userid' with value: '" |
| 73 | + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) |
| 74 | + + "' saved in session."); |
| 75 | + } // end doPost |
| 76 | + |
| 77 | + private class Test { |
| 78 | + |
| 79 | + public String doSomething(HttpServletRequest request, String param) |
| 80 | + throws ServletException, IOException { |
| 81 | + |
| 82 | + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); |
| 83 | + |
| 84 | + return bar; |
| 85 | + } |
| 86 | + } // end innerclass Test |
| 87 | +} // end DataflowThruInnerClass |
0 commit comments