Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HomeController.java #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update HomeController.java #45

wants to merge 1 commit into from

Conversation

sa-ny
Copy link
Owner

@sa-ny sa-ny commented Oct 11, 2024

No description provided.

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/webapp/WEB-INF/views/profile.jsp:
Falws found for this file:
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 119 for issue 1150
CWE 80 - Information Exposure Through Sent Data - Severity 2 on line 252 for issue 1002
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 163 for issue 1138
CWE 80 - Information Exposure Through Sent Data - Severity 2 on line 247 for issue 1000
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 160 for issue 1133
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 90 for issue 1146

Fix suggestions:

--- test/src/main/webapp/WEB-INF/views/profile.jsp
+++ test/src/main/webapp/WEB-INF/views/profile.jsp
@@ -157,10 +157,10 @@
 							<li>
 								<div class="clear">
 									<div class="commenterImage">
-										<img src="resources/images/<%= heckler.getUsername() %>.png" />
+										<img src="resources/images/<%= heckler.getUsername() %>.png" /><%= Encode.forHtml(heckler.getUsername()) %>										<img src="resources/images/<%= heckler.getUsername() %>.png" />
 									</div>
 									<div class="commentText">
-										<p><%= heckler.getBlabName() %></p>
+										<p><%= heckler.getBlabName() %></p><%= ESAPI.encoder().encodeForHTMLAttribute(heckler.getBlabName()) %>										<p><%= heckler.getBlabName() %></p>
 										<span class="date sub-text">member since <%= heckler.getCreatedDateString() %></span>
 										<br/>
 									</div>
@@ -237,14 +237,14 @@
 				data : new FormData(this),
 				processData : false,
 				contentType : false,
-				success : function(data) {
+				success : function(data) {e.preventDefault()				success : function(data) {
 					console.log("Profile updated");
 					if (data) {
 						if ('values' in data) {
 							$.each(data.values, function(key, val) {
 								$('input[name="' + key + '"]').val(val);
 								if (key === "username") {
-									$('#profileImage').attr('src', 'resources/images/' + val + '.png');
+									$('#profileImage').attr('src', 'resources/images/' + val + '.png');val = ESAPI.encoder().encodeForHTMLAttribute(val)									$('#profileImage').attr('src', 'resources/images/' + val + '.png');
 								}
 							});
 						}

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/webapp/WEB-INF/views/blab.jsp:
Falws found for this file:
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 56 for issue 1135
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 110 for issue 1147
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 60 for issue 1144
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 108 for issue 1131
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 104 for issue 1139

Fix suggestions:

--- test/src/main/webapp/WEB-INF/views/blab.jsp
+++ test/src/main/webapp/WEB-INF/views/blab.jsp
@@ -101,13 +101,13 @@
 							<li>
 								<div>
 									<div class="commenterImage">
-										<img src="resources/images/<%= comment.getAuthor().getUsername() %>.png" />
+										<img src="resources/images/<%= comment.getAuthor().getUsername() %>.png" />HtmlUtils.htmlEscape(comment.getAuthor().())										<img src="resources/images/<%= comment.getAuthor().getUsername() %>.png" />
 									</div>
 									<div class="blockquote">
 										<p class="">
-											"<%= comment.getContent() %>"
+											"<%= comment.getContent() %>", produces="application/json"											"<%= comment.getContent() %>"
 										</p>
-										<span class="date sub-text">by <%= comment.getAuthor().getBlabName() %>
+										<span class="date sub-text">by <%= comment.getAuthor().getBlabName() %>(ESAPI.encoder().encodeForHTMLAttribute(comment.getAuthor().getBlabName()))										<span class="date sub-text">by <%= comment.getAuthor().getBlabName() %>
 											on <%= comment.getTimestampString() %></span><br>
 									</div>
 								</div>

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/java/com/veracode/verademo/controller/BlabController.java:
Falws found for this file:
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 278 for issue 1083
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 175 for issue 1022
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 530 for issue 1081
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 463 for issue 1084
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 523 for issue 1095
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 213 for issue 1082
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 60 for issue 1085
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 531 for issue 1089
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 373 for issue 1080
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 444 for issue 1090
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 467 for issue 1020
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 196 for issue 1001

Fix suggestions:

--- test/src/main/java/com/veracode/verademo/controller/BlabController.java
+++ test/src/main/java/com/veracode/verademo/controller/BlabController.java
@@ -28,6 +28,10 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.apache.commons.text.StringEscapeUtils;
+import org.apache.commons.lang3.StringUtils;
+import java.net.URLEncoder;
+import org.owasp.encoder.Encode;
 
 @Controller
 @Scope("request")
@@ -57,7 +61,7 @@
 			return Utils.redirect("login?target=profile");
 		}
 
-		logger.info("User is Logged In - continuing... UA=" + httpRequest.getHeader("User-Agent") + " U=" + username);
+		logger.info("User is Logged In - continuing... UA=" + URLEncoder.encode(httpRequest.getHeader("User-Agent").toString()) + " U=" + username);
 
 		Connection connect = null;
 		PreparedStatement blabsByMe = null;
@@ -193,7 +197,7 @@
 			logger.error(ex);
 		}
 
-		return ret.toString();
+		return Encode.forHtml(ret.toString());
 	}
 
 	@RequestMapping(value = "/feed", method = RequestMethod.POST)
@@ -210,7 +214,7 @@
 			logger.info("User is not Logged In - redirecting...");
 			return Utils.redirect("login?target=profile");
 		}
