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

Android CookieManager throws error caused by websites that are sending back illegal/invalid cookies. #476

Closed
3 of 5 tasks
2x2xplz opened this issue Aug 9, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@2x2xplz
Copy link

2x2xplz commented Aug 9, 2020

This is technically not a "bug" in InAppWebView, but caused by websites that are sending back illegal/invalid cookies.

Environment

Technology Version
Flutter version 1.17.5
Plugin version 4.0.0+4
Android version android-30 (tested on Android 6 device)
iOS version
Xcode version

Device information:

Description

Expected behavior: degrade gracefully - set cookie value to "" if not supplied.

Current behavior: E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): Failed to handle method call

Steps to reproduce

Unfortunately some websites send back illegal cookies that aren't in "name=value" form, they are just a text string without any = sign. This causes the CookieManager to throw an error (stacktrace below). CookieManager is following the spec, the websites are violating it. But we'd still prefer to handle the illegal cookies rather than crash the app.

The proposed resolution would check that both a name and value exist, then set the value to an empty string if it doesn't exist.

Fix (1-line)

Line 156 of MyCookieManager.java could be String value = (nameValue.length > 1) ? nameValue[1].trim() : "";
The precisely equivalent code doesn't exist in Swift, there's no splitting the string into an array. I don't know how iOS behaves in this situation.

Stacktrace/Logcat

E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): Failed to handle method call
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at com.pichillilorenzo.flutter_inappwebview.MyCookieManager.getCookies(MyCookieManager.java:156)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at com.pichillilorenzo.flutter_inappwebview.MyCookieManager.onMethodCall(MyCookieManager.java:68)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at android.os.MessageQueue.next(MessageQueue.java:331)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at android.os.Looper.loop(Looper.java:218)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at android.app.ActivityThread.main(ActivityThread.java:5526)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/MethodChannel#com.pichillilorenzo/flutter_inappwebview_cookiemanager( 3057): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

potential test case:

public class Main
{
	public static void main(String[] args) {
	    String okcookie = "hello=world";
	    String badcookie = "foobar";
	    ParseCookie(okcookie);
	    ParseCookie(badcookie);
	}
	
	public static void ParseCookie(String cookie) {
           String[] nameValue = cookie.split("=", 2);
           String name = nameValue[0].trim();
           // String value = nameValue[1].trim();  // fails
           String value = (nameValue.length > 1) ? nameValue[1].trim() : "";  // works
           System.out.println(String.format("Cookie[name:%s, value=%s]", name, value));
	}
}
@2x2xplz 2x2xplz added the bug Something isn't working label Aug 9, 2020
@pichillilorenzo pichillilorenzo changed the title CookieManager throws error: Failed to handle method call Android CookieManager throws error caused by websites that are sending back illegal/invalid cookies. Sep 7, 2020
Copy link

github-actions bot commented Nov 9, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant