Skip to content

Commit

Permalink
[Hotfix] Fix arbitrary file readvulnerability on mysql jdbc(starrocks…
Browse files Browse the repository at this point in the history
  • Loading branch information
hailin0 committed Jun 12, 2024
1 parent 4a37ebf commit 3768a38
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import static com.google.common.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -169,11 +170,15 @@ private Connection getConnection(Map<String, String> requestParams, String datab
String url =
JdbcUtils.replaceDatabase(
requestParams.get(StarRocksOptionRule.URL.key()), databaseName);

Properties info = new java.util.Properties();
info.put("autoDeserialize", "false");
info.put("allowLoadLocalInfile", "false");
info.put("allowLoadLocalInfileInPath", "");
if (requestParams.containsKey(StarRocksOptionRule.USER.key())) {
String username = requestParams.get(StarRocksOptionRule.USER.key());
String password = requestParams.get(StarRocksOptionRule.PASSWORD.key());
return DriverManager.getConnection(url, username, password);
info.put("user", requestParams.get(StarRocksOptionRule.USER.key()));
info.put("password", requestParams.get(StarRocksOptionRule.PASSWORD.key()));
}
return DriverManager.getConnection(url);
return DriverManager.getConnection(url, info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -176,11 +177,14 @@ private Connection getConnection(Map<String, String> requestParams, String datab
String url =
JdbcUtils.replaceDatabase(
requestParams.get(TidbOptionRule.URL.key()), databaseName);
Properties info = new java.util.Properties();
info.put("autoDeserialize", "false");
info.put("allowLoadLocalInfile", "false");
info.put("allowLoadLocalInfileInPath", "");
if (requestParams.containsKey(TidbOptionRule.USER.key())) {
String username = requestParams.get(TidbOptionRule.USER.key());
String password = requestParams.get(TidbOptionRule.PASSWORD.key());
return DriverManager.getConnection(url, username, password);
info.put("user", requestParams.get(TidbOptionRule.USER.key()));
info.put("password", requestParams.get(TidbOptionRule.PASSWORD.key()));
}
return DriverManager.getConnection(url);
return DriverManager.getConnection(url, info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -79,7 +80,7 @@ public StarRocksCatalog(String catalogName, String username, String pwd, String

public List<String> listDatabases() throws CatalogException {
List<String> databases = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(defaultUrl, username, pwd);
try (Connection conn = getConnection(defaultUrl);
PreparedStatement ps = conn.prepareStatement("SHOW DATABASES;");
ResultSet rs = ps.executeQuery(); ) {

Expand All @@ -103,7 +104,7 @@ public List<String> listTables(String databaseName)
throw new DatabaseNotExistException(this.catalogName, databaseName);
}

try (Connection conn = DriverManager.getConnection(baseUrl + databaseName, username, pwd);
try (Connection conn = getConnection(baseUrl + databaseName);
PreparedStatement ps = conn.prepareStatement("SHOW TABLES;");
ResultSet rs = ps.executeQuery()) {

Expand All @@ -127,7 +128,7 @@ public List<TableField> getTable(TablePath tablePath)
}

String dbUrl = baseUrl + tablePath.getDatabaseName();
try (Connection conn = DriverManager.getConnection(dbUrl, username, pwd);
try (Connection conn = getConnection(dbUrl);
PreparedStatement statement =
conn.prepareStatement(
String.format(
Expand Down Expand Up @@ -178,7 +179,7 @@ public static String splitDefaultUrl(String defaultUrl) {
protected Optional<PrimaryKey> getPrimaryKey(String schema, String table) throws SQLException {

List<String> pkFields = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(defaultUrl, username, pwd);
try (Connection conn = getConnection(defaultUrl);
PreparedStatement statement =
conn.prepareStatement(
String.format(
Expand Down Expand Up @@ -222,4 +223,14 @@ public boolean tableExists(TablePath tablePath) throws CatalogException {
return false;
}
}

protected Connection getConnection(String url) throws SQLException {
Properties info = new java.util.Properties();
info.put("autoDeserialize", "false");
info.put("allowLoadLocalInfile", "false");
info.put("allowLoadLocalInfileInPath", "");
info.put("user", username);
info.put("password", pwd);
return DriverManager.getConnection(url, info);
}
}

0 comments on commit 3768a38

Please sign in to comment.