diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/network/ReactCookieJarContainer.java b/ReactAndroid/src/main/java/com/facebook/react/modules/network/ReactCookieJarContainer.java index a8436c21875ebc..370586fa50ca9c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/network/ReactCookieJarContainer.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/network/ReactCookieJarContainer.java @@ -1,5 +1,6 @@ package com.facebook.react.modules.network; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -7,6 +8,7 @@ import okhttp3.Cookie; import okhttp3.CookieJar; +import okhttp3.Headers; import okhttp3.HttpUrl; /** @@ -37,7 +39,17 @@ public void saveFromResponse(HttpUrl url, List cookies) { @Override public List loadForRequest(HttpUrl url) { if (cookieJar != null) { - return cookieJar.loadForRequest(url); + List cookies = cookieJar.loadForRequest(url); + ArrayList validatedCookies = new ArrayList<>(); + for (Cookie cookie : cookies) { + try { + Headers.Builder cookieChecker = new Headers.Builder(); + cookieChecker.add(cookie.name(), cookie.value()); + validatedCookies.add(cookie); + } catch (IllegalArgumentException ignored) { + } + } + return validatedCookies; } return Collections.emptyList(); }