focus-android icon indicating copy to clipboard operation
focus-android copied to clipboard

Google "search history" survives erasing browsing history

Open ghost opened this issue 9 years ago • 33 comments

Please can you add the below to Firefox Focus.

  1. Ability to remove search history. For example, my previous searches appears in the Google search bar when visiting www.google.com.

  2. Menu -> Open with Firefox. Can this option only appear to those who have Firefox installed.

Thanks

ghost avatar Sep 11 '17 08:09 ghost

  • Can you provide us with the exact steps to reproduce (1)?

  • Your second issue was recently fixed in #1025 and will be released soon.

pocmo avatar Sep 11 '17 08:09 pocmo

Also: What Android version / device are you using? :)

pocmo avatar Sep 11 '17 08:09 pocmo

I believe that I noticed this (1) before and came to the conclusion that Google just knows it's still you even if you clear history by tapping the trashcan or using the notification... it's kind of creepy actually. I just use DDG now. I think that if you clear focus from memory by swiping, with a little time and/or different IP address, your searches will disappear.

phunkular avatar Sep 16 '17 21:09 phunkular

Device: OnePlus 2 A2001 Version: 6.0.1

Steps below on reproducing issue 1.

Launch Focus -> Browse to www.google.com -> Search for something, like 'Nintendo Switch'

Despite having cleared the History within Focus and closing down the application my past search results from www.google.com still appear in the drop down menu (search bar). This behavior happens with other sites too I've noticed that use the same searching technology. Helpful for some I'm sure. But thought I should raise it.

See attached screenshot. screenshot_20170918-163824 1

ghost avatar Sep 18 '17 15:09 ghost

@pocmo I can repro this in sim for API 23. (remove/reinstalling app removes history) we had this issue a long time ago in Focus iOS - fixed by disabling localStorage (I think we already do that) would this be related in this instance too? https://bugzilla.mozilla.org/show_bug.cgi?id=1319208

it's strange, because I remember specifically looking for this a while ago, and didn't see this. use some non-common search term like 'nojun' :)

nojunpark avatar Sep 18 '17 17:09 nojunpark

We enabled local/session storage to fix a bug in #927. However we wrote some code to clear it whenever a session is erased.

pocmo avatar Sep 18 '17 18:09 pocmo

Just want to say thank you for your attention on this. Hopefully will be addressed very soon.

ghost avatar Sep 19 '17 11:09 ghost

To summarize so far:

  • I can reproduce on the API 23 emulator. Note that search history will persist even beyond process restarts
  • I can reproduce on desktop Chrome using responsive design mode
  • Clearing localStorage on desktop Chrome will prevent the history from appearing. In theory, one hack fix would be to call localStorage.clear() when opening Google and other affected pages but it's unclear whether the page would be able to access (and snoop) these values before we're able to clear manually.
  • Using remote dev tools, I found that when we hit the trash can, localStorage is not cleared between sessions on the API 23 emulator (using webkit version 44.0.2403.119) and manually clearing it fixes the issue

I'll keep looking for why WebStorage.deleteAllData does not appear to remove local storage - either:

  • we're not calling it correctly (e.g. we call delete, which could be async, but destroy the WebView instance before the call can complete)
  • We should be using a different method
  • it's a WebKit bug
  • it's not possible to clear localStorage outside of JS

mcomella avatar Oct 11 '17 23:10 mcomella

In a raw WebView, WebStorage.deleteAllData clears localStorage which makes me think we're not calling it as it's expected to be called (e.g. the async thing I mentioned).

mcomella avatar Oct 12 '17 00:10 mcomella

I commented out two lines:

And now it works correctly – apparently we've been interfering with WebKit's delete process.

One side effect of this is that the first trash can hit successfully clears the search history but subsequent ones do not.

mcomella avatar Oct 12 '17 00:10 mcomella

Like the previous, I just removed all invocations of deleteContentFromKnownLocations, which deletes files from the WebView directory, and deleting localStorage is working correctly. This matches my hypothesis that we're messing with WebKit's delete process.

mcomella avatar Oct 12 '17 00:10 mcomella

It appears the problem is with FileUtils.deleteWebViewDirectory(context);

mcomella avatar Oct 12 '17 00:10 mcomella

I modified the delete web view function so that it will delete everything but the "Local Storage" subdirectory and its contents and localStorage/Google search history is successfully cleared. If I delete the files inside the directory, localStorage/search history is not cleared. Therefore, we have to leave the files inside the "Local Storage" directory on delete. Unfortunately, these files give away domain names (not paths), e.g.:

