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

Ads confirmations should not be sent if the wildcard is in a forbidden part of the URL #24076

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Jun 8, 2024

Resolves brave/brave-browser#38683

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • 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 wiki
    • npm run presubmit wiki, 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:

  • Confirm that catalog creative set conversions are discarded if the url_pattern contains asterisk wildcard(s) in eTLD+1
  • Confirm that catalog creative set conversions are discarded if the url_pattern contains question mark wildcard(s) in eTLD+1
  • Confirm that catalog creative set conversions are discarded if the url_pattern does not have the same domain and registry as the target_url
  • Confirm that catalog creative instances are discarded if the target_url contains asterisk wildcard(s) in eTLD+1
  • Confirm that catalog creative instances are discarded if the target_url contains question mark wildcard(s) in eTLD+1
  • Confirm that catalog creative instances are discarded if the imageUrl contains asterisk wildcard(s) in eTLD+1
  • Confirm that catalog creative instances are discarded if the imageUrl contains question mark wildcard(s) in eTLD+1

@tmancey tmancey self-assigned this Jun 8, 2024
@tmancey tmancey requested a review from a team as a code owner June 8, 2024 08:10
@tmancey tmancey marked this pull request as draft June 8, 2024 08:10
@tmancey tmancey force-pushed the issues/38683 branch 9 times, most recently from 812f05e to d33d511 Compare June 11, 2024 11:50
@tmancey tmancey marked this pull request as ready for review June 11, 2024 11:50
@tmancey tmancey requested a review from tackley June 11, 2024 11:50
@tmancey tmancey force-pushed the issues/38683 branch 7 times, most recently from b38363f to 813aa29 Compare June 11, 2024 13:35
@tmancey tmancey force-pushed the issues/38683 branch 2 times, most recently from 5a93e5b to efbbb48 Compare June 11, 2024 17:10
@tmancey tmancey force-pushed the issues/38683 branch 8 times, most recently from f258d8d to 62d387b Compare June 13, 2024 17:50
Copy link
Contributor

[puLL-Merge] - brave/brave-core@24076

Here is my review of the pull request:

Description

This PR makes several changes to improve URL validation and filtering in the Brave Ads codebase. The main motivations appear to be:

  1. Strengthen checks for which URLs are considered supported for ads
  2. Ensure conversion URLs match the domain of the target ad URL
  3. Filter out unsupported URLs early in the catalog parsing process

Security Hotspots

  1. The ShouldSupportUrl function in url_util.cc is a critical security control point that determines which URLs will be allowed for ads. The changes here tighten the validation to exclude more categories of invalid or potentially unsafe URLs like IP addresses, URLs with port numbers, username/password, and wildcard eTLD+1s. This significantly reduces the risk of supporting malicious URLs.

  2. The changes in catalog_url_request_json_reader.cc to call ShouldSupportUrl on various URLs while parsing the catalog JSON help filter out bad URLs early before they get stored. This is a proactive security measure.

  3. The new logic in catalog_url_request_json_reader.cc to remove conversion URLs that don't match the domain of the creative target URL is an important fix. Previously, an attacker could potentially specify an arbitrary conversion URL. Now it must match the ad's domain.

Changes

Changes

url_util.cc:

  • Rename DoesSupportUrl to ShouldSupportUrl
  • Rewrite ShouldSupportUrl to perform more extensive URL validation using helper functions from the new url_util_internal.cc file.

url_util_internal.cc:

  • Add new file with helper functions for advanced URL parsing and validation used by ShouldSupportUrl

catalog_url_request_json_reader.cc:

  • Call ShouldSupportUrl on various URLs while parsing the catalog JSON
  • Filter out conversion URLs that don't match the domain of the creative's target URL

url_util_unittest.cc:

  • Update tests for renamed ShouldSupportUrl function and add many new test cases

url_util_internal_unittest.cc:

  • Add new tests for the internal URL helper functions

Overall this is a significant security improvement to URL validation in Brave Ads. The changes are well structured and tested. I did not see any major issues or overlooked vulnerabilities. Nice work!

Let me know if you have any other questions!

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.

Tests look good to me.

@tmancey tmancey force-pushed the issues/38683 branch 3 times, most recently from a432a7d to b1e7dd5 Compare June 13, 2024 22:49
@tmancey tmancey force-pushed the issues/38683 branch 2 times, most recently from ee43ebf to 1c20375 Compare June 13, 2024 23:09
@tmancey tmancey enabled auto-merge June 13, 2024 23:24
@tmancey tmancey merged commit 5c7a57a into master Jun 14, 2024
19 checks passed
@tmancey tmancey deleted the issues/38683 branch June 14, 2024 00:24
@github-actions github-actions bot added this to the 1.69.x - Nightly milestone Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants