Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Add support for SafeBrowsing via request #1332

Closed
wants to merge 3 commits into from

Conversation

Brandon-T
Copy link
Collaborator

@Brandon-T Brandon-T commented Aug 6, 2019

Fixes #483

There are two ways to implement safe-browsing. One is via a request to get the list and the other is to download the sb database and query against it via hashes and hash prefixes.

The ticket stated "via proxy" so I proxy the requests instead of checking against hashes.

NOTE: I am using my own API key atm for testing it.. It's included in this PR so others can test it without making one.. However, before MERGING, I need to get one from somewhere or perhaps the CI/CD will manage the keys? Not sure.

We will probably also want to get a design for the "Blocked" screen for when a request is blocked?

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • My patch or PR title has a standard commit message that looks like Fix #123: This fixes the shattered coffee cup! (or No Bug: <message> if no relevant ticket)
  • Unit Tests are updated to cover new or changed functionality
  • User-facing strings use NSLocalizableString()
  • New files have MPL-2.0 license header.

Test Plan:

Screenshots:

Reviewer Checklist:

  • PR is linked to an issue via Zenhub.
  • Issues are assigned to at least one epic.
  • Issues include necessary QA labels:
    • QA/(Yes|No)
    • release-notes/(include|exclude)
    • bug / enhancement
  • Necessary security reviews have taken place.
  • Adequate test coverage exists to prevent regressions.
  • Adequate test plan exists for QA to validate (if applicable)

@discardableResult
public static func threatMatches(urls: [URL], session: URLSession = .shared, _ completion: @escaping (Response, Error?) -> Void) throws -> URLSessionDataTask {

let apiKey = "AIzaSyDeglae_dQQyQuRNk1jPq5R5--jBy21H5o"
Copy link
Contributor

Choose a reason for hiding this comment

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

As a rule of thumb, never include API keys in the source code. We need to use the safe-browsing proxy for this. See: https://github.com/brave/handbook/blob/master/development/aws.md - This applies for all keys.

@jumde
Copy link
Contributor

jumde commented Aug 6, 2019

Please open a security review for this issue, we need multiple eyes on this feature to make sure its implemented correctly.

Thanks for such a quick turn around on this @Brandon-T

case unknown = "PLATFORM_TYPE_UNSPECIFIED"

/// Threat posed to Windows.
case windows = "WINDOWS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need other platforms here? Just iOS should work.

@jumde
Copy link
Contributor

jumde commented Aug 6, 2019

@Brandon-T - test suite for safe browsing:

https://testsafebrowsing.appspot.com/ - Tests with malicious sub-resources are not working correctly.


@discardableResult
public static func threatMatches(urls: [URL], session: URLSession = .shared, _ completion: @escaping (Response, Error?) -> Void) throws -> URLSessionDataTask {

Copy link
Contributor

Choose a reason for hiding this comment

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

This is using the Lookup API, we should use the recommended Update API to reduce the performance impact and not sending hash for every URL to the google servers: https://developers.google.com/safe-browsing/v4/update-api

@Brandon-T
Copy link
Collaborator Author

Hey, these are my own personal API keys that I created on my own account. I can revoke them at any given time as they are only attached to my account. It was only included so we can test the PR.. Was not aware we had a proxy but I’ll be rewriting this PR then because there’s no available Swift APIs or Libraries for “Update API”, etc..

I will open a new PR tomorrow with everything rewritten and working with the proxy instead of my own keys.

@Brandon-T Brandon-T closed this Aug 6, 2019
@jhreis jhreis deleted the feature/SafeBrowsing branch August 7, 2019 01:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update error/warning page communication and iconography & use Google Safe Browsing via proxy
2 participants