Repository navigation
Validate JDBC connection URLs and properties across database plugins and connectors - #690
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the JdbcConnectionValidator utility class to validate JDBC connection URLs and properties against security risks like JNDI injection, arbitrary file reads, and dangerous driver properties, integrating it across database connection and utility classes. The review feedback suggests adding the SQL Server Cloud SQL socket factory to the allowed list, blocking javax.naming.factory.initial for enhanced JNDI protection, and removing a redundant backslash directory traversal token due to path normalization.
| private static final Set<String> ALLOWED_CLOUDSQL_SOCKET_FACTORIES = | ||
| Collections.unmodifiableSet(new HashSet<>(Arrays.asList( | ||
| "com.google.cloud.sql.mysql.SocketFactory", | ||
| "com.google.cloud.sql.postgres.SocketFactory" | ||
| ))); |
There was a problem hiding this comment.
The list of allowed Cloud SQL socket factories is missing the official socket factory for SQL Server (com.google.cloud.sql.sqlserver.SocketFactory). If a user attempts to connect to a Google Cloud SQL Server instance using this socket factory, the connection will be blocked. Please add it to the allowed set.
| private static final Set<String> ALLOWED_CLOUDSQL_SOCKET_FACTORIES = | |
| Collections.unmodifiableSet(new HashSet<>(Arrays.asList( | |
| "com.google.cloud.sql.mysql.SocketFactory", | |
| "com.google.cloud.sql.postgres.SocketFactory" | |
| ))); | |
| private static final Set<String> ALLOWED_CLOUDSQL_SOCKET_FACTORIES = | |
| Collections.unmodifiableSet(new HashSet<>(Arrays.asList( | |
| "com.google.cloud.sql.mysql.SocketFactory", | |
| "com.google.cloud.sql.postgres.SocketFactory", | |
| "com.google.cloud.sql.sqlserver.SocketFactory" | |
| ))); |
| "javax.naming.provider.url", | ||
| "java.naming.provider.url", | ||
| "java.naming.factory.initial", |
There was a problem hiding this comment.
For completeness and defense-in-depth against JNDI injection, please also block javax.naming.factory.initial alongside java.naming.factory.initial and the provider URLs.
| "javax.naming.provider.url", | |
| "java.naming.provider.url", | |
| "java.naming.factory.initial", | |
| "javax.naming.provider.url", | |
| "java.naming.provider.url", | |
| "javax.naming.factory.initial", | |
| "java.naming.factory.initial", |
| "../", | ||
| "/..", | ||
| "..\\", |
There was a problem hiding this comment.
The token for backslash directory traversal is redundant because isSensitiveFilePath replaces all backslashes with forward slashes before performing the contains check. Any backslash-based directory traversal will be normalized to ../ and caught by the forward slash token. You can safely remove this redundant entry.
| "../", | |
| "/..", | |
| "..\\", | |
| "../", | |
| "/..", |
Summary
JdbcConnectionValidatorindatabase-commonsto validate JDBC connection URLs andProperties/ connection arguments against disallowed subprotocols, remote schemes, dangerous driver parameters, and encoding/comment bypasses (while preserving official CloudSQL MySQL and PostgreSQLSocketFactoryclasses in URLs).JDBCDriverShim,DBUtils.ensureJDBCDriverIsAvailable,DBUtils.validateJDBCPluginPipeline,RetryUtils.createConnectionWithRetry,ConnectionConfig,ConnectionConfigAccessor,AbstractDBSpecificSourceConfig,AbstractDBSpecificSinkConfig,AbstractDBConnectorConfig,AbstractDBSpecificConnector,DataDrivenETLDBInputFormat, andETLDBOutputFormat.JdbcConnectionValidatorTest,DBConfigTest,PostgresFailedConnectionTest, andMysqlFailedConnectionTest.