-		logger.info("User is Logged In - continuing... UA=" + httpRequest.getHeader("User-Agent") + " U=" + username);
+		logger.info("User is Logged In - continuing... UA=" + StringEscapeUtils.escapeJava(httpRequest.getHeader("User-Agent")) + " U=" + username);
 
 		Connection connect = null;
 		PreparedStatement addBlab = null;
@@ -275,7 +279,7 @@
 			return Utils.redirect("login?target=profile");
 		}
 
-		logger.info("User is Logged In - continuing... UA=" + httpRequest.getHeader("User-Agent") + " U=" + username);
+		logger.info("User is Logged In - continuing... UA=" + StringEscapeUtils.escapeJava(httpRequest.getHeader("User-Agent")) + " U=" + username);
 
 		Connection connect = null;
 		PreparedStatement blabDetails = null;
@@ -370,7 +374,7 @@
 			return Utils.redirect("login?target=feed");
 		}
 
-		logger.info("User is Logged In - continuing... UA=" + httpRequest.getHeader("User-Agent") + " U=" + username);
+		logger.info("User is Logged In - continuing... UA=" + URLEncoder.encode(httpRequest.getHeader("User-Agent")) + " U=" + username);
 		Connection connect = null;
 		PreparedStatement addComment = null;
 		String addCommentSql = "INSERT INTO comments (blabid, blabber, content, timestamp) values (?, ?, ?, ?);";
@@ -441,30 +445,28 @@
 			return Utils.redirect("login?target=blabbers");
 		}
 
-		logger.info("User is Logged In - continuing... UA=" + httpRequest.getHeader("User-Agent") + " U=" + username);
+		logger.info("User is Logged In - continuing... UA=" + URLEncoder.encode(httpRequest.getHeader("User-Agent")) + " U=" + username);
 
 		Connection connect = null;
 		PreparedStatement blabberQuery = null;
