Ensure browser sessions can not correlate identities between Status account sessions (#688)

This commit is contained in:
alwx 2017-01-17 00:16:55 +03:00 committed by Roman Volosovskyi
parent 351e54129c
commit 101448b963
4 changed files with 69 additions and 1 deletions

View File

@ -2,12 +2,17 @@ package im.status.ethereum.module;
import android.app.Activity;
import android.view.WindowManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebStorage;
import com.facebook.react.bridge.*;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import android.util.Log;
import java.util.HashMap;
import java.util.UUID;
@ -330,4 +335,41 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
});
}
@SuppressWarnings("deprecation")
@ReactMethod
public void clearCookies() {
Log.d(TAG, "clearCookies");
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
} else {
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(activity);
cookieSyncManager.startSync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncManager.stopSync();
cookieSyncManager.sync();
}
}
@ReactMethod
public void clearStorageAPIs() {
Log.d(TAG, "clearStorageAPIs");
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
}
WebStorage storage = WebStorage.getInstance();
if (storage != null) {
storage.deleteAllData();
}
}
}

View File

@ -283,6 +283,26 @@ RCT_EXPORT_METHOD(setSoftInputMode: (NSInteger) i) {
#endif
}
RCT_EXPORT_METHOD(clearCookies) {
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
}
RCT_EXPORT_METHOD(clearStorageAPIs) {
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
for (NSString *string in array) {
NSLog(@"Removing %@", [path stringByAppendingPathComponent:string]);
if ([[string pathExtension] isEqualToString:@"localstorage"])
[[NSFileManager defaultManager] removeItemAtPath:[path stringByAppendingPathComponent:string] error:nil];
}
}
+ (void)signalEvent:(const char *) signal
{
if(!signal){

View File

@ -35,6 +35,7 @@
:change-account
(u/side-effect!
(fn [_ [_ address new-account? callback]]
(status/clear-web-data)
(data-store/change-account address new-account?
#(callback % address new-account?)))))

View File

@ -151,5 +151,10 @@
(when status
(call-module #(.setSoftInputMode status mode))))
(defn clear-web-data []
(when status
(call-module #(.clearCookies status))
(call-module #(.clearStorageAPIs status))))
(def adjust-resize 16)
(def adjust-pan 32)