Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5869: Google OAuth should work by default #3784

Merged
merged 1 commit into from
Nov 15, 2019
Merged

Fix 5869: Google OAuth should work by default #3784

merged 1 commit into from
Nov 15, 2019

Conversation

jumde
Copy link
Contributor

@jumde jumde commented Oct 23, 2019

Fix brave/brave-browser#5869

Submitter Checklist:

Test Plan:

  1. Navigate to expensify.com
  2. Verify that Cross-Site cookie blocking is enabled
  3. Click login using Google
  4. Login should succeed
  5. Navigate to brave://settings/socialBlocking and disable Google login
  6. Navigate to brave://settings/clearBrowserData and clear all data
  7. Try logging in again, login should fail

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@jumde jumde requested a review from bridiver as a code owner October 23, 2019 16:28
@jumde jumde force-pushed the google_oauth branch 2 times, most recently from 4a6a17a to e0c3923 Compare October 29, 2019 22:21
@jumde jumde changed the title [WIP] Fix Google OAuth Fix 5869: Fix Google OAuth Oct 29, 2019
@jumde jumde changed the title Fix 5869: Fix Google OAuth Fix 5869: Google OAuth should work by default Oct 29, 2019
@jumde jumde self-assigned this Oct 29, 2019
@@ -205,6 +205,20 @@ ControlType GetCookieControlType(Profile* profile, const GURL& url) {
HostContentSettingsMapFactory::GetForProfile(profile), url);
}

void SetCookieWhitelist(HostContentSettingsMap* map, ControlType type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's confusing to me that we have a method called SetCookieWhitelist that takes a ControlType. It seems to me that this is just an overloaded SetCookieControlType with a string pattern instead of a GURL, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say SetCookieControlTypeForPattern? Overloads are often confusing and also not encouraged by CC.

CONTENT_SETTINGS_TYPE_PLUGINS, kCookies,
GetDefaultBlockFromControlType(type));

// Allow cookies for social media sites when used in first party context
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does this method care whether it's social media or not?

map->SetContentSettingCustomScope(
ContentSettingsPattern::FromString(pattern),
ContentSettingsPattern::FromString("https://firstParty/*"),
CONTENT_SETTINGS_TYPE_PLUGINS, kCookies, CONTENT_SETTING_ALLOW);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this always ALLOW if we're passing a ControlType?

ControlType type = prefs->GetBoolean(kGoogleLoginControlType)
? ControlType::ALLOW
: ControlType::BLOCK;
SetCookieWhitelist(map, type, kGoogleOAuthPattern);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's problematic to set this as a brave cookie plugin type because it will always end up with an override one direction or the other which could potentially conflict with user overrides. It seems better to convert this directly to cookie settings in BravePrefProvider so we only add an override when it's enabled

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's especially problematic because of this https://github.com/brave/brave-core/pull/3784/files#diff-6c160ccdf43d9f23e468a95ec08b4d12R219 which adds an allow override no matter what the setting is

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

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

as per comment we should not be adding any content settings when kGoogleLoginControlType is disabled and the current code just changes what the override is. We should convert it to non-persistent chrome cookie settings instead when we convert everything else in BravePrefProvider

