-
Notifications
You must be signed in to change notification settings - Fork 27
Add JDBC URL sanitizer to prevent credential exposure in logs #1136
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
base: main
Are you sure you want to change the base?
Conversation
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" |
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.
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.
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.
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) { |
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.
looks like this is not used anywhere?
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.
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" | ||
| + ")=[^;&]*", |
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.
can we use the enums to build this pattern matching string so that we do not have to make changes at multiple places?
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.
how can we also further ensure that folks add newer connection params containing credentials to this list?
|
|
||
| private SecurityUtil() { | ||
| // Utility class, prevent instantiation | ||
| } |
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.
do we need this?
Summary
Implements a comprehensive JDBC URL sanitizer to prevent accidental exposure of sensitive credentials (passwords, tokens, secrets) in log files and exception messages.
Changes
sanitizeJdbcUrl()method that redacts all sensitive parametersSensitive Parameters Covered
The sanitizer redacts 15+ credential types from DatabricksJdbcUrlParams:
Test Results
All 20 unit tests pass successfully:
Example
Before:
After:
🤖 Generated with Claude Code