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

Add ephemeral storage support for network cookies #7387

Merged
merged 2 commits into from
Dec 16, 2020

Conversation

mrobinson
Copy link
Contributor

@mrobinson mrobinson commented Dec 8, 2020

This change adds ephemeral storage support for network cookies
which are cookies that set and sent via HTTP headers.

Resolves brave/brave-browser#12788

Submitter Checklist:

  • There is a ticket for my issue.
  • Used Github auto-closing keywords in the commit message.
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed).
  • Requested a security/privacy review as needed.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

This change relies on browsertests for functionality testing. Later changes enabling ephemeral storage will have a broader testing plan.

@mrobinson mrobinson requested a review from a team as a code owner December 8, 2020 19:06
@mrobinson
Copy link
Contributor Author

Note that the first commit in this PR is: #7154 and this change will be rebased once that PR lands.

@mrobinson mrobinson force-pushed the ephemeral-cookie-storage-mimimal-network-cookies branch from 6ada214 to 4bdbfb4 Compare December 9, 2020 10:01
@mrobinson mrobinson changed the base branch from master to ephemeral-cookie-storage-mimimal December 10, 2020 22:11
@mrobinson mrobinson force-pushed the ephemeral-cookie-storage-mimimal-network-cookies branch from 4bdbfb4 to 40ff9b3 Compare December 10, 2020 23:28
@mrobinson mrobinson changed the title Ephemeral cookie storage mimimal network cookies Add ephemeral storage support for network cookies Dec 10, 2020
@mrobinson mrobinson force-pushed the ephemeral-cookie-storage-mimimal branch from 4fa55ef to fe5a8ec Compare December 11, 2020 09:30
@mrobinson mrobinson force-pushed the ephemeral-cookie-storage-mimimal-network-cookies branch from 40ff9b3 to 2695cfa Compare December 11, 2020 10:08
Base automatically changed from ephemeral-cookie-storage-mimimal to master December 11, 2020 14:20

#define BRAVE_ADDCOOKIEHEADERANDSTART \
if (ShouldUseEphemeralStorage(this)) { \
DCHECK(request()->isolation_info().top_frame_origin().has_value()); \
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 would be better to move this DCHECK here https://github.com/brave/brave-core/pull/7387/files#diff-2b849c37882ef112e7d503ffa24e13c9987f94b8f4cc5ee2870c4f87a357b8c4R24 so it doesn't have to be duplicated and also so you don't need the NOLINT for the weird parens

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove the DCHECK, but:

  1. At line 24 we should have returned early if request()->isolation_info().top_frame_origin().has_value() so the assertion might be a bit redundant.
  2. I think that since the code in the first if-block spans multiple lines it still needs braces and the NOLINT continues to be unavoidable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

braces are only needed if the there is more than one statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I've removed the DCHECK and the brace. Now the NOLINT statement is unnecessary.

ui_test_utils::NavigateToURL(browser(), b_site_set_cookie_url);
ui_test_utils::NavigateToURL(browser(), a_site_ephemeral_storage_url_);

std::string a_cookie =
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we covering all the cases here? For instance what about verifying that 1st-party iframe does not use ephemeral storage with and without being nested in 3p domain?

Copy link
Contributor Author

@mrobinson mrobinson Dec 14, 2020

Choose a reason for hiding this comment

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

Are you referring to the following situation?

  • Top frame:
    • 3rd party iframe
      • 1st party iframe

Copy link
Collaborator

Choose a reason for hiding this comment

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

correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a new browsertest for this functionality.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that was the only one that is missing, but please check with @pes10k and add any others in a follow-up


IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest,
NavigationCookiesArePartitioned) {
AllowAllCookies();
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have a ticket for connecting this to block3p shield setting?

Copy link
Contributor Author

@mrobinson mrobinson Dec 14, 2020

Choose a reason for hiding this comment

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

Can you confirm whether or not one of these tickets is what you are referring to?

I believe that the first bug covers the situation where cookies are blocked in brave shield.

if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage))
return false;

const net::IsolationInfo& isolation_info =
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing headers for isolation info, and request https://google.github.io/styleguide/cppguide.html#Include_What_You_Use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

->SetEphemeralCanonicalCookieAsync( \
std::move(cookie), request_->url(), \
request()->isolation_info().top_frame_origin()->GetURL(), options, \
base::BindOnce(&URLRequestHttpJob::OnSetCookieResult, \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@mrobinson mrobinson force-pushed the ephemeral-cookie-storage-mimimal-network-cookies branch from 2695cfa to f02a83a Compare December 15, 2020 20:46
@mrobinson
Copy link
Contributor Author

@bridiver I've pushed a new version of the branch which I believe addresses all your review comments. Please take a look.

@mrobinson
Copy link
Contributor Author

Thanks very kindly for the reviews.

The two failures look like an unrelated issue with the ios bot (a failure in vpython src/third_party/depot_tools/update_depot_tools_toggle.py and the ignorable [AdsWrapperTest testPreferencePersistance] test failure). The post-init failure is a lint failure in code that this change does not touch. Going to land this one.

@mrobinson mrobinson merged commit 61efb6a into master Dec 16, 2020
@mrobinson mrobinson deleted the ephemeral-cookie-storage-mimimal-network-cookies branch December 16, 2020 13:37
@mrobinson mrobinson added this to the 1.20.x - Nightly milestone Dec 16, 2020
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.

Add ephemeral storage support for network cookies
3 participants