Skip to content

Commit

Permalink
Use Prepared Statement For SQL
Browse files Browse the repository at this point in the history
To prevent SQL injection through UserID.
  • Loading branch information
AvocadoMoon committed May 29, 2024
1 parent ee14e6c commit 54259bd
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions vcell-server/src/main/java/cbit/vcell/modeldb/UserDbDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@

import java.math.BigDecimal;
import java.security.SecureRandom;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -58,7 +55,7 @@ public UserDbDriver() {


public User.SpecialUser getUserFromUserid(Connection con, String userid) throws SQLException {
Statement stmt;
PreparedStatement pstmt;
String sql;
ResultSet rset;
if (lg.isTraceEnabled()) {
Expand All @@ -68,16 +65,17 @@ public User.SpecialUser getUserFromUserid(Connection con, String userid) throws
" FROM " + userTable.getTableName() +
" LEFT JOIN " + SpecialUsersTable.table.getTableName() +
" ON " + SpecialUsersTable.table.userRef.getQualifiedColName()+"="+userTable.id.getQualifiedColName() +
" WHERE " + UserTable.table.userid + " = '" + userid + "'";
" WHERE " + UserTable.table.userid + " = ?";

if (lg.isTraceEnabled()) {
lg.trace(sql);
}
stmt = con.createStatement();
pstmt = con.prepareStatement(sql);
pstmt.setString(1, userid);
BigDecimal userKey = null;
ArrayList<User.SPECIAL_CLAIM> specials = new ArrayList<>();
try {
rset = stmt.executeQuery(sql);
rset = pstmt.executeQuery();
while (rset.next()) {
BigDecimal bigDecimal = rset.getBigDecimal("userkey");
if(userKey == null) {
Expand All @@ -96,7 +94,7 @@ public User.SpecialUser getUserFromUserid(Connection con, String userid) throws
}
}
} finally {
stmt.close();
pstmt.close();
}
if(userKey == null) {
return null;
Expand Down

0 comments on commit 54259bd

Please sign in to comment.