https://github.com/alexruperez/safebrowsing
Protect your users against malware and phishing threats using Google Safe Browsing
https://github.com/alexruperez/safebrowsing
api-wrapper google google-safebrowsing malware-detection phising protect-your-privacy safe-browsing safebrowsing security swift swift-library threats
Last synced: 3 months ago
JSON representation
Protect your users against malware and phishing threats using Google Safe Browsing
- Host: GitHub
- URL: https://github.com/alexruperez/safebrowsing
- Owner: alexruperez
- License: mit
- Created: 2018-03-26T19:34:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-04T10:35:56.000Z (almost 7 years ago)
- Last Synced: 2025-02-01T16:01:48.985Z (11 months ago)
- Topics: api-wrapper, google, google-safebrowsing, malware-detection, phising, protect-your-privacy, safe-browsing, safebrowsing, security, swift, swift-library, threats
- Language: Swift
- Homepage: https://developers.google.com/safe-browsing
- Size: 93.8 KB
- Stars: 21
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SafeBrowsing
[](http://twitter.com/alexruperez)
[](http://cocoapods.org/pods/SafeBrowsing)
[](http://cocoapods.org/pods/SafeBrowsing)
[](http://cocoapods.org/pods/SafeBrowsing)
[](https://swift.org)
[](https://github.com/Carthage/Carthage)
[](https://github.com/apple/swift-package-manager)
[](https://travis-ci.org/alexruperez/SafeBrowsing)
[](https://codecov.io/gh/alexruperez/SafeBrowsing)
### Protect your users against malware and phishing threats using Google Safe Browsing

## 🌟 Features
- [x] Check multiple URLs asynchronously
- [x] Check single URL asynchronously
- [x] Check single URL synchronously
- [x] Open URL in Safari only if it's safe
- [x] UIApplication extension
- [x] UIViewController extension
- [x] SFSafariViewController compatible
## 📲 Installation
SafeBrowsing is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'SafeBrowsing'
```
#### Or you can install it with [Carthage](https://github.com/Carthage/Carthage):
```ogdl
github "alexruperez/SafeBrowsing"
```
#### Or install it with [Swift Package Manager](https://swift.org/package-manager/):
```swift
dependencies: [
.package(url: "https://github.com/alexruperez/SafeBrowsing.git", from: "0.1.0")
]
```
## 🛠 Configuration
### Required configuration
Just [enable Google Safe Browsing API](https://console.developers.google.com/apis/api/safebrowsing.googleapis.com/overview) and [get your API key](https://console.cloud.google.com/apis/credentials).
```swift
SafeBrowsing.apiKey = "YOUR_API_KEY_HERE"
```
#### Advanced optional configuration
You can easily customize [threat types](https://developers.google.com/safe-browsing/v4/reference/rest/v4/ThreatType), [platform types](https://developers.google.com/safe-browsing/v4/reference/rest/v4/PlatformType) or [threat entry types](https://developers.google.com/safe-browsing/v4/reference/rest/v4/ThreatEntryType).
```swift
SafeBrowsing.clientId = "YOUR_CLIENT_ID" // By default your bundle identifier.
SafeBrowsing.clientVersion = "YOUR_CLIENT_VERSION" // By default your bundle short version.
SafeBrowsing.threatTypes = [.malware, .socialEngineering, .unwantedSoftware, .potenciallyHarmfulApplication]
SafeBrowsing.platformTypes = [.any]
SafeBrowsing.threatEntryTypes = [.url, .executable]
```
## 🐒 Usage
#### Check multiple URLs asynchronously:
```swift
SafeBrowsing.isSafe([anURL, anotherURL]) { isSafe, error in
// Your code here
}
```
#### Check single URL asynchronously:
```swift
SafeBrowsing.isSafe(anURL) { isSafe, error in
// Your code here
}
```
#### Check single URL synchronously:
###### **Caution**: Don't call it in main thread
```swift
if SafeBrowsing.isSafe(anURL) {
// Your code here
}
```
#### Open URL in Safari only if it's safe:
```swift
SafeBrowsing.safeOpen(anURL) { opened, error in
// Your code here
}
```
#### Open URL in SFSafariViewController only if it's safe:
```swift
SafeBrowsing.safeOpenInSafariViewController(anURL, over: aViewController, animated: true) { opened, error in
// Your code here
}
```
### UIApplication extension
Yes, you can use SafeBrowsing with UIApplication, just like [open(_:options:completionHandler:)](https://developer.apple.com/documentation/uikit/uiapplication/1648685-open) method works.
You also have all isSafe(_:) methods available with this extension.
```swift
UIApplication.shared.safeOpen(anURL) { opened, error in
// Your code here
}
```
#### Open URL in SFSafariViewController only if it's safe:
```swift
UIApplication.shared.safeOpenInSafariViewController(anURL, over: aViewController, animated: true) { opened, error in
// Your code here
}
```
#### UIViewController extension
```swift
aViewController.safeOpenInSafariViewController(anURL, animated: true) { opened, error in
// Your code here
}
```
### Testing Google Safe Browsing
```swift
let testingURL = URL(string: "http://malware.testing.google.test/testing/malware/")!
SafeBrowsing.isSafe(testingURL) { isSafe, error in
print(error.debugDescription)
}
```
## ❤️ Etc.
* Contributions are very welcome.
* Attribution is appreciated (let's spread the word!), but not mandatory.
## 👨💻 Authors
[alexruperez](https://github.com/alexruperez), contact@alexruperez.com
## 👮♂️ License
SafeBrowsing is available under the MIT license. See the LICENSE file for more info.