-
Notifications
You must be signed in to change notification settings - Fork 134
fix(jdbc): avoid String.format in log calls #4096
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
Conversation
Summary of ChangesHello @logachev, 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 focuses on a significant performance optimization within the BigQuery JDBC driver's logging infrastructure. By transitioning from immediate string formatting to a deferred approach, the driver now avoids unnecessary string allocations for log messages that would not be displayed due to the current log level. This change enhances efficiency, particularly in environments with verbose logging configurations, ensuring that resources are only consumed when log output is genuinely required. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
99949c1 to
8d758f8
Compare
There was a problem hiding this 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 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)
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)
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)
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)
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);
8d758f8 to
4853e99
Compare
4853e99 to
cb6949b
Compare
|
/gemini review |
There was a problem hiding this 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 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.
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)