ariaieboy / laravel-safe-browsing
Google Safe Browsing API Integration for LARAVEL
Fund package maintenance!
ariaieboy
Installs: 2 990
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ~8.1.0|~8.2.0|~8.3|~8.4
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^10.0|^11
- spatie/laravel-package-tools: ^1.13.5
Requires (Dev)
- graham-campbell/testbench: ^5.7|^6.0
- nunomaduro/larastan: ^1.0|^2.5
- pestphp/pest: ^2
- pestphp/pest-plugin-laravel: ^2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
Using this LaravelSafeBrowsing Package you can add google safe browsing api (v4) to your laravel application.
in applications that users generates the content of the website, It's necessary to check if the content is safe or not.
one of the important features of this package is that it will help you to check URLs and if it is not safe it will return the reason why it is not safe using google safe browsing api v4.
Installation
You can install the package via composer:
composer require ariaieboy/laravel-safe-browsing
You can publish the config file with:
php artisan vendor:publish --tag="safe-browsing-config"
This is the contents of the published config file:
return [ 'google'=>[ 'api_domain'=>env('SAFEBROWSING_GOOGLE_API_DOMAIN','https://safebrowsing.googleapis.com/'), 'api_key'=>env('SAFEBROWSING_GOOGLE_API_KEY',null), 'timeout'=>30, 'threatTypes' => [ 'THREAT_TYPE_UNSPECIFIED', 'MALWARE', 'SOCIAL_ENGINEERING', 'UNWANTED_SOFTWARE', 'POTENTIALLY_HARMFUL_APPLICATION', ], 'threatPlatforms' => [ 'ANY_PLATFORM' ], 'clientId' => 'ariaieboy-safebrowsing', 'clientVersion' => '1.0.0', ] ];
Set the api_key in your config file or using ENV SAFEBROWSING_GOOGLE_API_KEY
Usage
$result = LaravelSafeBrowsing::isSafeUrl('http://malware.testing.google.test/testing/malware/',true); // Return: (string) MALWARE
the first argument is the url that you want to check, the second argument is an optional boolean. if you don't pass the second argument or pass false the function will return true if the url is safe or false if it is not safe. if you pass true the function will return the threat type that is not safe. if the url is safe it will return true.
TODO
- add middleware to check if the url is safe
- add verification rules to check if the url is safe
- add caching mechanism using update api
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.