-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
396 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { WebRiskServiceClient, protos } from '@google-cloud/web-risk'; | ||
import Test, { TestParameters, Result } from '../Test'; | ||
import logger from '../logger'; | ||
|
||
/** | ||
* | ||
* @see https://cloud.google.com/web-risk | ||
* @see https://safebrowsing.google.com | ||
* @see https://transparencyreport.google.com/safe-browsing/search | ||
*/ | ||
class GoogleWebRisk extends Test { | ||
public name = 'GoogleWebRisk'; | ||
|
||
public async test({ url }: TestParameters): Promise<Result> { | ||
logger.info('Starting Google Web Risk test...'); | ||
|
||
const client = new WebRiskServiceClient(); | ||
|
||
const request = { | ||
uri: url, | ||
threatTypes: [ | ||
protos.google.cloud.webrisk.v1.ThreatType.MALWARE, | ||
protos.google.cloud.webrisk.v1.ThreatType.SOCIAL_ENGINEERING, | ||
protos.google.cloud.webrisk.v1.ThreatType.UNWANTED_SOFTWARE, | ||
], | ||
}; | ||
|
||
const response = await client.searchUris(request); | ||
|
||
const { threat } = response[0]; | ||
|
||
if (threat !== null) { | ||
return { | ||
status: 'ERROR', | ||
title: this.name, | ||
description: `This url contains ${threat.threatTypes.join(', ').toLowerCase()}!`, | ||
}; | ||
} | ||
|
||
return { | ||
status: 'SUCCESS', | ||
title: this.name, | ||
description: 'This URL is safe.', | ||
}; | ||
} | ||
} | ||
|
||
export default GoogleWebRisk; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.