-
Notifications
You must be signed in to change notification settings - Fork 949
[PM.24380] fix: Correct and redact flight recorder hostname on logs #6633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aj-rosado
wants to merge
9
commits into
main
Choose a base branch
from
PM-24380/flight-recorder-redact-hostname
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
β6
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81fc72d
redacting hostname from flight recorder logs
aj-rosado 45c195a
Redacting hostname when it matches a self-hosted hostname
aj-rosado b35e020
Merge branch 'main' into PM-24380/flight-recorder-redact-hostname
aj-rosado 78b2985
simplified method description
aj-rosado c2cd1f8
Merge branch 'main' into PM-24380/flight-recorder-redact-hostname
aj-rosado 4a711c8
using let instead of null validation
aj-rosado ee649db
Merge branch 'main' into PM-24380/flight-recorder-redact-hostname
aj-rosado 189916a
keeping BaseUrlProvider use only on the BaseUrlInterceptors.
aj-rosado 646e47e
Using the environment url hosts from ServerConfigRepository to redactβ¦
aj-rosado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
27 changes: 27 additions & 0 deletions
27
network/src/main/kotlin/com/bitwarden/network/util/HostnameRedactionUtil.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.bitwarden.network.util | ||
|
|
||
| /** | ||
| * List of official Bitwarden cloud hostnames that are safe to log. | ||
| */ | ||
| private val BITWARDEN_HOSTS = listOf("bitwarden.com", "bitwarden.eu", "bitwarden.pw") | ||
|
|
||
| /** | ||
| * Redacts hostnames in a log message by replacing bare hostnames with [REDACTED_SELF_HOST]. | ||
| * | ||
| * Only redacts hostnames that match [configuredHosts] AND are not official Bitwarden domains. | ||
| * Preserves all Bitwarden domains (including QA/dev environments). | ||
| * | ||
| * @param configuredHosts Set of hostnames to redact | ||
| * @return Message with hostnames redacted as [REDACTED_SELF_HOST] | ||
| */ | ||
| fun String.redactHostnamesInMessage(configuredHosts: Set<String>): String = | ||
| configuredHosts.fold(this) { result, hostname -> | ||
| val escapedHostname = Regex.escape(hostname) | ||
| val bareHostnamePattern = Regex("""\b$escapedHostname\b""") | ||
| bareHostnamePattern.replace(result) { hostname.redactIfSelfHosted() } | ||
| } | ||
|
|
||
| private fun String.redactIfSelfHosted(): String { | ||
| val isBitwardenHost = BITWARDEN_HOSTS.any { this.endsWith(it) } | ||
| return if (isBitwardenHost) this else "[REDACTED_SELF_HOST]" | ||
| } |
146 changes: 146 additions & 0 deletions
146
network/src/test/kotlin/com/bitwarden/network/util/HostnameRedactionUtilTest.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package com.bitwarden.network.util | ||
|
|
||
| import org.junit.jupiter.api.Assertions.assertEquals | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class HostnameRedactionUtilTest { | ||
| @Test | ||
| fun `redactHostnamesInMessage redacts configured self-hosted URLs`() { | ||
| val message = "--> GET https://vault.example.com/api/sync HTTP/1.1" | ||
| val configuredHosts = setOf("vault.example.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals("--> GET https://[REDACTED_SELF_HOST]/api/sync HTTP/1.1", result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage preserves non-configured URLs`() { | ||
| val message = "--> GET https://vault.example.com/api/sync HTTP/1.1" | ||
| val configuredHosts = setOf("api.bitwarden.com") // Different host | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals(message, result) // Unchanged - not in configured hosts | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage preserves Bitwarden URLs even if configured`() { | ||
| val message = "--> GET https://vault.bitwarden.com/api/sync HTTP/1.1" | ||
| val configuredHosts = setOf("vault.bitwarden.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals(message, result) // Unchanged - Bitwarden domain preserved | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage redacts quoted hostnames in error messages`() { | ||
| val message = """Unable to resolve host "vault.example.com": No address""" | ||
| val configuredHosts = setOf("vault.example.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals("""Unable to resolve host "[REDACTED_SELF_HOST]": No address""", result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage handles multiple URLs in one message`() { | ||
| val message = "Redirect from https://old.corp.com to https://new.corp.com" | ||
| val configuredHosts = setOf("old.corp.com", "new.corp.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals( | ||
| "Redirect from https://[REDACTED_SELF_HOST] to https://[REDACTED_SELF_HOST]", | ||
| result, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage handles empty configured hosts`() { | ||
| val message = "--> GET https://vault.example.com/api HTTP/1.1" | ||
| val configuredHosts = emptySet<String>() | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals(message, result) // Unchanged - no hosts to redact | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage handles NetworkCookieManagerImpl getCookies pattern`() { | ||
| val message = "2026-03-09 12:43:29:857 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "getCookies(vault.example.com): resolved=vault.example.com, count=0" | ||
| val configuredHosts = setOf("vault.example.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals( | ||
| "2026-03-09 12:43:29:857 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "getCookies([REDACTED_SELF_HOST]): resolved=[REDACTED_SELF_HOST], count=0", | ||
| result, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage preserves Bitwarden domains in NetworkCookieManagerImpl logs`() { | ||
| val message = "2026-03-09 12:43:29:857 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "getCookies(vault.example.com): resolved=vault.qa.bitwarden.pw, count=0" | ||
| val configuredHosts = setOf("vault.example.com", "vault.qa.bitwarden.pw") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals( | ||
| "2026-03-09 12:43:29:857 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "getCookies([REDACTED_SELF_HOST]): resolved=vault.qa.bitwarden.pw, count=0", | ||
| result, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage handles UnknownHostException error message`() { | ||
| val message = "DEBUG β BitwardenNetworkClient β <-- HTTP FAILED: " + | ||
| "java.net.UnknownHostException: Unable to resolve host " + | ||
| "\"vault.example.com\": No address associated with hostname." | ||
| val configuredHosts = setOf("vault.example.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals( | ||
| "DEBUG β BitwardenNetworkClient β <-- HTTP FAILED: " + | ||
| "java.net.UnknownHostException: Unable to resolve host " + | ||
| "\"[REDACTED_SELF_HOST]\": No address associated with hostname.", | ||
| result, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage handles needsBootstrap pattern`() { | ||
| val message = "2026-03-09 12:43:29:851 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "needsBootstrap(vault.example.com): false (cookieDomain=null)" | ||
| val configuredHosts = setOf("vault.example.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals( | ||
| "2026-03-09 12:43:29:851 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "needsBootstrap([REDACTED_SELF_HOST]): false (cookieDomain=null)", | ||
| result, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `redactHostnamesInMessage handles resolveHostname pattern`() { | ||
| val message = "2026-03-09 12:43:29:855 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "resolveHostname(vault.example.com): no stored config found, using original" | ||
| val configuredHosts = setOf("vault.example.com") | ||
|
|
||
| val result = message.redactHostnamesInMessage(configuredHosts) | ||
|
|
||
| assertEquals( | ||
| "2026-03-09 12:43:29:855 β DEBUG β NetworkCookieManagerImpl β " + | ||
| "resolveHostname([REDACTED_SELF_HOST]): no stored config found, using original", | ||
| result, | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.