CVE-2016-15021 (Java, published 2023-01-17T16:15Z)
Description: value: A vulnerability was found in nickzren alsdb. It has been rated as critical. This issue affects some unknown processing. The manipulation leads to sql injection. Upgrading to version v2 is able to address this issue. The identifier of the patch is cbc79a68145e845f951113d184b4de207c341599. It is recommended to upgrade the affected component. The identifier VDB-218429 was assigned to this vulnerability.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
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.
Repository: https://github.com/nickzren/alsdb
Files changed:
src/main/java/model/Input.java
src/main/java/model/Output.java
src/main/java/object/Variant.java
src/main/java/util/DBManager.java
Commit message: fixed sql injection vulnerability


Vulnerable code:
        String sql = "SELECT * "
                + "FROM gene_region "
                + "WHERE gene_name='" + geneName + "'";
        ResultSet rset = DBManager.executeQuery(sql);
        String sql = "SELECT * "
                + "FROM rvis "
                + "WHERE gene_name='" + geneName + "'";
        ResultSet rset = DBManager.executeQuery(sql);
                + "WHERE chr='" + tmp[0] + "' "
                + "AND pos=" + tmp[1] + " "
                + "AND ref='" + tmp[2] + "' "
                + "AND allele='" + tmp[3] + "'";

        ResultSet rset = DBManager.executeQuery(sql);
                + "WHERE variant_id = " + id + " "
        ResultSet rset = DBManager.executeQuery(sql);

Fixed code:
import java.sql.PreparedStatement;
        String sql = "SELECT * FROM gene_region WHERE gene_name=?";
        PreparedStatement stmt = DBManager.prepareStatement(sql);
        stmt.setString(1, geneName);
        ResultSet rset = stmt.executeQuery();
        String sql = "SELECT * FROM rvis WHERE gene_name=?";
        PreparedStatement stmt = DBManager.prepareStatement(sql);
        stmt.setString(1, geneName);
        ResultSet rset = stmt.executeQuery();
import java.sql.PreparedStatement;
                + "WHERE chr= ? AND pos= ? AND ref= ? AND allele= ?";

        PreparedStatement stmt = DBManager.prepareStatement(sql);
        stmt.setString(1, tmp[0]);
        stmt.setInt(2, Integer.valueOf(tmp[1]));
        stmt.setString(3, tmp[2]);
        stmt.setString(4, tmp[3]);
        ResultSet rset = stmt.executeQuery();
import java.sql.PreparedStatement;
                + "WHERE variant_id = ? "
        PreparedStatement stmt = DBManager.prepareStatement(sql);
        stmt.setInt(1, id);
        ResultSet rset = stmt.executeQuery();
    
    public static PreparedStatement prepareStatement(String sqlQuery) throws SQLException{
        return connection.prepareStatement(sqlQuery);
    }