Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions kotlix/src/commonMain/kotlin/app/octocon/kotlix/Socket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,14 @@ abstract class SocketCommon(
return ref.toString()
}

/** A nullable-aware wrapper around the [logger] lambda */
/** A nullable-aware wrapper around the [logger] lambda that sanitizes sensitive data */
internal fun logItems(body: String) {
logger?.invoke(body)
var sanitized = body
// Redact system IDs: "system:123" -> "system:<redacted>"
sanitized = sanitized.replace(Regex("""system:[^"]+"""), "system:<redacted>")
// Redact token values in JSON: "token":"..." -> "token":"<redacted>"
sanitized = sanitized.replace(Regex(""""token":"[^"]*"""), """"token":"<redacted>""")
logger?.invoke(sanitized)
}

/**
Expand Down Expand Up @@ -583,4 +588,4 @@ fun buildEndpointUrl(
}

return urlBuilder.build()
}
}