MCPcopy
hub / github.com/lissy93/web-check / safeBrowsing

Function safeBrowsing

api/threats.js:7–32  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

5import { requireEnv, upstreamError } from './_common/upstream.js';
6
7const safeBrowsing = async (url) => {
8 const auth = requireEnv('GOOGLE_CLOUD_API_KEY', 'Google Safe Browsing');
9 if (auth.skipped) return auth;
10 try {
11 const res = await httpPost(
12 `https://safebrowsing.googleapis.com/v4/threatMatches:find?key=${auth.value}`,
13 {
14 threatInfo: {
15 threatTypes: [
16 'MALWARE',
17 'SOCIAL_ENGINEERING',
18 'UNWANTED_SOFTWARE',
19 'POTENTIALLY_HARMFUL_APPLICATION',
20 'API_ABUSE',
21 ],
22 platformTypes: ['ANY_PLATFORM'],
23 threatEntryTypes: ['URL'],
24 threatEntries: [{ url }],
25 },
26 },
27 );
28 return res.data?.matches ? { unsafe: true, details: res.data.matches } : { unsafe: false };
29 } catch (error) {
30 return upstreamError(error, 'Google Safe Browsing');
31 }
32};
33
34const urlHaus = async (url) => {
35 const { hostname } = parseTarget(url);

Callers 1

threatsHandlerFunction · 0.85

Calls 3

requireEnvFunction · 0.90
httpPostFunction · 0.90
upstreamErrorFunction · 0.90

Tested by

no test coverage detected