Skip to content

Validate JDBC connection URLs and properties across database plugins and connectors - #690

Draft
bhardwaj-priyanshu wants to merge 1 commit into
data-integrations:developfrom
bhardwaj-priyanshu:fix/jdbc-connection-property-validation
Draft

bhardwaj-priyanshu wants to merge 1 commit into
data-integrations:developfrom
bhardwaj-priyanshu:fix/jdbc-connection-property-validation

Conversation

@bhardwaj-priyanshu

Copy link
Copy Markdown

Summary

  • Add JdbcConnectionValidator in database-commons to validate JDBC connection URLs and Properties / connection arguments against disallowed subprotocols, remote schemes, dangerous driver parameters, and encoding/comment bypasses (while preserving official CloudSQL MySQL and PostgreSQL SocketFactory classes in URLs).
  • Enforce validation in JDBCDriverShim, DBUtils.ensureJDBCDriverIsAvailable, DBUtils.validateJDBCPluginPipeline, RetryUtils.createConnectionWithRetry, ConnectionConfig, ConnectionConfigAccessor, AbstractDBSpecificSourceConfig, AbstractDBSpecificSinkConfig, AbstractDBConnectorConfig, AbstractDBSpecificConnector, DataDrivenETLDBInputFormat, and ETLDBOutputFormat.
  • Add unit tests in JdbcConnectionValidatorTest, DBConfigTest, PostgresFailedConnectionTest, and MysqlFailedConnectionTest.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +44 to +48
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"
)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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"
)));

Comment on lines +144 to +146
"javax.naming.provider.url",
"java.naming.provider.url",
"java.naming.factory.initial",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

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.

Suggested change
"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",

Comment on lines +196 to +198
"../",
"/..",
"..\\",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
"../",
"/..",
"..\\",
"../",
"/..",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant