HttpClient exception unexpected char in header value

SteveW6219SteveW6219 USMember
edited April 16 in Xamarin.Android

Hi,

We recently added analytics and crash tracking to our Android app using MS App Centre and it's helped shed some light on a bug that has blighted us for a while.

What we are seeing is that when making calls using HttpClient to our API an exception is thrown when the http client parses the response headers, stating that there is an invalid character in the header value. Specifically its the content of the set cookie header. The problematic content appears to be related to Google Analytics due to the cookie name being prefixed with __utm.

The API's that the application is calling do not have Google Analytics enabled, nor do we have Google Analytics integrated into the mobile application.

This appears to be affecting just some Android Oreo and Pie devices but it prevents all calls from completing without exception.

We do not see these cookies on every http call to our API's.

An example of the exception is attached at the end of the post.

I've a number of questions and concerns:

  1. Given that our API and application does not have Google analytics enabled or integrated, where are the cookies coming from? Note there are other cookies present (visid_incap and incap_ses) I know what issues these, so they aren't a concern.
  2. Is the cookie container implementation effectively sandboxed to the application or does it share cookies across applications, browser and across the device? The fact that these cookies are not present on every API call from every device implies the cookies must exist on the devices exhibiting a problem.
  3. Is there any way in which we can disable header validation or clear these cookies?
  4. Is it possible that Google services on the device are somehow pervasive and are the cause of these cookies?

Any help would be appreciated

Thanks

Steve

Note: A non-ascii character appears 3 character in on this cookie value ___utmvaaFuFsaK=rnGDhH

The full exception is as follows:

java.lang.IllegalArgumentException: Unexpected char 0x01 at 48 in header value: ___utmvmaFuFsaK=urwttAhlnib; ___utmvaaFuFsaK=rnGDhH; visid_incap_705123=Gja+h34KRPG/XfQmeLdezP/stVwAAAAAQUIPAAAAAAD9YkX6STEQkigyefQj2KSw; incap_ses_143_705123=FxxTMwI5ZzNz77UtBAz8Af/stVwAAAAAcdpnCD6O/UffW7AohMqoDA==
com.android.okhttp.Headers$Builder.checkNameAndValue(Headers.java:314)
com.android.okhttp.Headers$Builder.set(Headers.java:275)
com.android.okhttp.internal.huc.HttpURLConnectionImpl.setRequestProperty(HttpURLConnectionImpl.java:562)
com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.setRequestProperty(DelegatingHttpsURLConnection.java:258)
com.android.okhttp.internal.huc.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:26)
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
android.os.Handler.handleCallback(Handler.java:891)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:207)
android.app.ActivityThread.main(ActivityThread.java:7470)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

Sign In or Register to comment.