Skip to content

Conversation

@gopalldb
Copy link
Collaborator

Summary

Implements a comprehensive JDBC URL sanitizer to prevent accidental exposure of sensitive credentials (passwords, tokens, secrets) in log files and exception messages.

Changes

  • Created SecurityUtil class with sanitizeJdbcUrl() method that redacts all sensitive parameters
  • Updated exception messages in Driver.java and DatabricksConnectionContext.java to sanitize URLs
  • Updated test files (LoggingTest.java, SSLTest.java) to use sanitizer as best practice
  • Added comprehensive unit tests - 20 tests covering all credential types and edge cases

Sensitive Parameters Covered

The sanitizer redacts 15+ credential types from DatabricksJdbcUrlParams:

  • PASSWORD, PWD
  • CLIENT_SECRET, OAUTH2SECRET
  • AUTH_ACCESS_TOKEN
  • AUTH_REFRESH_TOKEN, OAUTH_REFRESH_TOKEN
  • PROXY_PWD, CF_PROXY_PWD
  • PROXY_USER, PROXY_UID, CF_PROXY_UID
  • JWT_PASS_PHRASE, AUTH_JWT_KEY_PASSPHRASE
  • SSL_TRUST_STORE_PASSWORD, SSL_KEY_STORE_PASSWORD
  • TOKEN_CACHE_PASS_PHRASE
  • UID

Test Results

All 20 unit tests pass successfully:

Tests run: 20, Failures: 0, Errors: 0, Skipped: 0

Example

Before:

jdbc:databricks://host:443/default;PWD=secret123;UID=user@example.com;HttpPath=/sql/1.0

After:

jdbc:databricks://host:443/default;PWD=***REDACTED***;UID=***REDACTED***;HttpPath=/sql/1.0

🤖 Generated with Claude Code

gopalldb and others added 2 commits December 11, 2025 21:36
Implements SecurityUtil.sanitizeJdbcUrl() to redact sensitive parameters
(passwords, tokens, secrets, etc.) from JDBC URLs before logging or
including them in exception messages.

Changes:
- Created SecurityUtil class with comprehensive pattern matching for all
  sensitive parameters from DatabricksJdbcUrlParams (15+ credential types)
- Updated Driver.java exception messages to sanitize URLs
- Updated DatabricksConnectionContext.java exception messages to sanitize URLs
- Updated test files (LoggingTest.java, SSLTest.java) to use sanitizer
- Added 20 comprehensive unit tests in SecurityUtilTest

All sensitive parameters are redacted including: PASSWORD, PWD, CLIENT_SECRET,
AUTH_ACCESS_TOKEN, OAUTH_REFRESH_TOKEN, PROXY credentials, JWT passphrases,
SSL store passwords, TOKEN_CACHE_PASS_PHRASE, and UID.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
UID is an identifier (like CLIENT_ID) rather than a secret credential.
Keeping it visible in logs helps with debugging while still protecting
truly sensitive data (passwords, tokens, secrets).

Changes:
- Removed UID from CREDENTIAL_PATTERN regex
- Updated isCredentialParameter() to not treat UID as sensitive
- Updated all tests to verify UID is preserved in sanitized URLs
- All 20 tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
+ "|CLIENT_?SECRET|OAUTH2SECRET"
+ "|AUTH_?ACCESS_?TOKEN"
+ "|AUTH_?REFRESH_?TOKEN|OAUTH_?REFRESH_?TOKEN"
+ "|PROXY_?PWD|CF_?PROXY_?PWD"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we limit to actual values in URL params, for ex: there is no proxy_pwd, only proxypwd. similar for other like truststore/keystore where the key is SSLTrustStorePwd but we check for underscores, full form of password etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

* @param parameterName the parameter name to check, case-insensitive
* @return true if the parameter represents a credential, false otherwise
*/
public static boolean isCredentialParameter(String parameterName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like this is not used anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

…ed method

- Use exact JDBC parameter names from DatabricksJdbcUrlParams (no wildcards)
  - password, pwd, OAuth2Secret, Auth_AccessToken, Auth_RefreshToken,
    OAuthRefreshToken, proxyuid, proxypwd, cfproxyuid, cfproxypwd,
    Auth_JWT_Key_Passphrase, SSLTrustStorePwd, SSLKeyStorePwd, TokenCachePassPhrase
- Remove unused isCredentialParameter() method (only used in tests)
- Remove corresponding test for removed method
- Keep UID unredacted (it's an identifier, not a secret)
- All 19 tests passing

Addresses comments from @vikrantpuppala
+ "|Auth_JWT_Key_Passphrase"
+ "|SSLTrustStorePwd|SSLKeyStorePwd"
+ "|TokenCachePassPhrase"
+ ")=[^;&]*",
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use the enums to build this pattern matching string so that we do not have to make changes at multiple places?

Copy link
Collaborator

Choose a reason for hiding this comment

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

how can we also further ensure that folks add newer connection params containing credentials to this list?


private SecurityUtil() {
// Utility class, prevent instantiation
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this?

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.

2 participants