Mask credentials embedded in JDBC URL authority - #2416
Open
fudianchn wants to merge 1 commit into
Open
Conversation
fudianchn
force-pushed
the
mask-url-authority-credentials
branch
from
August 13, 2026 02:59
d427b9a to
dea2c2c
Compare
maskPasswordInJdbcUrl() only masked the password query parameter (e.g. ?password=secret) but missed credentials embedded in the URL authority (e.g. jdbc:postgresql://user:password@host), which were logged verbatim at DEBUG level via HikariConfig.logConfiguration(). Add a second pattern that masks the secret following the first colon of the userinfo, while preserving the username and host:port for log readability. The query-parameter masking behaviour is unchanged. Fixes brettwooldridge#2413 Signed-off-by: 付典 <fudianchn@gmail.com>
fudianchn
force-pushed
the
mask-url-authority-credentials
branch
from
August 15, 2026 15:16
dea2c2c to
6cdeed7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.
Problem
UtilityElf.maskPasswordInJdbcUrl()only masks the password query parameter (?password=secret), but misses credentials embedded in the URL authority (user:password@host):The existing pattern
([?&;][^&#;=]*[pP]password=)[^&#;]*requires a leading?,&, or;delimiter, so the userinfo password is never matched and is logged verbatim at DEBUG level viaHikariConfig.logConfiguration()(andDriverDataSource). Reported in #2413.Fix
Add a second pattern that masks the secret following the first colon of the userinfo, anchored on
://and terminated by@:admin:s3cret@→admin:<masked>@), consistent with the existing query-parameter masking that keeps thepassword=key and masks only the value.host:portwithout userinfo is not touched: the password component is delimited by the RFC 3986 reserved delimiters/,?,#,@, so://host:5432never matches and a query value containing an at-sign (e.g.jdbc:mysql://host:3306/db?user=admin@corp.com, common for cloud databases with e-mail-style usernames) is never swallowed.://:password@host) is masked as well./,?,#or a second@(all invalid unencoded per RFC 3986) cannot be told apart from path/query content by a regex over the URL string and are therefore left unmasked; percent-encode them (%2F,%3F,%23,%40) and they are masked. A URI-parsing approach could resolve the ambiguity, at the cost of rejecting the non-standard JDBC URL schemes; kept the regex for consistency with the existing query-parameter masking.Verification
UtilityElfTestnow covers: query-param regression, authority masking, both combined, port preservation, no false mask without userinfo, at-sign-in-query not swallowed, empty username masked, first-colon convention, and the reserved-delimiter boundary. Local run (JDK 21, JaCoCo skipped, 0.8.8 predates JDK 21): 14/14 tests pass.Alternative considered
Mask the entire userinfo (
user:pass@→<masked>@) for maximal secrecy. I kept the username visible to stay consistent with the existing "mask the secret, keep the structure" behaviour and to preserve useful logging context. Happy to switch to full userinfo masking if that's preferred.Related: #2415
#2415 addresses the same issue with a nearly identical approach (second regex chained after the existing query-parameter mask). Both PRs use
[^@]+for the password segment. The remaining differences are minor:://; fix: mask authority-embedded passwords in JDBC URLs #2415 uses//.?#(RFC 3986 gen-delimiters, not valid in userinfo); fix: mask authority-embedded passwords in JDBC URLs #2415 allows them.UtilityElfTest; fix: mask authority-embedded passwords in JDBC URLs #2415 adds 4 unit cases plus an integration test inHikariConfigTest.Happy to defer to the maintainer on which to merge.
Fixes #2413.