ariaieboy/laravel-safe-browsing

Google Safe Browsing API Integration for LARAVEL

1.4.0 2024-10-19 15:52 UTC

This package is auto-updated.

Last update: 2024-12-19 16:21:47 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.