configcat / kotlin-sdk

ConfigCat SDK for Kotlin Multiplatform. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
https://configcat.com/docs/sdk-reference/kotlin
MIT License
14 stars 0 forks source link

Custom baseUrl does not work when using ConfigCat Proxy #29

Closed croemmich closed 6 months ago

croemmich commented 6 months ago

Describe the bug

We're running the ConfigCat Proxy (v0.4.2) and have set a custom baseUrl. The initial config fetch works however subsequent fetches do not.

The issue lies in how preferences from the response are being handled:

https://github.com/configcat/kotlin-sdk/blob/ea7a1fb32f39ac0664b16daf157d99f15823b696/src/commonMain/kotlin/com/configcat/fetch/ConfigFetcher.kt#L33-L39

response.entry.config.preferences?.baseUrl is https://cdn-global.configcat.com. As such, baseUrl.update { "https://cdn-global.configcat.com" } is being called, which breaks the client.

I'm not sure if this should be fixed in the client or if the proxy should be re-writing the baseUrl.

I also don't love that the redirect preference can force the baseUrl to update when using the proxy.

SDK version

com.configcat:configcat-kotlin-client-jvm:3.0.0

SDK configuration

ConfigCatClient("configcat-proxy/my-sdk") {
    baseUrl = "http://proxy-url"
}

Logs

2024-04-09 16:44:59 UTC [ERROR]: ConfigCat - [1100] Your SDK Key seems to be wrong. You can find the valid SDK Key at https://app.configcat.com/sdkkey. Received response: 403

Language/Framework version

Kotlin 1.9.23 Java 21

Platform

Mac/Linux

z4kn4fein commented 6 months ago

Hi @croemmich, thank you for reporting this issue! I'm going to create a fix here, because it's indeed a bug in the Kotlin SDK and let you know when it's published. Also, we'll discuss the possibility of removing the whole preferences section of the config JSON on the Proxy side to prevent any accidental redirection.

croemmich commented 6 months ago

Thanks @z4kn4fein!

z4kn4fein commented 6 months ago

Hi @croemmich, I've released the fix in 3.0.1 (it may take a little longer to be available on maven central).

Regarding the FORCE_REDIRECT value of the redirect parameter, I can confirm that it's not used currently anywhere in our system, and we don't plan to do so either. However, we'll definitely figure out something for making the Proxy usage an exception for any possible force redirection.

croemmich commented 6 months ago

Our team pulled it in and confirmed it's working. Thanks @z4kn4fein!