Skip to content

Commit 1bc2845

Browse files
authored
feat: sanitize password in URL for logging (#70)
1 parent 4a7a2af commit 1bc2845

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/RedisBrain.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ export default (robot, redis = Redis) => {
2121
const redisUrl = process.env[redisUrlEnv] || 'redis://localhost:6379'
2222
robot.config = Object.assign(robot.config || {}, { redisUrl })
2323
if (redisUrlEnv) {
24-
robot.logger.info(`hubot-redis-brain: Discovered redis from ${redisUrlEnv} environment variable: ${redisUrl}`)
24+
// Sanitize password in URL for logging
25+
const sanitizedUrl = (() => {
26+
try {
27+
const urlObj = new URL(redisUrl)
28+
if (urlObj.password) {
29+
urlObj.password = '*****'
30+
}
31+
return urlObj.toString()
32+
} catch {
33+
return redisUrl
34+
}
35+
})()
36+
robot.logger.info(`hubot-redis-brain: Discovered redis from ${redisUrlEnv} environment variable: ${sanitizedUrl}`)
2537
} else {
2638
robot.logger.info('hubot-redis-brain: Using default redis on localhost:6379')
2739
}

0 commit comments

Comments
 (0)