Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/main/java/org/owasp/benchmark/testcode/BenchmarkTest00094.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");

javax.servlet.http.Cookie[] theCookies = request.getCookies();

String param = "noCookieValueSupplied";
if (theCookies != null) {
for (javax.servlet.http.Cookie theCookie : theCookies) {
if (theCookie.getName().equals("BenchmarkTest00094")) {
param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8");
break;
}
}
}
String param = getParam(request);

String bar = "safe!";
java.util.HashMap<String, Object> map52993 = new java.util.HashMap<String, Object>();
Expand Down Expand Up @@ -128,4 +118,19 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
response.getWriter()
.println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed");
}

private static String getParam(HttpServletRequest request)
throws java.io.UnsupportedEncodingException {
javax.servlet.http.Cookie[] theCookies = request.getCookies();
String param = "noCookieValueSupplied";
if (theCookies != null) {
for (javax.servlet.http.Cookie theCookie : theCookies) {
if (theCookie.getName().equals("BenchmarkTest00094")) {
param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8");
break;
}
}
}
return param;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
if (cookies != null) {
for (int i = 0; !foundUser && i < cookies.length; i++) {
javax.servlet.http.Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName())) {
if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) {
foundUser = true;
}
if (cookieName.equals(cookie.getName())
&& cookie.getValue()
.equals(request.getSession().getAttribute(cookieName))) {
foundUser = true;
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/org/owasp/benchmark/testcode/BenchmarkTest02354.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");

String param = "";
boolean flag = true;
java.util.Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements() && flag) {
String name = (String) names.nextElement();
String[] values = request.getParameterValues(name);
if (values != null) {
for (int i = 0; i < values.length && flag; i++) {
String value = values[i];
if (value.equals("BenchmarkTest02354")) {
param = name;
flag = false;
}
}
}
}
String param = findParam(request);

String bar = doSomething(request, param);

Expand All @@ -76,6 +61,22 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
}
} // end doPost

private static String findParam(HttpServletRequest request) {
java.util.Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String[] values = request.getParameterValues(name);
if (values != null) {
for (int i = 0; i < values.length; i++) {
if (values[i].equals("BenchmarkTest02354")) {
return name;
}
}
}
}
return "";
}

private static String doSomething(HttpServletRequest request, String param)
throws ServletException, IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
if (cookies != null) {
for (int i = 0; !foundUser && i < cookies.length; i++) {
javax.servlet.http.Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName())) {
if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) {
foundUser = true;
}
if (cookieName.equals(cookie.getName())
&& cookie.getValue()
.equals(request.getSession().getAttribute(cookieName))) {
foundUser = true;
}
}
}
Expand Down