-
Notifications
You must be signed in to change notification settings - Fork 445
[Blocked Security Review]Fixes #1144 Sharing of session amongst tabs and sharing of Authenticated Documents #1237
Conversation
Security review issue: https://github.com/brave/internal/issues/616 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall, small changes requested
0068fb5
to
54ca680
Compare
There are too many edge cases with cookie handling in private and normal tabs, I think we should add more tests for the cases that we have tested with this PR to avoid regressions in future. |
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.statusCode = try container.decode(Int.self, forKey: .statusCode) | ||
self.data = Data(base64Encoded: try container.decode(String.self, forKey: .base64Data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor-nit: we should probably add a maximum cap on how much data can be downloaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add that cap in Javascript but what would be the max file size? It will pull the "PDF" or image or whatever data from the WebKit's internal cache if available instead of "downloading" and it only does this when the user hits "share".
Also, what kind of tests did you have in mind? :)
I'll try to think of scenarios that I haven't tested already.
I've mostly been comparing various browsers' behaviours to our Brave-iOS.
Didn't realize how many problems arrises just trying to fix PDF :D lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the Content-Length
header, if the request is from the cache you can check if the status code is 304.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache doesn't return a 304 ever (it's local). It returns a 0 if it fails. If that's the case, my code returns you null because there is no document available. In the case where a document is available to share, it returns a 200 always and the byte-data associated with it.
If the web-server returns a 304, the page would have loaded the document from the cache, this Javascript would pull it from the page returning a 200.
I checked Brave Desktop, there's no limit to what you can download and I haven't seen any limits in the old code before this PR so I'm not sure what the limit is.
@jumde can you please help us getting together a list for the same. Its really difficult to figure out all possibilities :) |
Yes! Let's use this comment to compile the list, feel free to add the cases you think i've missed:
|
xhr.responseType = "arraybuffer"; | ||
xhr.onreadystatechange = function() { | ||
if (this.readyState == XMLHttpRequest.DONE) { | ||
if (this.status == 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about redirects here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't matter because it only triggers the Javascript when you press "Share" and it only injects the Javascript when the page is completely loaded (IE: 200 or 404).
In such a case, you won't be able to share a 404 page anyway as the Mime-Type is not a doc type.
There is some code that was written before that checks:
if response.mimeType?.isKindOfHTML == false
before allowing you to "share" the page.
Basically, if the document was never loaded into a page with a 200, this Javascript won't ever be triggered because you won't be able to share in the first place.
In the case that the page is loaded and we attempt to get the document, I can't see it ever returning a redirect since the document is already downloaded. Also, if it does return a redirect for the weirdest possible reason, the JS would return you NULL as per the else statement.
Hmm I tested these cases in my PR with gmail & safari dev tools. Case 1 -> Opening a normal tab kills all private tabs and all their non-persistent stores along with them. Also tested in PR. Case 2 -> Login gmail via Normal tab does NOT log you into a Private tab & vice-versa since they use different storage. Tested this in my PR. Case 3 -> Killing the last private tab does the same as killing all private tabs and their non-persistent stores along with them. Case 4 -> Verified in my PR via gmail log in. Login to tab-a automatically logs you in to tab-b. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, although this needs some serious testing from the QA team.
54ca680
to
7be96be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I was thinking more of some automated tests, you can check the tests in |
7be96be
to
7890d34
Compare
Fixed. I've added some important tests that cleared up a lot of confusion and discovered some bugs along the way. class TabSessionTests: XCTestCase {
/** Tests whether or not two private tabs are sharing the same data-store/cookie-store **/
func testPrivateTabSessionSharing()
/** Tests whether or not a private tab's data-store/cookie-store is truly non-persistent **/
func testPrivateTabNonPersistence()
/** Tests whether or not switching from private tab to normal tab destroys the data-store/cookie-store completely **/
func testTabsPrivateToNormal()
/** Tests whether or not switching from normal tab to private tab keeps the data-store/cookie-store separate **/
func testTabsNormalToPrivate()
} These seem to be the most important and have fixed any bugs related to their failures. |
0382115
to
93b8b53
Compare
629c541
to
44352e9
Compare
@jumde tests have been added. Can you verify and update the security review status? |
If you haven't done it already, this also needs to be rebased to latest development to pass CI |
9ea1e6c
to
a138dde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid work!!!
Fixed a background thread issue where "displayTitle" is being called on WKWebView on a non-main thread causing the PrintPreview to have undefined-behaviour. Fixed opening Authenticated documents in Private-Browsing mode when it opens in a new tab. Fixed opening Authenticated documents and attempting to share, or print them. Fixes tabs not having the same data store as other tabs (IE: Log-In to any website on one tab should log you in on another tab). Fixed destroying of data-store to only happen when ALL tabs are destroyed. Changed Temporary Storage to pull out the document from the WebPage instead of making server calls outside the webview's session (IE: No need for cookie injecting, etc).. Instead, we get the webview to give us the document via Javascript injection which passes the document to iOS for display/saving, etc..
Minor change to filtering tabs. Implicitly use the error parameter.
Fixed a bug in `removeAllBrowsingDataForTab` where it only removed select data instead of ALL data.
…te tabs have been destroyed. - Discovered during unit tests.
80e5d2e
to
be9e0f2
Compare
BUG FIXES:
WHAT I TESTED:
Log into Email (gmail.com) in PrivateTab-A
Log out of Email (gmail.com) in PrivateTab-A
Above tested in normal mode as well.
Log into PrivateTab-A
Log into Normal Tab-A
Log into banking website in PrivateTab-A
Log into banking website in PrivateTab-A
Log into banking website in PrivateTab-A
Log into banking website in PrivateTab-A
Submitter Checklist:
Fix #123: This fixes the shattered coffee cup!
(orNo Bug: <message>
if no relevant ticket)NSLocalizableString()
Test Plan:
Screenshots:
Reviewer Checklist:
QA/(Yes|No)
release-notes/(include|exclude)
bug
/enhancement