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

Search result ad click confirmation. #13444

Closed
wants to merge 2 commits into from
Closed

Search result ad click confirmation. #13444

wants to merge 2 commits into from

Conversation

aseren
Copy link
Collaborator

@aseren aseren commented May 24, 2022

Spec: https://docs.google.com/document/d/1ncuyw0Yv_qawR-FM0_e1r4pNU2pGDhS49KfwfHqqrqs/edit#heading=h.txs9x3akav5

Description is here: https://github.com/brave/security/issues/876

Resolves brave/brave-browser#23002

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • 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)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • 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:

Test case 1

  • Turn off Brave Private Ads.
  • Do several search requests on search.brave.com until an ad is shown in a SERP.
  • Click on the ad link.
  • Check that the page navigates to https://search.anonymous.ads.brave.com/v3/click and then navigates to the ad landing page using a server redirect.

Test case 2

  • Turn on Brave Private Ads.
  • Do several search requests on search.brave.com until an ad is shown in a SERP.
  • Check that an ad viewed event is triggered. There should be Viewed search result ad with placement id message in rewards-internals log.
  • Click on the ad link.
  • Check that the page navigates to the ad landing page without navigation to https://search.anonymous.ads.brave.com/v3/click.
  • Check that an ad clicked event is triggered. There should be Clicked search result ad with placement id message in rewards-internals log.

@aseren aseren requested review from a team as code owners May 24, 2022 16:18
@aseren aseren requested a review from tmancey May 24, 2022 16:21
@aseren aseren requested a review from a team as a code owner May 25, 2022 10:04
@aseren aseren requested a review from goodov May 25, 2022 10:41
goodov
goodov previously approved these changes May 25, 2022
@aseren aseren mentioned this pull request May 25, 2022
25 tasks
@diracdeltas diracdeltas added the CI/run-network-audit Run network-audit label May 25, 2022
fmarier
fmarier previously approved these changes May 25, 2022
Copy link
Member

@fmarier fmarier left a comment

Choose a reason for hiding this comment

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

Updates to chromium_src/net/tools/transport_security_state_generator/input_file_parsers.cc look good.

tmancey
tmancey previously approved these changes May 27, 2022

request->url = *search_result_ad_target_url;
request->credentials_mode = network::mojom::CredentialsMode::kOmit;
request->referrer_policy = net::ReferrerPolicy::NO_REFERRER;
Copy link
Collaborator Author

@aseren aseren Jun 6, 2022

Choose a reason for hiding this comment

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

Removed site_for_cookies changing code.
Also added credentials_mode and referrer_policy modification as suggested here: https://github.com/brave/security/issues/876#issuecomment-1139044261

cc @ShivanKaul @diracdeltas @bridiver

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aseren not sure that is necessary. Just to verify, this url is the ad landing page, right? The actual confirmation happens in the background somewhere from MaybeTriggerSearchResultAdClickedEvent, correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually looking more closely I think this functionality is not correct. We should not be navigating to the click confirmation link here, we should be navigating directly to the landing page and the confirmation should happen in the background from a non-profile context

Copy link
Collaborator

@bridiver bridiver Jun 8, 2022

Choose a reason for hiding this comment

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

so after talking to @pes10k we don't need to do anything special here in terms of referrer, credentials mode, etc..., but there are other issues here because we have all this extra infrastructure and complications that aren't necessary if we're just following the click-through url. We don't need to parse ad info from the page and associate it with the tab, we can just put everything we need in the url.

Copy link
Member

@diracdeltas diracdeltas Jun 8, 2022

Choose a reason for hiding this comment

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

we should be navigating directly to the landing page and the confirmation should happen in the background from a non-profile context

just a reminder if this functionality is enabled in Tor windows, then any background requests associated with a confirmation that happens in a Tor window needs to still go through Tor; otherwise the ads server can link the user's real IP address to the ID of an ad that they saw in a Tor window

Copy link
Collaborator

Choose a reason for hiding this comment

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

also seriously please add a test for Tor and private

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@bridiver bridiver Jun 9, 2022