@@ -21,6 +23,21 @@ namespace brave_shields {

namespace {

void SetCookieWhitelistForSocialMedia(HostContentSettingsMap* map,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this method makes more sense as SetCookieWhitelist because it will potentially add other pref based overrides, but ForSocialMedia seems irrelevant to the method and google auth isn't social media anyway. This is just setting a whitelist based on prefs

@bridiver
Copy link
Collaborator

please add tests for this including a test to ensure that no overrides are added when the pref is false


void SetCookieWhitelist(HostContentSettingsMap* map,
ControlType type,
std::string pattern);
Copy link
Contributor

Choose a reason for hiding this comment

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

const std::string& or base::StringPiece

@jumde jumde force-pushed the google_oauth branch 3 times, most recently from 0977c74 to a7be6ec Compare November 3, 2019 19:01
}

void NavigateToPageWithFrame(const std::string& host) {
GURL main_url(https_server_.GetURL(host, "/iframe.html"));
Copy link
Contributor

Choose a reason for hiding this comment

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

pls correct spaces everywhere (or use clang-format)

@@ -17,6 +17,7 @@ const char kFingerprinting[] = "fingerprinting";
const char kBraveShields[] = "braveShields";
const char kReferrers[] = "referrers";
const char kCookies[] = "cookies";
const char kGoogleLogin[] = "google-login";
Copy link
Contributor

Choose a reason for hiding this comment

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

is it used anywhere?

@@ -56,6 +56,8 @@ class BravePrefProvider : public PrefProvider,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const std::string& resource_identifier) override;
void OnCookiePrefsChanged(const std::string& pref);
void SetOAuthCookieException(ContentSettingsType type);
Copy link
Contributor

Choose a reason for hiding this comment

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

unused?


IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest,
IframeGoogleAccountsCookieBlocked) {
BlockGoogleOAuthCookies();
Copy link
Contributor

Choose a reason for hiding this comment

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

we need a test, showing that the new preference doesn't override user choice in per-site shields settings

Copy link
Collaborator

Choose a reason for hiding this comment

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

I actually requested this in the last review and should verify your comment below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -254,6 +261,14 @@ void BravePrefProvider::UpdateCookieRules(ContentSettingsType content_type,
}
}

if (prefs_->GetBoolean(kGoogleLoginControlType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if this overrides user shields settings or not.
Anyway, this method becomes too fat, so i'd prefer to put it into a separate method (or at least add a comment).

Copy link
Collaborator

Choose a reason for hiding this comment

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

it shouldn't override shields settings as long as it comes last, but it should have a test to verify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

although actually we want it to override site shield settings because it should work the same whether the default is block 3p cookies or whether the default is something else and site shield settings are block 3p cookies. In the case where site settings are block all you won't be able to login to anything anyway


void BravePrefProvider::OnCookiePrefsChanged(
const std::string& pref) {
OnCookieSettingsChanged(CONTENT_SETTINGS_TYPE_PLUGINS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

lint - 2 spaces

@jumde jumde changed the title Fix 5869: Google OAuth should work by default [WIP] Fix 5869: Google OAuth should work by default Nov 7, 2019
@jumde jumde added the CI/skip Do not run CI builds (except noplatform) label Nov 7, 2019
@@ -188,7 +212,7 @@ IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest, DefaultCookiesBlocked) {
IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest,
PrefToggleBlockAllToBlockThirdParty) {
DefaultBlockAllCookies();
BlockThirdPartyCookies();
BlockAllThirdPartyCookies();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed so that it's consistent with other helper functions like DefaultBlockAllCookies

@jumde jumde changed the title [WIP] Fix 5869: Google OAuth should work by default Fix 5869: Google OAuth should work by default Nov 12, 2019
@jumde jumde removed the CI/skip Do not run CI builds (except noplatform) label Nov 12, 2019
rules.clear();

if (prefs_->GetBoolean(kGoogleLoginControlType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I desperately desire a comment here, describing the whole situation. So an occasional stranger could have a little chance to understand why and what happens here :)

server->GetURL("a.com", "/"));
}

void BlockThirdPartyCookies(const EmbeddedTestServer* server) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this method name is confusing because it's not obvious in the tests that this is a site override and not the default. I think it's better to pass in the URL instead of the server

@@ -67,21 +82,28 @@ class BraveNetworkDelegateBrowserTest : public InProcessBrowserTest {
browser()->profile(), brave_shields::ControlType::ALLOW, GURL());
}

void AllowCookies() {
void AllowCookies(const EmbeddedTestServer* server) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as below

}

void BlockCookies() {
void BlockCookies(const EmbeddedTestServer* server) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same ^^

void DefaultBlockAllCookies() {
brave_shields::SetCookieControlType(
browser()->profile(), brave_shields::ControlType::BLOCK, GURL());
}

void BlockThirdPartyCookies() {
void BlockAllThirdPartyCookies() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

BlockAllThirdPartyCookies doesn't mean anything different to me than BlockThirdPartyCookies. DefaultBlockThirdPartyCookies maybe?

@@ -298,3 +329,58 @@ IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest,
ExpectCookiesOnHost(embedded_test_server(), "a.com", "");
ExpectCookiesOnHost(embedded_test_server(), "b.com", "");
}

IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest,
IframeGoogleAccountsCookieAllowed) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should these maybe be ThirdPartyGoogleAccountsCookiesAllowed? Instead of Iframe? I know it's basically equivalent, but I think ThirdParty is a better description

@jumde jumde force-pushed the google_oauth branch 2 times, most recently from 29563ff to 0728dde Compare November 14, 2019 21:28
@jumde jumde merged commit cac5b82 into master Nov 15, 2019
@jumde jumde deleted the google_oauth branch November 15, 2019 20:49
@jumde jumde added this to the 1.3.x - Nightly milestone Nov 15, 2019
@bsclifton
Copy link
Member

🎉 !!

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

Successfully merging this pull request may close these issues.

Cannot login to expensify (Google Auth)
4 participants