Skip to content
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

RUM-6454: fixing potential issues with subdomain host lookup #2436

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
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
1 change: 1 addition & 0 deletions detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ datadog:
- "kotlin.collections.Set.any(kotlin.Function1)"
- "kotlin.collections.Set.associate(kotlin.Function1)"
- "kotlin.collections.Set.contains(com.datadog.android.trace.TracingHeaderType)"
- "kotlin.collections.Set.firstOrNull(kotlin.Function1)"
- "kotlin.collections.Set.forEach(kotlin.Function1)"
- "kotlin.collections.Set.ifEmpty(kotlin.Function0)"
- "kotlin.collections.Set.isEmpty()"
Expand Down