Skip to content

Commit

Permalink
RUM-6454: fixing potential issues with subdomain host lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
satween committed Dec 5, 2024
1 parent 53e3a46 commit 8715a13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class DefaultFirstPartyHostHeaderTypeResolver(
/** @inheritdoc */
override fun headerTypesForUrl(url: HttpUrl): Set<TracingHeaderType> {
val host = url.host
val filteredHosts = knownHosts.filter {
it.key == "*" || it.key == host || host.endsWith(".${it.key}")
}
return filteredHosts.values.flatten().toSet()

return knownHosts[host]
?: knownHosts.entries.firstOrNull { host.endsWith(".${it.key}") }?.value
?: knownHosts["*"]
?: emptySet()
}

/** @inheritdoc */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,22 @@ internal class DefaultFirstPartyHostHeaderTypeResolverTest {
}
}

@Test
fun `M return correct header type W headerTypesForUrl(String) {domain and subdomain has different types}`() {
val resolver = DefaultFirstPartyHostHeaderTypeResolver(
mapOf(
"bar.com" to setOf(TracingHeaderType.DATADOG),
"foo.bar.com" to setOf(TracingHeaderType.TRACECONTEXT)
)
)

assertThat(resolver.headerTypesForUrl("http://bar.com"))
.isEqualTo(setOf(TracingHeaderType.DATADOG))

assertThat(resolver.headerTypesForUrl("http://foo.bar.com"))
.isEqualTo(setOf(TracingHeaderType.TRACECONTEXT))
}

companion object {
private const val HOST_REGEX = "([a-z][a-z0-9_~-]{3,9}\\.){1,4}[a-z][a-z0-9]{2,3}"
}
Expand Down

0 comments on commit 8715a13

Please sign in to comment.