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

STP #403

Merged
merged 2 commits into from
Apr 18, 2019
Merged

STP #403

merged 2 commits into from
Apr 18, 2019

Conversation

jumde
Copy link
Contributor

@jumde jumde commented Sep 5, 2018

fix brave/brave-browser#803
fix brave/brave-browser#3025
related brave/brave-browser#3888

Description

Smart Tracking Protection aims to block trackers that use storage in the first party context to track users (see: https://webkit.org/blog/8311/intelligent-tracking-prevention-2-0/ - First Party Bounce Trackers).

How it works:

  1. Tracker list (csv) will be generated by an offline tracker that @snyderp worked on.
  2. This list will be available as part of the Tracking Protection component. (Issue 2980: Creating an initial list of storage trackers for STP tracking-protection#26)
  3. STP will monitor redirect chains, and on an automated redirect (no user interaction) if tracking protection is enabled , access to storage apis (cookie, local storage, session storage, indexedDB, WebSQL) will be blocked.

For more info refer to:
Spec - https://docs.google.com/document/d/1jolVinFcN4sl0z1zdIHyGdV594Yz6RY4zssnm_VJOYg/edit#

Slide deck -
https://docs.google.com/presentation/d/1eykguzVpzAUSUWibabXEwUYsxES44eN61phTQ0fsgL8/edit#slide=id.p

Please feel free to DM/email me if you have any additional questions

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).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests && npm run test-security) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Needed or QA/No-QA-Needed) to include the closed issue in milestone

Test Plan:

Navigate to Brave's data directory and create a file: StorageTrackingProtection.dat in afalakplffnnnlkncjhbmahjfjhmlkal/1.0.9/1

$ cat StorageTrackingProtection.dat
browsertesting.orgfree.com,

Test Domains

browsertesting.freevar.com/redirect_stp.html -> browsertesting.orgfree.com/stp.html -> browsertesting.ueuo.com/stp.html -> browsertesting.freevar.com/final.html

Repro Steps

For Devs - Enable STP runtime and buildflags

  1. In brave_browser/lib/config.js add an arg brave_stp_enabled: true
  2. In brave_browser/package.json add --enable-smart-tracking-protection to the start script to enable stp

PR to add runtime switch to brave-browser: brave/brave-browser#3026

Feature test:

  1. Open Brave and navigate to http://browsertesting.freevar.com/redirect_stp.html
  2. The navigation has a 5 second time window (for demo purposes)
  3. Once the navigation is complete. Open http://browsertesting.orgfree.com/.
  4. Navigate to Developer Tools > Application. Verify none of the storage entries (localStorage, sessionStorage, IndexedDB, WebSQL, Cookies) are populated
  5. Open http://browsertesting.ueuo.com
  6. Navigate to Developer Tools > Application. All of the storage entries should be populated.
  7. Navigate to http://browsertesting.freevar.com/. Disable Ads and Trackers blocked in shields
  8. Navigate to http://browsertesting.freevar.com/redirect_stp.php. Storage entries should be available for orgfree.com

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

