# safe-browse-url-lookup

> A simplified wrapper for Google's Safe Browsing API v4 to check whether a URL is malicious or not. See https://developers.google.com/safe-browsing/v4/ for more information.

Latest version **0.1.1** (published 2021-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install safe-browse-url-lookup
pnpm add safe-browse-url-lookup
yarn add safe-browse-url-lookup
bun add safe-browse-url-lookup
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-01-09 |
| First published | 2017-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.9.0 |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Ferdinand Mütsch |
| Maintainers | n1try |

## Links

- npm: https://www.npmjs.com/package/safe-browse-url-lookup
- Repository: https://github.com/n1try/safe-browse-url-lookup
- npm.io page: https://npm.io/package/safe-browse-url-lookup

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Recent versions

- 0.1.1 (latest) — 2021-01-09
- 0.1.0 — 2020-01-08
- 0.0.4 — 2018-01-31
- 0.0.3 — 2017-07-02
- 0.0.2 — 2017-07-01
- 0.0.1 — 2017-07-01

## README

# safe-browse-url-lookup

## What is this?
This is a simplified wrapper for NodeJS for Google's Safe Browsing API v4 to check whether a URL is malicious or not. Refer to the [official documentation](https://developers.google.com/safe-browsing/v4/) for more information.

Currently this library only implements lookup functionality for URLs, where all types of threats are being requested. 

## How to use
First, you need to get an API key from the [Google Cloud Developer Console](https://console.cloud.google.com/apis/api/safebrowsing.googleapis.com/credentials). 

### Check single URL for safety
You can test the library with Google's test URL (see example below) or a domain listed at [OpenFish](https://openphish.com/).

```javascript
const lookup = require('safe-browse-url-lookup')({ apiKey: '<YOU GOOGLE API KEY HERE>' });

lookup.checkSingle('http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/')
    .then(isMalicious => {
        console.log(isMalicious ? 'Hands off! This URL is evil!' : 'Everything\'s safe.');
    })
    .catch(err => {
        console.log('Something went wrong.');
        console.log(err);
    });
```

### Check multiple URLs at once
```javascript
const lookup = require('safe-browse-url-lookup')({ apiKey: '<YOU GOOGLE API KEY HERE>' });

lookup.checkMulti(['https://muetsch.io', 'https://kit.edu'])
    .then(urlMap => {
        for (let url in urlMap) {
            console.log(urlMap[url] ? `${url} is evil!` : `${url} is safe.`);
        }
    })
    .catch(err => {
        console.log('Something went wrong.');
        console.log(err);
    });
```

The promise returns a map from URLs to boolean values, where `true` means a match (= a malicious URL).
```json
{
    "https://muetsch.io": false,
    "https://kit.edu": false
}
```

### Options
To initialize the library, you call its exported function with an options object that can have the following properties.

* `apiKey` - It's mandatory to pass your API key you got from the Google Developer's Console
* `clientId` _[optional]_ - A client ID that (hopefully) uniquely identifies the client implementation of the Safe Browsing API. ([Reference](https://developers.google.com/safe-browsing/v4/reference/rest/v4/ClientInfo)). If not specified, a default value is used.
* `clientVersion` _[optional]_ - The version of the client implementation. If not specified, a default value is used.

## Other Implementations
* [google/safebrowsing](https://github.com/google/safebrowsing) (`Go`)
* [junv/safebrowsing](https://github.com/junv/safebrowsing) (`Python`)

## Contribute
Feel free to implement the remaining API features and make a PR! 

## License
MIT @ [Ferdinand Mütsch](https://muetsch.io)

---
_Source: https://npm.io/package/safe-browse-url-lookup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
