fix: 限制 clickhouse 非法参数

This commit is contained in:
an5er 2024-04-07 15:40:08 +08:00
parent 199c77d4ac
commit 7592defa39

View File

@ -11,14 +11,22 @@ public class CHConfiguration extends JdbcConfiguration {
private String driver = "ru.yandex.clickhouse.ClickHouseDriver";
private String extraParams = "";
private List<String> illegalParameters = Arrays.asList("localFile");
public String getJdbc() {
if(StringUtils.isEmpty(extraParams.trim())){
if (StringUtils.isEmpty(extraParams.trim())) {
return "jdbc:clickhouse://HOSTNAME:PORT/DATABASE"
.replace("HOSTNAME", getHost().trim())
.replace("PORT", getPort().toString().trim())
.replace("DATABASE", getDataBase().trim());
}else {
} else {
for (String illegalParameter : getIllegalParameters()) {
if (getExtraParams().toLowerCase().contains(illegalParameter.toLowerCase()) ||
URLDecoder.decode(getExtraParams()).toLowerCase().contains(illegalParameter.toLowerCase())) {
throw new RuntimeException("Illegal parameter: " + illegalParameter);
}
}
return "jdbc:clickhouse://HOSTNAME:PORT/DATABASE?EXTRA_PARAMS"
.replace("HOSTNAME", getHost().trim())
.replace("PORT", getPort().toString().trim())