| import axios from 'axios'; |
|
|
| |
| const TEST_PHISHING_URLS = [ |
| 'http://testsafebrowsing.appspot.com/', |
| 'http://testsafebrowsing.appspot.com/s/phishing.html', |
| 'http://testsafebrowsing.appspot.com/s/malware.html', |
| 'https://testsafebrowsing.appspot.com/s/phishing.html', |
| 'http://ianfette.org', |
| 'http://www.ianfette.org', |
| 'http://malware.testing.google.test/testing/malware/', |
| ]; |
|
|
| export async function checkSafeBrowsing(url: string) { |
| const API_KEY = process.env.GOOGLE_SAFE_BROWSING_API_KEY; |
|
|
| |
| if (!API_KEY || API_KEY === 'your_key_here') { |
| if (TEST_PHISHING_URLS.some(testUrl => url.includes(testUrl))) { |
| return { |
| matches: true, |
| mock: true, |
| details: { |
| threatType: "SOCIAL_ENGINEERING", |
| platformType: "ANY_PLATFORM" |
| } |
| }; |
| } |
| return { matches: false, skipped: true }; |
| } |
|
|
| try { |
| const response = await axios.get( |
| `https://safebrowsing.googleapis.com/v5/urls:search`, |
| { |
| params: { |
| key: API_KEY, |
| urls: url |
| } |
| } |
| ); |
|
|
| |
| const hasMatches = (response.data.matches && response.data.matches.length > 0) || |
| (response.data.threats && response.data.threats.length > 0); |
| return { |
| matches: hasMatches, |
| details: response.data |
| }; |
| } catch (error: any) { |
| console.error('GSB v5 Error:', error.response?.data || error.message); |
| return { matches: false, error: true }; |
| } |
| } |
|
|