(url)
| 5 | import { requireEnv, upstreamError } from './_common/upstream.js'; |
| 6 | |
| 7 | const 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 | |
| 34 | const urlHaus = async (url) => { |
| 35 | const { hostname } = parseTarget(url); |
no test coverage detected