Choose a reason for hiding this comment

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

I did look at the factory code and it will be created for incognito and it will have a null AdsService

Copy link
Collaborator

Choose a reason for hiding this comment

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

The way to prevent it from being created in incognito is to return null in SearchResultAdServiceFactory::BuildServiceInstanceFor

Copy link
Collaborator Author

@aseren aseren Jun 10, 2022

Choose a reason for hiding this comment

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

When requesting service we run KeyedServiceFactory::GetServiceForContext https://source.chromium.org/chromium/chromium/src/+/main:components/keyed_service/core/keyed_service_factory.cc;l=56?q=KeyedServiceFactory::GetServiceForContext&ss=chromium%2Fchromium%2Fsrc

GetContextToUse call eventually goes to BrowserContextKeyedServiceFactory::GetBrowserContextToUse which returns nullptr for incognito profiles:
https://source.chromium.org/chromium/chromium/src/+/main:components/keyed_service/content/browser_context_keyed_service_factory.cc;l=64

To create service in incognito we need to override GetBrowserContextToUse method, like here:
https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/safe_browsing/advanced_protection_status_manager_factory.cc;l=52

diracdeltas
diracdeltas previously approved these changes Jun 7, 2022
Copy link
Member

@diracdeltas diracdeltas left a comment

Choose a reason for hiding this comment

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

still have some concerns about the server side of this but this PR lgtm

DCHECK(search_result_ad->target_url.is_valid() &&
search_result_ad->target_url.SchemeIs(url::kHttpsScheme));

TriggerSearchResultAdClickedEvent(search_result_ad->Clone());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added triggering of an ad click event as it was removed during refactoring.

@wknapik wknapik dismissed stale reviews from diracdeltas, tmancey, fmarier, and goodov via cc4b150 June 23, 2022 14:31
DCHECK(web_contents);

if (!search_result_ad_service || !request.request_initiator ||
!request.has_user_gesture || !request.is_outermost_main_frame ||
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 you checking user_gesture here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

also if we only care about the main frame, why are you using URLLoaderThrottle instead of NavigationThrottle?

Copy link
Collaborator Author

@aseren aseren Oct 11, 2022

Choose a reason for hiding this comment

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

why are you checking user_gesture here?

I thought there was such a requirement. Will double check it.

also if we only care about the main frame, why are you using URLLoaderThrottle instead of NavigationThrottle?

Yes, NavigationThrottle is also possible here. I will change


SessionID tab_id = sessions::SessionTabHelper::IdForTab(web_contents);
content::WebContents* original_web_contents =
web_contents->GetFirstWebContentsInLiveOriginalOpenerChain();
Copy link
Collaborator

Choose a reason for hiding this comment

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

the tab id does not change so this is not necessary

Copy link
Collaborator Author

@aseren aseren Oct 21, 2022

Choose a reason for hiding this comment

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

Link target can be opened in a new tab if it has target="_blank” attribute. In this case, tab id is changed.
Anyway, in the latest code we moved from KeyedService to TabHelper, so we don’t use Tab id values at all.

@aseren aseren requested a review from a team as a code owner October 21, 2022 16:55
@aseren aseren force-pushed the issues/23002 branch 2 times, most recently from a9b393a to fd78efc Compare October 22, 2022 00:15
@aseren
Copy link
Collaborator Author

aseren commented Nov 30, 2022

Decline the PR, because basing on the latest spec changes, https://search.anonymous.ads.brave.com/v3/click request interception is not required:
https://docs.google.com/document/d/1ncuyw0Yv_qawR-FM0_e1r4pNU2pGDhS49KfwfHqqrqs/edit#heading=h.hnm67cu7xxpw

@aseren aseren closed this Nov 30, 2022
@aseren
Copy link
Collaborator Author

aseren commented Dec 1, 2022

The new PR, which is based on the recent spec changes: #16179

@tmancey tmancey deleted the issues/23002 branch February 3, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-network-audit Run network-audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement clicked confirmation for Brave Search Ads
6 participants