-
-		/* START EXAMPLE VULNERABILITY */
-		String blabbersSql = "SELECT users.username," + " users.blab_name," + " users.created_at,"
-				+ " SUM(if(listeners.listener=?, 1, 0)) as listeners,"
-				+ " SUM(if(listeners.status='Active',1,0)) as listening"
-				+ " FROM users LEFT JOIN listeners ON users.username = listeners.blabber"
-				+ " WHERE users.username NOT IN (\"admin\",?)" + " GROUP BY users.username" + " ORDER BY " + sort + ";";
-
+		/* START EXAMPLE FIX */
+		String blabbersSql = "SELECT users.username, " + " users.blab_name, " + " users.created_at, "
+		+ " SUM(if(listeners.listener=?, 1, 0)) as listeners, "
+		+ " SUM(if(listeners.status='Active', 1, 0)) as listening"
+		+ " FROM users LEFT JOIN listeners ON users.username = listeners.blabber"
+		+ " WHERE users.username NOT IN (?)" + " GROUP BY users.username" + " ORDER BY " + sort + ";";
 		try {
-			logger.info("Getting Database connection");
-			// Get the Database Connection
-			Class.forName("com.mysql.jdbc.Driver");
-			connect = DriverManager.getConnection(Constants.create().getJdbcConnectionString());
-
-			// Find the Blabbers
-			logger.info(blabbersSql);
-			blabberQuery = connect.prepareStatement(blabbersSql);
-			blabberQuery.setString(1, username);
-			blabberQuery.setString(2, username);
-			ResultSet blabbersResults = blabberQuery.executeQuery();
+		    logger.info("Getting Database connection");
+		    // Get the Database Connection
+		    Class.forName("com.mysql.jdbc.Driver");
+		    connect = DriverManager.getConnection(Constants.create().getJdbcConnectionString());
+		    // Find the Blabbers
+		    logger.info(blabbersSql);
+		    blabberQuery = connect.prepareStatement(blabbersSql);
+		    blabberQuery.setString(1, username);
+		    blabberQuery.setString(2, username);
+		    blabberQuery.setString(3, username);
+		    ResultSet blabbersResults = blabberQuery.executeQuery();
 			/* END EXAMPLE VULNERABILITY */
 
 			List<Blabber> blabbers = new ArrayList<Blabber>();
@@ -520,15 +522,15 @@
 			return Utils.redirect("login?target=blabbers");
 		}
 
-		logger.info("User is Logged In - continuing... UA=" + httpRequest.getHeader("User-Agent") + " U=" + username);
+		logger.info("User is Logged In - continuing... UA=" + URLEncoder.encode(httpRequest.getHeader("User-Agent")) + " U=" + username);
 
 		if (command == null || command.isEmpty()) {
 			logger.info("Empty command provided...");
 			return nextView = Utils.redirect("login?target=blabbers");
 		}
 
-		logger.info("blabberUsername = " + blabberUsername);
-		logger.info("command = " + command);
+		logger.info("blabberUsername = " + StringUtils.normalizeSpace(blabberUsername));
+		logger.info("command = " + StringUtils.normalizeSpace(command));
 
 		Connection connect = null;
 		PreparedStatement action = null;

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/java/com/veracode/verademo/controller/UserController.java:
Falws found for this file:
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 47 for issue 1086

Fix suggestions:

