Skip to content

Commit

Permalink
Fixes #1136 sanitize jdbcUrl for logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwooldridge committed Apr 18, 2018
1 parent b363232 commit 95e0b42
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/zaxxer/hikari/util/DriverDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ public DriverDataSource(String jdbcUrl, String driverClassName, Properties prope
}
}

final String sanitizedUrl = jdbcUrl.replaceAll("([?&;]password=)[^&#;]*(.*)", "$1<masked>$2");
try {
if (driver == null) {
driver = DriverManager.getDriver(jdbcUrl);
LOGGER.debug("Loaded driver with class name {} for jdbcUrl={}", driver.getClass().getName(), jdbcUrl);
LOGGER.debug("Loaded driver with class name {} for jdbcUrl={}", driver.getClass().getName(), sanitizedUrl);
}
else if (!driver.acceptsURL(jdbcUrl)) {
throw new RuntimeException("Driver " + driverClassName + " claims to not accept jdbcUrl, " + jdbcUrl);
throw new RuntimeException("Driver " + driverClassName + " claims to not accept jdbcUrl, " + sanitizedUrl);
}
}
catch (SQLException e) {
throw new RuntimeException("Failed to get driver instance for jdbcUrl=" + jdbcUrl, e);
throw new RuntimeException("Failed to get driver instance for jdbcUrl=" + sanitizedUrl, e);
}
}

Expand Down

0 comments on commit 95e0b42

Please sign in to comment.