Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Add cookieException for google drive #9879

Merged
merged 4 commits into from
Jul 25, 2017
Merged

Conversation

darkdh
Copy link
Member

@darkdh darkdh commented Jul 5, 2017

fixes #9810

Auditors: @diracdeltas, @bsclifton, @bbondy

Test Plan:

  1. Go to google drive
  2. Make sure block 3rd party cookies
  3. You should be able to download file
    Submitter Checklist:
  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.

Test Plan:

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@diracdeltas
Copy link
Member

I would prefer if this allowed specific cookies or cookie domains instead of all 3p cookies on Facebook and Google Drive. I use both FB and Google Drive with 3p cookies blocked (the default right now) and have never had a problem, so I don't want Brave to automatically change the setting to 'allow'.

@darkdh darkdh force-pushed the default_unblock_3rd_cookies branch from ac891d8 to dc208c1 Compare July 6, 2017 19:26
@darkdh darkdh changed the title Default disable 3rd party cookies for these sites Add exception of 3rd party cookies for these sites Jul 6, 2017
@darkdh darkdh force-pushed the default_unblock_3rd_cookies branch from dc208c1 to 3e1bc32 Compare July 6, 2017 20:24
@darkdh darkdh changed the title Add exception of 3rd party cookies for these sites Add cookieException for google drive Jul 6, 2017
@@ -46,9 +47,6 @@ let initializedPartitions = {}
const transparent1pxGif = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
const pdfjsOrigin = `chrome-extension://${config.PDFJSExtensionId}`

// Third party domains that require a valid referer to work
const refererExceptions = ['use.typekit.net', 'cloud.typography.com', 'www.moremorewin.net']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

app/filtering.js Outdated
@@ -273,9 +271,15 @@ function registerForBeforeSendHeaders (session, partition) {

if (cookieSetting === 'blockAllCookies' ||
isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) {
let hasCookieException = false
cookieExceptions.forEach((exceptionPair) => {
Copy link
Member

@diracdeltas diracdeltas Jul 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this would be more efficient if cookieExceptions were a map like {firstPartyOrigin: [origins]} instead of a list like [[firstPartyOrigin, origin],...]. but this seems ok for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is HUGE 😛 I'd love to see this (the cookieSetting logic) moved into it's own method so we can easily unit test it. If you don't mind, maybe I can try a rev1 for the test?

darkdh and others added 2 commits July 6, 2017 21:42
fixes #9810

Auditors: @diracdeltas, @bsclifton, @bbondy

Test Plan:
1. Go to google drive
2. Make sure block 3rd party cookies
3. You should be able to download file
Auditors: @darkdh, @diracdeltas

Test Plan:
`npm run unittest -- --grep="filtering unit tests"`
@bsclifton bsclifton force-pushed the default_unblock_3rd_cookies branch from 3e1bc32 to 695f0f8 Compare July 7, 2017 06:07
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darkdh @diracdeltas I rebased this, pulled the logic out to a method, and then added some unit tests 😄 I was going to give this as feedback after reviewing, but had some free cycles. Let me know what you think!

The unit tests I added help add this coverage (and I think also help prevent regressions):

  • Statement coverage from 15.63% to 19.05%
  • Branch coverage from 0% to 7.3%
  • Function coverage from 0% to 4.17%
  • Line coverage from 15.63% to 19.05%

app/filtering.js Outdated
@@ -273,9 +271,15 @@ function registerForBeforeSendHeaders (session, partition) {

if (cookieSetting === 'blockAllCookies' ||
isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) {
let hasCookieException = false
cookieExceptions.forEach((exceptionPair) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is HUGE 😛 I'd love to see this (the cookieSetting logic) moved into it's own method so we can easily unit test it. If you don't mind, maybe I can try a rev1 for the test?

@bsclifton bsclifton added this to the 0.19.x (Developer Channel) milestone Jul 7, 2017
assert(cookieException)

const url = cookieException[0]
const firstPartyUrl = cookieException[1]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

�The firstPartyUrl should be cookieException[0]. I will make it right in the commit changing the cookie exception to map

app/filtering.js Outdated
@@ -220,6 +218,38 @@ function registerForBeforeRedirect (session, partition) {
})
}

module.exports.considerRequestExceptions = (requestHeaders, url, firstPartyUrl, isPrivate) => {
Copy link
Member

@diracdeltas diracdeltas Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename this to something more descriptive like applyCookieSetting

app/filtering.js Outdated
firstPartyOrigin !== pdfjsOrigin && !hasCookieException) {
requestHeaders['Cookie'] = undefined
}
if (cookieSetting !== 'blockAllCookies' &&
Copy link
Member

@diracdeltas diracdeltas Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the cookieSetting !== 'blockAllCookies' part is a bug in the original code and should be omitted. the referer should be blocked when the cookieSetting is 'blockAllCookies'.

['https://inbox.google.com', 'https://hangouts.google.com'],
['https://mail.google.com', 'https://hangouts.google.com']
]
module.exports.cookieExceptions = {
Copy link
Member

@diracdeltas diracdeltas Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will probably need to be a map of domains to list, like 'https://inbox.google.com': [...] because we may need multiple cookie exception origins for the same top-level origin

@diracdeltas
Copy link
Member

thanks for adding tests!

@diracdeltas
Copy link
Member

diracdeltas commented Jul 7, 2017

this doesn't seem to fix the cookie issue on drive.google.com for me. i don't see any requests to https://doc-0g-3g-docs.googleusercontent.com, only https://lh*.googleusercontent.com

@darkdh
Copy link
Member Author

darkdh commented Jul 8, 2017

@diracdeltas I downloaded .pdf, .html, .txt, .mp4 files from google drive and it will send request to doc-*-3g-doc.googleusercontent.com
I think we need wildcard on this

screen shot 2017-07-07 at 5 04 22 pm

If you blocked [*.]googleusercontent.com on Chrome, and doing the steps listed above, you can see the download failed just same as we see in Brave

@diracdeltas
Copy link
Member

the wildcard fixes the issue for me 👍

@bsclifton bsclifton merged commit edf2d34 into master Jul 25, 2017
@bsclifton bsclifton deleted the default_unblock_3rd_cookies branch July 25, 2017 16:45
bsclifton added a commit that referenced this pull request Jul 25, 2017
@luixxiul
Copy link
Contributor

luixxiul commented Sep 9, 2017

@darkdh should this fix #8601 as well?

@darkdh
Copy link
Member Author

darkdh commented Sep 9, 2017

@luixxiul, no they are different. We are missing something on #8601 because you can see other non-chromium based browsers don't have the option(ex. Firefox).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downloading from Google Drive appears to become stuck
4 participants