Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ZEPPELIN-6095] validate decoded url in jdbc interpreter #4838

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.DriverManager;
Expand Down Expand Up @@ -587,10 +589,13 @@ public Connection getConnection(InterpreterContext context)
}

private void validateConnectionUrl(String url) {
if (containsIgnoreCase(url, ALLOW_LOAD_LOCAL_IN_FILE_NAME) ||
containsIgnoreCase(url, AUTO_DESERIALIZE) ||
containsIgnoreCase(url, ALLOW_LOCAL_IN_FILE_NAME) ||
containsIgnoreCase(url, ALLOW_URL_IN_LOCAL_IN_FILE_NAME)) {
String decodedUrl;
decodedUrl = URLDecoder.decode(url, StandardCharsets.UTF_8);

if (containsIgnoreCase(decodedUrl, ALLOW_LOAD_LOCAL_IN_FILE_NAME) ||
containsIgnoreCase(decodedUrl, AUTO_DESERIALIZE) ||
containsIgnoreCase(decodedUrl, ALLOW_LOCAL_IN_FILE_NAME) ||
containsIgnoreCase(decodedUrl, ALLOW_URL_IN_LOCAL_IN_FILE_NAME)) {
throw new IllegalArgumentException("Connection URL contains sensitive configuration");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,21 @@ void testValidateConnectionUrl() throws IOException, InterpreterException {
interpreterResult.message().get(0).getData());
}

@Test
void testValidateConnectionUrlEncoded() throws IOException, InterpreterException {
Properties properties = new Properties();
properties.setProperty("default.driver", "org.h2.Driver");
properties.setProperty("default.url", getJdbcConnection() + ";%61llowLoadLocalInfile=true");
properties.setProperty("default.user", "");
properties.setProperty("default.password", "");
JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
jdbcInterpreter.open();
InterpreterResult interpreterResult = jdbcInterpreter.interpret("SELECT 1", context);
assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
assertEquals("Connection URL contains improper configuration",
interpreterResult.message().get(0).getData());
}

private InterpreterContext getInterpreterContext() {
return InterpreterContext.builder()
.setAuthenticationInfo(new AuthenticationInfo("testUser"))
Expand Down
Loading