fix(jdbc): avoid String.format in log calls by logachev · Pull Request #4096 · googleapis/java-bigquery · GitHub
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

fix(jdbc): avoid String.format in log calls#4096

Merged
logachev merged 4 commits into
mainfrom
kirl/format_logging
Feb 6, 2026
Merged

fix(jdbc): avoid String.format in log calls#4096
logachev merged 4 commits into
mainfrom
kirl/format_logging

Conversation

@logachev

@logachev logachev commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Add wrappers for log calls requiring String.format() to ensure it is not used directly but passed to the lambda instead.

Update all logging that was using System.format() to use new wrappers. I see some perf gains for both rest & read APIs (~10-15% rows/second, but would wait for internal perf framework runs to have a better idea)

@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 5, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

@logachev logachev force-pushed the kirl/format_logging branch from 99949c1 to 8d758f8 Compare February 5, 2026 21:02

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

Copy link
Copy Markdown
Contributor

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 aims to improve logging performance by avoiding unnecessary String.format calls and introducing new logger methods for lazy parameterized message handling. However, a critical security vulnerability has been identified: the driver logs sensitive data (including auth tokens, passwords, and query parameter values) at the INFO level, leading to high-severity sensitive data exposure. Additionally, a critical bug was introduced in BigQueryDatabaseMetaData.java where the schemaRegex variable was removed but is still referenced, which will cause a compilation error. Beyond these, the refactoring for String.format calls appears incomplete in BigQueryDatabaseMetaData.java, a functional change removed a null-check in the same file, and a typo was introduced in a log message in PooledConnectionListener.java.

I am having trouble creating individual review comments. Click here to see my feedback.

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java (604)

security-high high

The appendPropertiesToURL method logs all connection properties at the INFO level. These properties can include highly sensitive information such as OAuthAccessToken, OAuthRefreshToken, and ProxyPwd. Logging these secrets in plain text poses a significant security risk as they may be accessible to unauthorized individuals through log files or monitoring systems. It is recommended to change the log level to FINEST or implement a masking mechanism for sensitive keys.

        LOG.finest("Appending %s with value %s to URL", entry.getKey(), entry.getValue());

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryParameterHandler.java (62-64)

security-high high

The configureParameters method logs the values of all query parameters at the INFO level. If a query contains sensitive data (e.g., passwords, PII) as parameters, this information will be written to the logs in plain text. It is recommended to change the log level to FINEST to ensure these values are only logged when deep debugging is enabled, consistent with other parts of the driver.

        LOG.finest(
            "Parameter %s of type %s at index %s added to QueryJobConfiguration",
            parameterValue, sqlType, i);

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java (786-791)

high

This check for null/empty catalog and empty patterns was removed. This seems to be an unintended functional change as part of a logging refactoring. Other similar methods like getProcedureColumns retain this check. Removing it might lead to unexpected behavior or NullPointerExceptions if catalog is null and used later. Please consider if this removal was intentional.

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PooledConnectionListener.java (121)

medium

There appears to be a typo in this log message. 'dor:' should likely be 'due to error:'.

    LOG.finest("Removed pooled connection from connection pool due to error: %s", errorMessage);

@logachev logachev force-pushed the kirl/format_logging branch from 8d758f8 to 4853e99 Compare February 5, 2026 21:04
@logachev logachev force-pushed the kirl/format_logging branch from 4853e99 to cb6949b Compare February 5, 2026 21:10
@logachev

logachev commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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 aims to improve logging performance by removing explicit String.format calls and using deferred formatting. While this is a good practice, a critical security vulnerability was identified: sensitive information, including full connection URLs with credentials and query parameter values, is being logged. The most critical findings involve logging the full connection URL at fine and warning levels in BigQueryJdbcUrlUtility.java, which poses a significant security risk. Additionally, the implementation of new logging methods in BigQueryJdbcCustomLogger can be made more efficient, and there are still instances where string concatenation happens before the log call, and some String.format calls were missed during the refactoring.

@logachev logachev marked this pull request as ready for review February 5, 2026 22:03
@logachev logachev requested a review from a team February 5, 2026 22:03
@logachev logachev requested a review from a team as a code owner February 5, 2026 22:03
@logachev logachev added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 6, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 6, 2026
@logachev logachev merged commit ad438dc into main Feb 6, 2026
26 checks passed
@logachev logachev deleted the kirl/format_logging branch February 6, 2026 20:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

3 participants