CVE-2013-10013: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability was found in Bricco Authenticator Plugin. It has been declared as critical. This vulnerability affects the function authenticate/compare of the file src/java/talentum/escenic/plugins/authenticator/authenticators/DBAuthenticator.java. The manipulation leads to sql injection. Upgrading to version 1.39 is able to address this issue. The name of the patch is a5456633ff75e8f13705974c7ed1ce77f3f142d5. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-218428.
CWE description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
CVSS v3 base score: 9.8
Published: 2023-01-17T16:15Z
Repository: https://github.com/Bricco/authenticator-plugin
Language: Java
Files changed: src/java/talentum/escenic/plugins/authenticator/authenticators/DBAuthenticator.java
Commit date: 2013-09-04 05:09:30 +0000
Commit message: Prevent SQL-injection

Diff: diff --git a/src/java/talentum/escenic/plugins/authenticator/authenticators/DBAuthenticator.java b/src/java/talentum/escenic/plugins/authenticator/authenticators/DBAuthenticator.java
index b160a36..6b611a6 100644
--- a/src/java/talentum/escenic/plugins/authenticator/authenticators/DBAuthenticator.java
+++ b/src/java/talentum/escenic/plugins/authenticator/authenticators/DBAuthenticator.java
@@ -1,13 +1,11 @@
 package talentum.escenic.plugins.authenticator.authenticators;
 
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -65,24 +63,20 @@ public class DBAuthenticator extends Authenticator {
 			throw new AuthenticationException(
 					"Authentication failed: Invalid arguments");
 		}
 		try {
 
+
 			ContentManager contentManager = ContentManager.getContentManager();
 			List result = new ArrayList();
 			String sql = "SELECT * FROM " + table + " WHERE "
 					+ columns.get("username") + "= ? AND "
-					+ columns.get("password") + "= '?'";
-			
-			String[] preparedVariables = new String[] {username, password};
-			
-			
-			
+					+ columns.get("password") + "= ?";
 			if(log.isDebugEnabled()) {
 				log.debug(sql);
 			}
-			contentManager.doQuery(new Query(sql, preparedVariables, result));
+			contentManager.doQuery(new Query(sql, new String[] { username, password },  result));
 			
 			if(log.isDebugEnabled()) {
 				log.debug("found " + result.size() + " records");
 			}
 			if(result.size() > 0) {
@@ -138,33 +132,34 @@ public class DBAuthenticator extends Authenticator {
 		};
 	}
 	
 	private static class Query implements TransactionOperation {
 		private String query;
+		private String[] args;
 		private List list;
-		private String[] variables;
 
-		public Query(String query, String[] variables, List list) {
+		public Query(String query, String[] args, List list) {
 			this.query = query;
-			this.variables = variables;
+			this.args = args;
 			this.list = list;
 		}
 
 		public void execute(Transaction t) throws SQLException {
-			//Statement st = t.getConnection().createStatement();
-			Statement st = t.getConnection().prepareStatement(query, variables);
+			PreparedStatement prepStmt = t.getConnection().prepareStatement(query);
+			prepStmt.setString(1, args[0]);
+			prepStmt.setString(2, args[1]);
 			try {
-				ResultSet rs = st.executeQuery(query);
+				ResultSet rs = prepStmt.executeQuery();
 				ResultSetMetaData metaData = rs.getMetaData();
 				while (rs.next()) {
 					Map map = new HashMap();
 					for (int i = 0; i < metaData.getColumnCount(); i++) {
 						map.put(metaData.getColumnLabel(i + 1), rs.getString(i + 1));
 					}
 					list.add(map);
 				}
 	        } finally {
-	            st.close();
+	        	prepStmt.close();
 	        }
 		}
 	}
 }
\ No newline at end of file

Vulnerable code: import java.sql.Connection;
import java.sql.Statement;
					+ columns.get("password") + "= '?'";
			
			String[] preparedVariables = new String[] {username, password};
			
			
			
			contentManager.doQuery(new Query(sql, preparedVariables, result));
		private String[] variables;
		public Query(String query, String[] variables, List list) {
			this.variables = variables;
			//Statement st = t.getConnection().createStatement();
			Statement st = t.getConnection().prepareStatement(query, variables);
				ResultSet rs = st.executeQuery(query);
	            st.close();
Fixed code: 
					+ columns.get("password") + "= ?";
			contentManager.doQuery(new Query(sql, new String[] { username, password },  result));
		private String[] args;
		public Query(String query, String[] args, List list) {
			this.args = args;
			PreparedStatement prepStmt = t.getConnection().prepareStatement(query);
			prepStmt.setString(1, args[0]);
			prepStmt.setString(2, args[1]);
				ResultSet rs = prepStmt.executeQuery();
	        	prepStmt.close();