--- test/src/main/java/com/veracode/verademo/controller/UserController.java
+++ test/src/main/java/com/veracode/verademo/controller/UserController.java
@@ -11,6 +11,7 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.apache.commons.text.StringEscapeUtils;
 
 /**
  * @author johnadmin
@@ -44,7 +45,7 @@
 		}
 		//..
 
-		logger.info("Entering showLogin with username " + username + " and target " + target);
+		logger.info("Entering showLogin with username " + StringEscapeUtils.escapeJava(username) + " and target " + target);
 
 		model.addAttribute("username", username);
 		model.addAttribute("target", target);

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/webapp/WEB-INF/views/feed.jsp:
Falws found for this file:
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 96 for issue 1152
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 141 for issue 1148
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 93 for issue 1141
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 98 for issue 1151

Fix suggestions:

--- test/src/main/webapp/WEB-INF/views/feed.jsp
+++ test/src/main/webapp/WEB-INF/views/feed.jsp
@@ -90,12 +90,12 @@
 							<li>
 								<div>
 									<div class="commenterImage">
-										<img src="resources/images/<%= post.getAuthor().getUsername() %>.png" />
+										<img src="resources/images/<%= post.getAuthor().getUsername() %>.png" /><%= StringEscapeUtils.escapeXml11(post.getAuthor().getUsername()) %>										<img src="resources/images/<%= post.getAuthor().getUsername() %>.png" />
 									</div>
 									<div class="commentText">
-										<p class=""><%= post.getContent() %></p>
+										<p class=""><%= post.getContent() %></p>ESAPI.encoder().encodeForHTMLAttribute(post.getContent())										<p class=""><%= post.getContent() %></p>
 										<span class="date sub-text">
-											by <%= post.getAuthor().getBlabName() %> on <%= post.getPostDateString() %>
+											by <%= post.getAuthor().getBlabName() %> on <%= post.getPostDateString() %>by <%= ESAPI.encoder().encodeForHTMLAttribute(post.getAuthor().getBlabName()) %>											by <%= post.getAuthor().getBlabName() %> on <%= post.getPostDateString() %>
 										</span>
 										<br/>
 										<span class="date sub-text">
@@ -138,7 +138,7 @@
 							%>
 							<li>
 								<div class="commentText">
-									<p class=""><%= post.getContent() %></p>
+									<p class=""><%= post.getContent() %></p><%= StringEscapeUtils.escapeXml11(post.getContent()) %>									<p class=""><%= post.getContent() %></p>
 									<span class="date sub-text">by you on <%= post.getPostDateString() %></span><br/>
 									<span class="date sub-text">
 										<a href="blab?blabid=<%= post.getId() %>"><%= post.getCommentCount() %> Comments</a>

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/java/com/veracode/verademo/commands/IgnoreCommand.java:
Falws found for this file:
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 40 for issue 1014
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 39 for issue 1092
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 46 for issue 1087
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 38 for issue 1033
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 40 for issue 1017
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 47 for issue 1010

Fix suggestions:

--- test/src/main/java/com/veracode/verademo/commands/IgnoreCommand.java
+++ test/src/main/java/com/veracode/verademo/commands/IgnoreCommand.java
@@ -8,6 +8,8 @@
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.commons.lang3.StringUtils;
+import java.net.URLEncoder;
 //..
 public class IgnoreCommand implements BlabberCommand {
 	private static final Logger logger = LogManager.getLogger("VeraDemo:IgnoreCommand");
@@ -24,7 +26,7 @@
 
 	@Override
 	public void execute(String blabberUsername) {
-		String sqlQuery = "DELETE FROM listeners WHERE blabber=? AND listener=?;";
+		String sqlQuery = StringUtils.normalizeSpace("DELETE FROM listeners WHERE blabber=? AND listener=?;");
 		logger.info(sqlQuery);
 		PreparedStatement action;
 		try {
@@ -41,10 +43,13 @@
 			result.next();
 
 			/* START EXAMPLE VULNERABILITY */
-			String event = username + " is now ignoring " + blabberUsername + " (" + result.getString(1) + ")";
-			sqlQuery = "INSERT INTO users_history (blabber, event) VALUES (\"" + username + "\", \"" + event + "\")";
+			String event = username + " is now ignoring " + blabberUsername + " (" + URLEncoder.encode(result.getString(1).toString()) + ")";
+			sqlQuery = "INSERT INTO users_history (blabber, event) VALUES (?,?)";
 			logger.info(sqlQuery);
