Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit d9a7eec

Browse files
authored
Avoid saving FXA login sessions (#3190)
1 parent 0192ce9 commit d9a7eec

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/browser/Services.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import org.mozilla.geckoview.GeckoResult
3030
import org.mozilla.geckoview.GeckoSession
3131
import org.mozilla.vrbrowser.R
3232
import org.mozilla.vrbrowser.browser.engine.EngineProvider
33-
import org.mozilla.vrbrowser.utils.SystemUtils
3433
import org.mozilla.vrbrowser.telemetry.GleanMetricsService
34+
import org.mozilla.vrbrowser.utils.SystemUtils
3535

3636

3737
class Services(val context: Context, places: Places): GeckoSession.NavigationDelegate {
@@ -128,10 +128,22 @@ class Services(val context: Context, places: Places): GeckoSession.NavigationDel
128128
val state = parsedUri.getQueryParameter("state") as String
129129
val action = parsedUri.getQueryParameter("action") as String
130130

131+
val geckoResult = GeckoResult<AllowOrDeny>()
132+
131133
// Notify the state machine about our success.
132-
accountManager.finishAuthenticationAsync(FxaAuthData(action.toAuthType(), code = code, state = state))
134+
val result = accountManager.finishAuthenticationAsync(FxaAuthData(action.toAuthType(), code = code, state = state))
135+
CoroutineScope(Dispatchers.Main).launch {
136+
if (!result.await()) {
137+
android.util.Log.e(LOGTAG, "Authentication finish error.")
138+
geckoResult.complete(AllowOrDeny.DENY)
139+
140+
} else {
141+
android.util.Log.e(LOGTAG, "Authentication successfully completed.")
142+
geckoResult.complete(AllowOrDeny.ALLOW)
143+
}
144+
}
133145

134-
return GeckoResult.ALLOW
146+
return geckoResult
135147
}
136148
return GeckoResult.DENY
137149
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
import java.util.ArrayList;
4040
import java.util.Collections;
4141
import java.util.List;
42+
import java.util.function.Predicate;
4243
import java.util.stream.Collectors;
44+
import java.util.stream.Stream;
4345

4446
import mozilla.components.concept.sync.AccountObserver;
4547
import mozilla.components.concept.sync.AuthType;
@@ -60,6 +62,11 @@ public class Windows implements TrayListener, TopBarWidget.Delegate, TitleBarWid
6062
private static final int TAB_SENT_NOTIFICATION_ID = 1;
6163
private static final int BOOKMARK_ADDED_NOTIFICATION_ID = 2;
6264

65+
// Restore URLs blacklist
66+
private static final List<String> SAVE_BLACKLIST = Stream.of(
67+
"https://accounts.firefox.com/oauth/"
68+
).collect(Collectors.toList());
69+
6370
class WindowState {
6471
WindowPlacement placement;
6572
int textureWidth;
@@ -185,11 +192,17 @@ public void saveState() {
185192
state.privateMode = mPrivateMode;
186193
state.focusedWindowPlacement = mFocusedWindow.isFullScreen() ? mFocusedWindow.getWindowPlacementBeforeFullscreen() : mFocusedWindow.getWindowPlacement();
187194
ArrayList<Session> sessions = SessionStore.get().getSortedSessions(false);
188-
state.tabs = sessions.stream().map(Session::getSessionState).collect(Collectors.toCollection(ArrayList::new));
195+
state.tabs = sessions.stream()
196+
.map(Session::getSessionState)
197+
.filter(sessionState -> SAVE_BLACKLIST.stream().noneMatch(uri -> sessionState.mUri.startsWith(uri)))
198+
.collect(Collectors.toCollection(ArrayList::new));
189199
for (WindowWidget window : mRegularWindows) {
190-
WindowState windowState = new WindowState();
191-
windowState.load(window, state, sessions.indexOf(window.getSession()));
192-
state.regularWindowsState.add(windowState);
200+
if (window.getSession() != null &&
201+
SAVE_BLACKLIST.stream().noneMatch(uri -> window.getSession().getCurrentUri().startsWith(uri))) {
202+
WindowState windowState = new WindowState();
203+
windowState.load(window, state, sessions.indexOf(window.getSession()));
204+
state.regularWindowsState.add(windowState);
205+
}
193206
}
194207
Gson gson = new GsonBuilder().setPrettyPrinting().create();
195208
gson.toJson(state, writer);

0 commit comments

Comments
 (0)