Skip to content

Comments

feat(jdbc): enforce strict JDBC URL parsing and sync DataSource properties#4107

Open
keshavdandeva wants to merge 12 commits intomainfrom
jdbc/feat-strict-url-parse-and-sync-dataSource
Open

feat(jdbc): enforce strict JDBC URL parsing and sync DataSource properties#4107
keshavdandeva wants to merge 12 commits intomainfrom
jdbc/feat-strict-url-parse-and-sync-dataSource

Conversation

@keshavdandeva
Copy link
Contributor

b/429272203

This PR refactors the JDBC connection string parsing logic to be stricter and more robust, preventing silent failures due to typos. It also synchronizes DataSource properties with BigQueryConnection to ensure full feature parity.

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigquery Issues related to the googleapis/java-bigquery API. labels Feb 17, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @keshavdandeva, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the BigQuery JDBC driver by implementing stricter URL parsing to prevent configuration errors and by aligning the DataSource class with the full range of BigQueryConnection properties. These changes improve the robustness and feature parity of the driver, ensuring more reliable connection handling and configuration.

Highlights

  • Stricter JDBC URL Parsing: Implemented strict validation for JDBC connection URL properties, throwing exceptions for unknown or malformed entries, preventing silent failures due to typos.
  • DataSource Property Synchronization: Synchronized DataSource properties to match BigQueryConnection, adding support for labels, request reasons, various timeouts, maximum billed bytes, and SWA row counts.
  • Refactored URL Parsing Logic: Refactored URL parsing logic in BigQueryJdbcUrlUtility to use a centralized map for property validation and improved handling of PartnerToken.
  • Improved Error Reporting: Introduced BigQueryJdbcRuntimeException for specific URL parsing errors, ensuring clearer and more consistent error reporting.
Changelog
  • google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDriver.java
    • Imported BigQueryJdbcRuntimeException.
    • Added a try-catch block around URL parsing to convert BigQueryJdbcRuntimeException to BigQueryJdbcException.
  • google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java
    • Defined a PARTNER_TOKEN_PATTERN regex for more robust parsing.
    • Created PROPERTY_NAME_MAP to hold all valid connection property names for strict validation.
    • Rewrote parseUriProperty to leverage the new parseUrl method.
    • Implemented parseUrl to strictly parse and validate all URL properties, throwing an exception for unknown properties.
    • Refactored parsePartnerTokenProperty to use a new helper method that also removes the token from the URL string builder.
  • google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/DataSource.java
    • Added new fields for labels, requestReason, timeout, jobTimeout, retryInitialDelay, retryMaxDelay, httpConnectTimeout, httpReadTimeout, maximumBytesBilled, swaActivationRowCount, and swaAppendRowCount.
    • Updated createProperties to include these new properties in the connection properties.
    • Added corresponding getter and setter methods for all newly introduced properties.
  • google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java
    • Added new test cases to verify that parseUrl throws BigQueryJdbcRuntimeException for unknown properties and typos.
    • Updated existing tests to use more specific and relevant property names for multiline and integer parsing tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 enhances the robustness of JDBC URL parsing through stricter validation, refactored logic, and synchronization of DataSource properties. However, the new parsing logic introduces a connection string injection vulnerability due to unescaped delimiters in property values and insufficient validation for sensitive properties like LogPath. This flaw could enable path traversal or the overriding of security-sensitive connection settings. It is recommended to implement proper escaping for property values and add validation for security-critical properties during URL parsing.

@keshavdandeva
Copy link
Contributor Author

/gemini review

Copy link
Contributor

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

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 significantly improves the JDBC driver's connection string parsing by introducing stricter validation for property names, preventing silent failures, and correctly URL-encoding property values. It also synchronizes DataSource properties with BigQueryConnection for enhanced feature parity. However, a potential information exposure vulnerability exists: the parseUrl method could leak sensitive data in SQLException messages if a secret is accidentally provided as a property key, as the raw key is included in error messages. Additionally, there is a minor suggestion to reduce code duplication.

@keshavdandeva keshavdandeva marked this pull request as ready for review February 18, 2026 13:42
@keshavdandeva keshavdandeva requested review from a team as code owners February 18, 2026 13:42
try {
BigQueryJdbcUrlUtility.parseUrl(connectionUri);
} catch (BigQueryJdbcRuntimeException e) {
throw new BigQueryJdbcException(e.getMessage(), e);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason to wrap BigQueryJdbcRuntimeException with BigQueryJdbcException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the JDBC spec required the connect() method to throw SQLException for connection failures and BigQueryJdbcException extends SQLException

private Integer metadataFetchThreadCount;
private String sslTrustStorePath;
private String sslTrustStorePassword;
private String labels;
Copy link
Contributor

Choose a reason for hiding this comment

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

labels supposed to be Map<String, String>, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Also, I realised for properties like labels and queryProperties we needed to serialize maps

}
String[] kv = part.split("=", 2);
String key = kv[0].trim();
if (kv.length == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That seems easier to read?

String key = kv[0].trim().toUpperCase();
if (kv.length != 2 || !PROPERTY_NAME_MAP.containsKey(key) ) {
  throw new BigQueryJdbcRuntimeException(String.format("Wrong value or unknown setting found in connection string: %s", part.substring(0, Math.min(part.length(), 12)))
}

String value = kv[1].trim();
map.put(key, CharEscapers.decodeUriPath(value));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adopted your suggestion but with modified error handling. I kept it to log the key if available (truncated to 32 chars) or the truncated part only if the property is malformed.

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

Labels

api: bigquery Issues related to the googleapis/java-bigquery API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants