fix: 修复SQL注入漏洞

This commit is contained in:
taojinlong 2024-03-22 15:51:04 +08:00
parent 49555ab90f
commit 65dd5eb9f8
2 changed files with 8 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
@ -28,7 +29,9 @@ public class H2EngineProvider extends EngineProvider {
CoreDatasource datasource = new CoreDatasource();
BeanUtils.copyBean(datasource, engineRequest.getEngine());
try (Connection connection = getConnection(datasource); Statement stat = getStatement(connection, queryTimeout)) {
Boolean result = stat.execute(engineRequest.getQuery());
PreparedStatement preparedStatement = connection.prepareStatement(engineRequest.getQuery());
preparedStatement.setQueryTimeout(queryTimeout);
Boolean result = preparedStatement.execute();
} catch (Exception e) {
throw e;
}

View File

@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
@ -32,7 +33,9 @@ public class MysqlEngineProvider extends EngineProvider {
CoreDatasource datasource = new CoreDatasource();
BeanUtils.copyBean(datasource, engineRequest.getEngine());
try (Connection connection = getConnection(datasource); Statement stat = getStatement(connection, queryTimeout)) {
Boolean result = stat.execute(engineRequest.getQuery());
PreparedStatement preparedStatement = connection.prepareStatement(engineRequest.getQuery());
preparedStatement.setQueryTimeout(queryTimeout);
Boolean result = preparedStatement.execute();
} catch (Exception e) {
throw e;
}