https_news.google.com_0.localstorage
https_news.google.com_0.localstorage-journal
https_support.google.com_0.localstorage
https_support.google.com_0.localstorage-journal
https_www.google.com_0.localstorage
https_www.google.com_0.localstorage-journal

So we have to trust WebKit to not leak this data. In theory, we should be able to delete the files on process deletion/creation, which isn't ideal.


@pocmo FYI.

Thought: deleting the web view directory prevents the browser from getting rid of local storage – what else could it be preventing? Perhaps this is the cause of #1392 – visited colors persist?

Observation: when we delete the web view directory, WebKit does not restore the directories we delete (i.e. I deleted everything but “Local Storage” when the trash can is hit and LS is the only directory that exists when I load more pages) until the process is recreated.

Hypothesis: when WebKit can’t write state to files (because we deleted them), it refuses to clear its in-memory cache

mcomella avatar Oct 12 '17 17:10 mcomella

Perhaps this is the cause of #1392 – visited colors persist?

Nope: I commented out the delete code and visited colors still persist.

mcomella avatar Oct 12 '17 17:10 mcomella

Deleting the WebKit dir was added in #433 (PR #476) but it seems it was a preventative measure rather than one trying to solve a specific problem.

In the worst (and simplest) case, I think we should keep the "Local Storage" folder and its contents when we clear state. Further investigation to continue with preventative measures:

  • Deleting "Local Storage" contents when the process starts (in Application.onCreate; I confirmed this works)
  • Deleting the "Local Storage" contents after the process ends (since there's no callback, we might have to schedule a repeating job in onStop)
  • Tricking WebKit into deleting its Local Storage in memory while deleting the files: e.g. this could entail copying the files into memory while deleting them from disk and restoring them to disk just before we call delete,
  • File a bug with Chromium mentioning that it leaks data through the filesystem despite clearing it in the UX

@pocmo Do you have any thoughts on the best approach?


As per https://github.com/mozilla-mobile/focus-android/issues/1306#issuecomment-336207972, we should also consider investigating whether deleting WebKit files on trash can is a good idea.

mcomella avatar Oct 12 '17 18:10 mcomella

I wrote WebViewDataTest which does a couple of things and then checks the data directory whether there are any traces of the browsing session. This test showed that WebView leaves traces even when calling all available clear()/delete()/etc. methods. Debugging another issue I even realized that some things stay around as long as the Chrome process is alive (Although maybe that's a side effect of the issue you are seeing here).

So we have to trust WebKit to not leak this data. In theory, we should be able to delete the files on process deletion/creation, which isn't ideal.

I would be very cautious with trust here. There are a lot of different versions of WebView/Chromium/Chrome we run on top of across various devices. That's a big drawback of not owning the web engine.

Thought: deleting the web view directory prevents the browser from getting rid of local storage – what else could it be preventing? Perhaps this is the cause of #1392 – visited colors persist?

The root issue of the link coloring problem is known and tracked by #990 and the linked Chromium bug. Other issues we saw were our workaround not working ("Remove :visited link colors") and other memory/chrome-process caches. Nevertheless it would be interesting to know whether we break more - I think I saw some cookie write log errors from WebView at times.

Overall I'm not happy about our approach of deleting everything. Especially it's now called way too often. When I refactored the app to support multiple tabs I was wondering if we can limit that to very specific points only (e.g. app start to clear whatever survived from the last time). There's also a chance that over-doing it influences other tabs if they kill each others persisted data.

In the worst (and simplest) case, I think we should keep the "Local Storage" folder and its contents when we clear state

Can you try this and run WebViewDataTest to see if there's still data surviving? This /could/ be problematic: We saw that reddit uses Local Storage to mark subreddits as read. If this data survives then we introduces a new problem. However now I think that was the case where I saw that this data survives our process lifetime and I had to kill the Chrome process (or wait) to kill it. I wonder if removing the unnecessary deletes fixes that?

Deleting "Local Storage" contents when the process starts (in Application.onCreate; I confirmed this works)

That's what I was wondering too and I think we could try that.

Deleting the "Local Storage" contents after the process ends (since there's no callback, we might have to schedule a repeating job in onStop)

This sounds hacky. I saw that a Service set to sticky will restart (and also the process!). Maybe we could use that to clean up and then shut it down again. But that's a bit hacky too.

File a bug with Chromium mentioning that it leaks data through the filesystem despite clearing it in the UX

That's always a good idea. From the other bugs it's very unlikely that they are going to deploy a fix that will change an existing WebView API behavior - even if it's weird. But they mentioned that they are working on some kind of support library that allows users of it to call new APIs that are not exposed otherwise and with that get new features/behaviors (e.g. clear link coloring).

As per #1306 (comment), we should also consider investigating whether deleting WebKit files on trash can is a good idea.

I agree and think it's actually a pretty bad idea if this happens whenever a tab(!) gets removed. It's not possible via the erase button but via back button for example.

pocmo avatar Oct 12 '17 18:10 pocmo

We say we do not store any history etc. - So I think our requirements are:

  • Make sure that we do not accumulate traces of browsing history on disk. Temporary caches are okay.
  • Do not leak any data to other apps.

I think as long as we stay in those bounds we can be flexible.

pocmo avatar Oct 12 '17 18:10 pocmo

Make sure that we do not accumulate traces of browsing history on disk. Temporary caches are okay.

@pocmo how long do you think temporary data should persist? i.e. is clearing data files on process start-up good enough or should we be trying to do better? Some attack vectors for temporary files (like these localStorage domains) are:

  1. Third party APIs, including WebKit, access these files and do something with the information. I'm not sure it matters how long these files are on disk, but just the fact that they're written to disk at all so clear on start-up is probably good enough
  2. Users can open the filesystem on unencrypted devices to find these files (fwiw, it looks like new official Android devices since Marshmallow are encrypted by default)
  3. Rooted devices (afaik, i) in some implementations, everything runs as root and apps can read any other apps data and ii) Users can adb shell into the device to read files): I assume we don't care about this case

(1), in addition to how WebKit seems to use these files, makes me think it's fine to clear on process creation and (2) makes me think we should additionally have a clean-up job that will run a few hours after Focus is closed (e.g. create the job in onPause; this job will have to make sure the Focus process is not still running though so could become complicated).


In the worst (and simplest) case, I think we should keep the "Local Storage" folder and its contents when we clear state

Can you try this and run WebViewDataTest to see if there's still data surviving?

The test fails because it expects the webview data directory to be deleted and I intentionally delete all the subdirectories but "Local Storage".

This /could/ be problematic: We saw that reddit uses Local Storage to mark subreddits as read. If this data survives then we introduces a new problem.

By using the dev tools (opening a console on the page and checking localStorage.length), I was able to determine WebStorage.deleteAllData will clear the localStorage such that the page cannot access the data. However, the files are left on disk: I haven't checked what their contents contain but their filenames expose the domains the user has visited. We should decide on an appropriate solution based on the attack vectors I've listed above (and any you can think of).

However now I think that was the case where I saw that this data survives our process lifetime and I had to kill the Chrome process (or wait) to kill it. I wonder if removing the unnecessary deletes fixes that?

Debugging another issue I even realized that some things stay around as long as the Chrome process is alive (Although maybe that's a side effect of the issue you are seeing here).

Yes, deleting the "Local Storage" files appears to block Chrome from deleting the localStorage data exposed to the web page (until the process is killed), which is why I suggest that we should, in the simplest case, leave the files when hitting erase but delete them at some later point.

As per #1306 (comment), we should also consider investigating whether deleting WebKit files on trash can is a good idea.

I agree

I filed #1472.

mcomella avatar Oct 12 '17 22:10 mcomella

Very curious! In my RawWebView project (basically a web view with a WebStorage.deleteAllData button), the local storage files are deleted successfully – I wonder what Focus is doing differently. Maybe we don't need a special solution (beyond don't delete the "Local Storage" dir) after all.

mcomella avatar Oct 12 '17 23:10 mcomella

Commenting out our manual deletion of the web view files, WebStorage.deleteAllData will sometimes remove the local storage files in Focus and always will in my test project (using the same test cases). My test case:

  1. Navigate to www.google.com
  2. Search "apple", hit enter, wait for page load
  3. Clear local storage (trash can, or clear button)

~~On Focus, sometimes this will clear the local storage files and sometimes this will not.~~ [edit: see below] In my testing just now, Focus will always clear the files if we leave out the "apple" step. I wonder if we're hiding/destroying the WebView before we can complete all these async delete calls (assuming they're async). I tried commenting out all the other delete state calls and it doesn't seem to have made a difference.

mcomella avatar Oct 12 '17 23:10 mcomella