-			sqlStatement.execute(sqlQuery);
+			sqlStatement = connect.prepareStatement(sqlQuery);
+			sqlStatement.setString(1, username);
+			sqlStatement.setString(2, event);
+			sqlStatement.execute();
 			/* END EXAMPLE VULNERABILITY */
 		} catch (SQLException e) {
 			// TODO Auto-generated catch block

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/java/com/veracode/verademo/commands/ListenCommand.java:
Falws found for this file:
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 40 for issue 1015
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 46 for issue 1088
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 38 for issue 1034
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 40 for issue 1018
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 47 for issue 1011
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 39 for issue 1093

Fix suggestions:

--- test/src/main/java/com/veracode/verademo/commands/ListenCommand.java
+++ test/src/main/java/com/veracode/verademo/commands/ListenCommand.java
@@ -8,6 +8,8 @@
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import java.net.URLEncoder;
+import org.apache.commons.lang3.StringUtils;
 
 public class ListenCommand implements BlabberCommand {
 	private static final Logger logger = LogManager.getLogger("VeraDemo:ListenCommand");
@@ -24,7 +26,7 @@
 
 	@Override
 	public void execute(String blabberUsername) {
-		String sqlQuery = "INSERT INTO listeners (blabber, listener, status) values (?, ?, 'Active');";
+		String sqlQuery = StringUtils.normalizeSpace("INSERT INTO listeners (blabber, listener, status) values (?, ?, 'Active');");
 		logger.info(sqlQuery);
 		PreparedStatement action;
 		try {
@@ -41,10 +43,13 @@
 			result.next();
 
 			/* START EXAMPLE VULNERABILITY */
-			String event = username + " started listening to " + blabberUsername + " (" + result.getString(1) + ")";
+			String event = username + " started listening to " + blabberUsername + " (" + URLEncoder.encode(result.getString(1).toString()) + ")";
 			sqlQuery = "INSERT INTO users_history (blabber, event) VALUES (\"" + username + "\", \"" + event + "\")";
 			logger.info(sqlQuery);
-			sqlStatement.execute(sqlQuery);
+			PreparedStatement sqlStatement = connect.prepareStatement(sqlQuery);
+			sqlStatement.setString(1, username);
+			sqlStatement.setString(2, event);
+			sqlStatement.execute();
 			/* END EXAMPLE VULNERABILITY */
 		} catch (SQLException e) {
 			// TODO Auto-generated catch block

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/java/com/veracode/verademo/commands/RemoveAccountCommand.java:
Falws found for this file:
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 42 for issue 1019
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 40 for issue 1035
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 52 for issue 1079
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 48 for issue 1094
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 49 for issue 1012
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 53 for issue 1013
CWE 89 - Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - Severity 4 on line 42 for issue 1016
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 41 for issue 1096

Fix suggestions:

--- test/src/main/java/com/veracode/verademo/commands/RemoveAccountCommand.java
+++ test/src/main/java/com/veracode/verademo/commands/RemoveAccountCommand.java
@@ -8,6 +8,9 @@
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.commons.lang3.StringUtils;
+import java.net.URLEncoder;
+import java.util.*;
 
 public class RemoveAccountCommand implements BlabberCommand {
 	private static final Logger logger = LogManager.getLogger("VeraDemo:RemoveAccountCommand");
@@ -26,7 +29,7 @@
 	 */
 	@Override
 	public void execute(String blabberUsername) {
-		String sqlQuery = "DELETE FROM listeners WHERE blabber=? OR listener=?;";
+		String sqlQuery = StringUtils.normalizeSpace("DELETE FROM listeners WHERE blabber=? OR listener=?;");
 		logger.info(sqlQuery);
 		PreparedStatement action;
 		try {
@@ -43,14 +46,18 @@
 			result.next();
 
 			/* START EXAMPLE VULNERABILITY */
-			String event = "Removed account for blabber " + result.getString(1);
+			Set<String> whitelistResultGetstring1 = new HashSet<>(Arrays.asList("item1", "item2", "item3"));
+			if (!result.getString(1).matches("\\w+(\\s*\\.\\s*\\w+)*") && !whitelistResultGetstring1.contains(result.getString(1)))
+			    throw new IllegalArgumentException();
+			String event = "Removed account for blabber " + URLEncoder.encode(result.getString(1).toString());
 			sqlQuery = "INSERT INTO users_history (blabber, event) VALUES ('" + blabberUsername + "', '" + event + "')";
 			logger.info(sqlQuery);
 			sqlStatement.execute(sqlQuery);
 
 			sqlQuery = "DELETE FROM users WHERE username = '" + blabberUsername + "'";
 			logger.info(sqlQuery);
-			sqlStatement.execute(sqlQuery);
+			PreparedStatement sqlStatement2 = conn.prepareStatement(sqlQuery);
+			sqlStatement2.execute();
 			/* END EXAMPLE VULNERABILITY */
 
 		} catch (SQLException e) {

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/webapp/WEB-INF/views/tools.jsp:
Falws found for this file:
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 67 for issue 1153
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 64 for issue 1134
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 77 for issue 1154

Fix suggestions:

--- test/src/main/webapp/WEB-INF/views/tools.jsp
+++ test/src/main/webapp/WEB-INF/views/tools.jsp
@@ -61,7 +61,7 @@
 			<form method="post">
 				<label for="host">Host:</label> <input type="text" name="host"
 					<%if (request.getParameter("host") != null) {%>
-					value="<%=request.getParameter("host")%>" <%}%> /> <input
+					value="<%=request.getParameter("host")%>" <%}%> /> <inputvalue="<%=ESAPI.encoder().encodeForHTMLAttribute(request.getParameter("host"))%>					value="<%=request.getParameter("host")%>" <%}%> /> <input
 					type="submit" value="Check" />
 			</form>
 			<pre>${ping}</pre>

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/webapp/WEB-INF/views/blabbers.jsp:
Falws found for this file:
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 100 for issue 1132
CWE 80 - Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) - Severity 3 on line 103 for issue 1145

Fix suggestions:

--- test/src/main/webapp/WEB-INF/views/blabbers.jsp
+++ test/src/main/webapp/WEB-INF/views/blabbers.jsp
@@ -97,10 +97,10 @@
 								%>
 								<tr>
 									<td class="commenterImage">
-										<img src="resources/images/<%= blabber.getUsername() %>.png" />
+										<img src="resources/images/<%= blabber.getUsername() %>.png" /><%= ESAPI.encoder().encodeForHTMLAttribute(blabber.getBlabName()) %>										<img src="resources/images/<%= blabber.getUsername() %>.png" />
 									</td>
 									<td class="commenterName">
-										<%= blabber.getBlabName() %>
+										<%= blabber.getBlabName() %><%= ESAPI.encoder().encodeForHTMLAttribute(blabber.getBlabName()) %>										<%= blabber.getBlabName() %>
 									</td>
 									<td class="commenterJoinDate">
 										<%= blabber.getCreatedDateString() %>

Copy link

Caution

Breaking Flaws identified in code!

Fixes for test/src/main/java/com/veracode/verademo/controller/ToolsController.java:
Falws found for this file:
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 88 for issue 1031
CWE 117 - Improper Output Neutralization for Logs - Severity 3 on line 49 for issue 1091
CWE 404 - Improper Resource Shutdown or Release - Severity 0 on line 58 for issue 1032

Fix suggestions:

--- test/src/main/java/com/veracode/verademo/controller/ToolsController.java
+++ test/src/main/java/com/veracode/verademo/controller/ToolsController.java
@@ -16,6 +16,7 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.apache.commons.lang3.StringUtils;
 
 @Controller
 @Scope("request")
@@ -46,7 +47,7 @@
 		String output = "";
 		Process proc;
 
-		logger.info("Pinging: " + host);
+		logger.info("Pinging: " + StringUtils.normalizeSpace(host));
 
 		try {
 			/* START EXAMPLE VULNERABILITY */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant