Skip to content

Commit bded299

Browse files
committed
fix: remove sensitive database metadata from health endpoint
1 parent a373482 commit bded299

1 file changed

Lines changed: 1 addition & 18 deletions

File tree

src/main/java/com/iemr/admin/service/health/HealthService.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ private Map<String, Object> checkDatabaseHealth() {
106106
long responseTime = System.currentTimeMillis() - startTime;
107107

108108
dbStatus.put("status", "UP");
109-
dbStatus.put("database", connection.getMetaData().getDatabaseProductName());
110-
dbStatus.put("driver", connection.getMetaData().getDriverName());
111-
dbStatus.put("url", sanitizeUrl(connection.getMetaData().getURL()));
112109
dbStatus.put("responseTime", responseTime + "ms");
113110
dbStatus.put("message", "Database connection successful");
114111

@@ -128,11 +125,10 @@ private Map<String, Object> checkDatabaseHealth() {
128125
} catch (Exception e) {
129126
long responseTime = System.currentTimeMillis() - startTime;
130127
dbStatus.put("status", "DOWN");
131-
dbStatus.put("message", "Database connection failed: " + e.getMessage());
132128
dbStatus.put("responseTime", responseTime + "ms");
133129
dbStatus.put("error", e.getClass().getSimpleName());
134130

135-
logger.error("Database health check failed", e);
131+
logger.error("Database health check failed: {}", e.getMessage(), e);
136132
}
137133

138134
return dbStatus;
@@ -189,17 +185,4 @@ private Map<String, Object> checkRedisHealth() {
189185

190186
return redisStatus;
191187
}
192-
193-
/**
194-
* Sanitize database URL to remove sensitive information like passwords
195-
*/
196-
private String sanitizeUrl(String url) {
197-
if (url == null) {
198-
return "unknown";
199-
}
200-
201-
// Remove password parameter if present
202-
return url.replaceAll("password=[^&]*", "password=***")
203-
.replaceAll("pwd=[^&]*", "pwd=***");
204-
}
205188
}

0 commit comments

Comments
 (0)