@jumde jumde changed the title WIP: Preventing data storage from first parties using ObservableProvider WIP: STP Sep 17, 2018
@@ -30,6 +38,31 @@ void BraveResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
content::ResourceContext* resource_context,
ResourceType resource_type,
std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) {

CHECK(g_brave_browser_process->tracking_protection_service()->IsInitialized());
Copy link
Collaborator

Choose a reason for hiding this comment

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

wy are we doing this in AppendStandardResourceThrottles? This code isn't doing anything with resource throttles

@@ -54,6 +54,14 @@ void TrackingProtectionService::Cleanup() {
tracking_protection_client_.reset();
}

std::vector<std::string> TrackingProtectionService::addFirstPartyTrackers() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Method names should be capitalized
These two methods don't really make sense to me. Why do we have add/remove instead of just providing a list?

HostContentSettingsMap* contentSettingsMap = io_data->GetHostContentSettingsMap();

if (!g_brave_browser_process->tracking_protection_service()->addFirstPartyTrackers().empty()) {
for(std::string tracker : g_brave_browser_process->tracking_protection_service()->addFirstPartyTrackers()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think these should go into user content settings. That will potentially change or wipe out user specified settings

Copy link
Collaborator

Choose a reason for hiding this comment

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

these need to come from a separate content settings provider as we discussed in slack

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.

see comments

CHECK(g_brave_browser_process->tracking_protection_service()->IsInitialized());

bool allow_brave_shields = brave_shields::IsAllowContentSetting(
host_content_settings_map_, top_origin_url, top_origin_url, 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.

shouldn't this use the primary and secondary url for the check?

return ChromeRenderMessageFilter::OnMessageReceived(message);
}

bool BraveRenderMessageFilter::ShouldStoreState(const GURL& origin_url,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are there two separate checks? ShouldStoreState in BraveRenderMessageFilter and then ShouldStoreState in TrackingProtectionService? I think TrackingProtectionService should encapsulate the whole check

service_manager::mojom::ServiceRequest* service_request) {
int id = host->GetID();
Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
- host->AddFilter(new ChromeRenderMessageFilter(id, profile));
Copy link
Collaborator

Choose a reason for hiding this comment

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

patching is not necessary for this, you can do a chromium src redefine

bool* allowed) {
*allowed = ShouldStoreState(origin_url, top_origin_url);

BrowserThread::PostTask(
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should call the superclass method here and just pass it a different bool if we don't care about the result. We don't want to have to keep this in sync with upstream changes

const GURL& origin_url) {

if (!first_party_storage_trackers_initailized_) {
LOG(INFO) << "First party storage trackers not initialized";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

INFO till the PR in tracking-protection repo is merged.

darkdh
darkdh previously requested changes Oct 15, 2018
Copy link
Member

@darkdh darkdh left a comment

Choose a reason for hiding this comment

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

I don't enumerate all the lints that requires <=80 chars, too many of them.
Also see other comments

@jumde jumde force-pushed the stp branch 4 times, most recently from 945732d to 35e3501 Compare April 11, 2019 03:52
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::Bind(&TrackingProtectionHelper::SetStartingSiteForRenderFrame,
base::Unretained(this), handle->GetURL(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Unretained is not allowed here, you want weak pointers

}
}

void TrackingProtectionHelper::DeleteRenderFrameKey(int render_process_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

This and other IO functions now can be free functions, not methods.

iefremov
iefremov previously approved these changes Apr 11, 2019
@bsclifton
Copy link
Member

@jumde does this need an official security review? I didn't see one. I know @diracdeltas and likely others are aware of the change, but wanted to see if we could capture something formally

bsclifton
bsclifton previously approved these changes Apr 16, 2019
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.

Ran through test plan - works great! Verified it builds + all tests pass (updated PR template). Let comment about security review - let's create one if needed (even if it's just a formality). Great work 😄

1. Parse the FirstPartyTracker list provided by the `tracking-protection` extension.
2. On any request to Store data (Cookies, localStorage, sessionStorage, WebSQL, indexedDB)
  1. Check if the Shield Settings and tracker blocking is allowed for the site that initiated the redirects
  2. Check if the site is in the Storage trackers list.
3. Deny if the URL is found in the tracker list.

This feature is currently gated behind a BUILD flag and a runtime flag. The flags are disabled by default

auditors: @bridiver, @iefremov
@jumde jumde merged commit 7cdda52 into master Apr 18, 2019
@jumde jumde added this to the 0.65.x - Nightly milestone Apr 18, 2019
char* thirdPartyHosts =
tracking_protection_client_->findFirstPartyHosts(base_host.c_str());
std::string thirdPartyHosts =
tracking_protection_client_->findFirstPartyHosts(base_host.c_str());
Copy link
Member

@bsclifton bsclifton Apr 18, 2019

Choose a reason for hiding this comment

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

this is returning char* that was allocated on heap... it gets leaked, because it's never cleaned up. Delete should still be called

A work-around for this (if you wanted to use std::string) could be:

char* thirdPartyHosts =
    tracking_protection_client_->findFirstPartyHosts(base_host.c_str());
std::string thirdPartyHostsStr = std::string(thirdPartyHosts);
delete []thirdPartyHosts;
// use thirdPartyHostsStr now instead

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 buildflag and runtime switch to disable STP by default Block storage from first party trackers
5 participants