Skip to content

Commit e65b543

Browse files
authored
[ZEPPELIN-5990] Disable sensitive configuration for JDBC url (#4709)
* [ZEPPELIN-5990] Disable sensitive configuration for JDBC url * [ZEPPELIN-5990] Disable sensitive configuration for JDBC url
1 parent 01231e6 commit e65b543

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ public class JDBCInterpreter extends KerberosInterpreter {
153153
"KerberosConfigPath", "KerberosKeytabPath", "KerberosCredentialCachePath",
154154
"extraCredentials", "roles", "sessionProperties"));
155155

156+
private static final String ALLOW_LOAD_LOCAL_IN_FILE_NAME = "allowLoadLocalInfile";
157+
158+
private static final String AUTO_DESERIALIZE = "autoDeserialize";
159+
160+
private static final String ALLOW_LOCAL_IN_FILE_NAME = "allowLocalInfile";
161+
162+
private static final String ALLOW_URL_IN_LOCAL_IN_FILE_NAME = "allowUrlInLocalInfile";
163+
156164
// database --> Properties
157165
private final HashMap<String, Properties> basePropertiesMap;
158166
// username --> User Configuration
@@ -533,6 +541,7 @@ public Connection getConnection(InterpreterContext context)
533541
String url = properties.getProperty(URL_KEY);
534542
url = appendProxyUserToURL(url, user);
535543
String connectionUrl = appendTagsToURL(url, context);
544+
validateConnectionUrl(connectionUrl);
536545

537546
String authType = getProperty("zeppelin.jdbc.auth.type", "SIMPLE")
538547
.trim().toUpperCase();
@@ -576,6 +585,15 @@ public Connection getConnection(InterpreterContext context)
576585
return connection;
577586
}
578587

588+
private void validateConnectionUrl(String url) {
589+
if (containsIgnoreCase(url, ALLOW_LOAD_LOCAL_IN_FILE_NAME) ||
590+
containsIgnoreCase(url, AUTO_DESERIALIZE) ||
591+
containsIgnoreCase(url, ALLOW_LOCAL_IN_FILE_NAME) ||
592+
containsIgnoreCase(url, ALLOW_URL_IN_LOCAL_IN_FILE_NAME)) {
593+
throw new IllegalArgumentException("Connection URL contains sensitive configuration");
594+
}
595+
}
596+
579597
private String appendProxyUserToURL(String url, String user) {
580598
StringBuilder connectionUrl = new StringBuilder(url);
581599

@@ -749,6 +767,9 @@ private InterpreterResult executeSql(String sql,
749767

750768
try {
751769
connection = getConnection(context);
770+
} catch (IllegalArgumentException e) {
771+
LOGGER.error("Cannot run " + sql, e);
772+
return new InterpreterResult(Code.ERROR, "Connection URL contains improper configuration");
752773
} catch (Exception e) {
753774
LOGGER.error("Fail to getConnection", e);
754775
try {
@@ -763,7 +784,7 @@ private InterpreterResult executeSql(String sql,
763784
}
764785
}
765786
if (connection == null) {
766-
return new InterpreterResult(Code.ERROR, "User's connectin not found.");
787+
return new InterpreterResult(Code.ERROR, "User's connection not found.");
767788
}
768789

769790
try {

jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,21 @@ void testSplitSqlQueryWithComments() throws IOException,
747747
assertEquals(3, resultMessages.size());
748748
}
749749

750+
@Test
751+
void testValidateConnectionUrl() throws IOException, InterpreterException {
752+
Properties properties = new Properties();
753+
properties.setProperty("default.driver", "org.h2.Driver");
754+
properties.setProperty("default.url", getJdbcConnection() + ";allowLoadLocalInfile=true");
755+
properties.setProperty("default.user", "");
756+
properties.setProperty("default.password", "");
757+
JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
758+
jdbcInterpreter.open();
759+
InterpreterResult interpreterResult = jdbcInterpreter.interpret("SELECT 1", context);
760+
assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
761+
assertEquals("Connection URL contains improper configuration",
762+
interpreterResult.message().get(0).getData());
763+
}
764+
750765
private InterpreterContext getInterpreterContext() {
751766
return InterpreterContext.builder()
752767
.setAuthenticationInfo(new AuthenticationInfo("testUser"))

0 commit comments

Comments
 (0)