rattfieldnz / safe-urls
一个使用Google安全浏览API检查URL的Laravel包。
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- curl/curl: ^2.2
- illuminate/support: ~5
Requires (Dev)
- barryvdh/laravel-ide-helper: 2.6.*
- fzaninotto/faker: ~1.8
- mihaeu/test-generator: ^1.0
- mockery/mockery: ^1.2
- orchestra/testbench: ^3.8
- php-cs-fixer/phpunit-constraint-isidenticalstring: ^1.1
- phpspec/prophecy: ^1.8
- phpunit/php-code-coverage: ~6.1
- phpunit/phpunit: ~7.5
- sempro/phpunit-pretty-print: ^1.0
- squizlabs/php_codesniffer: ^3.4
- dev-master
- 0.0.58
- 0.0.57
- 0.0.56
- 0.0.55
- 0.0.54
- 0.0.53
- 0.0.52
- 0.0.51
- 0.0.50
- 0.0.49
- 0.0.48
- 0.0.47
- 0.0.46
- 0.0.45
- 0.0.44
- 0.0.43
- 0.0.42
- 0.0.41
- 0.0.40
- 0.0.39
- 0.0.38
- 0.0.37
- 0.0.36
- 0.0.35
- 0.0.34
- 0.0.33
- 0.0.32
- 0.0.31
- 0.0.30
- 0.0.29
- 0.0.28
- 0.0.27
- 0.0.26
- 0.0.25
- 0.0.24
- 0.0.23
- 0.0.22
- 0.0.21
- 0.0.20
- 0.0.19
- 0.0.18
- 0.0.17
- 0.0.16
- 0.0.15
- 0.0.14
- 0.0.13
- 0.0.12
- 0.0.11
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-dependabot/composer/symfony/http-kernel-4.4.18
- dev-dependabot/composer/composer/composer-1.10.22
- dev-scrutinizer-patch-11
- dev-scrutinizer-patch-10
- dev-scrutinizer-patch-9
- dev-scrutinizer-patch-8
- dev-scrutinizer-patch-7
- dev-scrutinizer-patch-6
- dev-scrutinizer-patch-5
- dev-scrutinizer-patch-4
- dev-scrutinizer-patch-3
- dev-scrutinizer-patch-1
- dev-scrutinizer-patch-2
- dev-analysis-8Kb6De
This package is auto-updated.
Last update: 2024-09-26 06:17:31 UTC
README
一个使用Google安全浏览API(查找)检查URL的Laravel包。
受到https://github.com/snipe/Safebrowsing的另一个类似包的启发。
查看contributing.md以查看待办事项列表。
请注意
此包需要您拥有有效的Google安全浏览API密钥。没有它将无法工作。创建API密钥是免费的。
Google还会限制API使用,所以如果您有一个高流量站点,您可能需要构建一个缓存层或类似的东西,以避免快速耗尽您的请求。您可以通过Google API控制台监视您的使用情况。
此项目尚未准备好在生产环境中使用。当它准备好时,将会有第一个主要版本(即1.0.0)。
关于Google安全浏览API结果的说明
在测试期间,有几次API将一些恶意网站显示为“安全”,而实际上它们并不是。
例如,运行PHPUnit测试将以下示例站点显示为“安全”;然而,在Postman中运行API产生了预期的结果。我还没有找到解决方案;然而,任何反馈/建议都受欢迎,包括pull请求等。以下是我阅读关于此问题的链接
- google/safebrowsing#30(评论).
- https://stackoverflow.com/questions/41934692/google-url-safe-browsingv4-lookup-api-is-not-working.
- https://groups.google.com/forum/#!topic/google-safe-browsing-api/Z5FVGfBbl20
- https://stackoverflow.com/questions/54625443/google-safe-browsing-not-detecting-url-even-it-unsafe-url
安装
通过Composer
$ composer require rattfieldnz/safe-urls
更新您的配置
对于使用Laravel < 5.4的应用程序
打开config/app.php
并将以下内容添加到您的providers
数组中,并将以下内容添加到您的aliases
数组中:
RattfieldNz\SafeUrls\SafeUrlsServiceProvider::class,
到您的providers
数组在config/app.php
中,和
'SafeUrls' => RattfieldNz\SafeUrls\Facades\SafeUrlsFacade::class,
到您的aliases
数组在config/app.php
中。
发布配置
php artisan vendor:publish
这将把一个safe-urls.php
配置文件添加到您的项目的config
文件夹中。
设置您的Google安全浏览API密钥
在您的.env
文件中添加:
GOOGLE_API_KEY=YOUR-ACTUAL-API-KEY GOOGLE_CLIENT_ID=your-client-id GOOGLE_CLIENT_VERSION=1.0 (or your preferred number) GOOGLE_CURL_TIMEOUT=10 (in seconds)
配置文件中还有一些额外选项,这些选项与您希望检查的具体威胁类型以及希望检查的平台有关,但除非您想要检查更少的事情,否则您实际上无需过多担心,因为它已经相当全面了。
使用方法
使用 Blade 语法
@if(isset(SafeUrls::check($urls, true)["response"]["matches"])) <p>There are {{ count(SafeUrls::check($urls, true)["response"]["matches"]) }} dangerous URLs.</p> @else <p>No results were found</p> @endif
其中 $urls
可以是一个待检查的 URL 数组,也许是通过您的控制器传递到视图中的。
true
将以关联数组的形式返回结果。
false
(或没有第二个参数)将以 JSON 编码字符串的形式返回结果。
@if (SafeUrls::isDangerous('http://twitter.com/')) // do something if the url is flagged as suspicious @else // hooray - it's not flagged! @endif
使用外观
SafeUrls::add(['http://ianfette.org']); SafeUrls::add(['http://malware.testing.google.test/testing/malware/']); SafeUrls::execute(); print('Status of the third URL is: '.SafeUrls::isDangerous('http://twitter.com/'));
输入和输出示例
如果 $urls
的值为
$urls = [ 'http://www.yahoo.com/' 'http://www.google.com/' 'http://malware.testing.google.test/testing/malware/' 'http://twitter.com/' 'http://ianfette.org' 'https://github.com/' 'https://testsafebrowsing.appspot.com/s/phishing.html' 'https://testsafebrowsing.appspot.com/s/malware.html' 'http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/' 'http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/SOCIAL_ENGINEERING/URL/' ];
SafeUrls::check($urls, true)
将返回以下关联数组
[ "status" => 200, "response" => [ "matches" => [ [ "threatType" => "MALWARE", "platformType" => "ANY_PLATFORM", "threat" => [ "url" => "http://malware.testing.google.test/testing/malware/" ], "cacheDuration" => "300s", "threatEntryType" => "URL" ], [ "threatType" => "SOCIAL_ENGINEERING", "platformType" => "ANY_PLATFORM", "threat" => [ "url" => "http://malware.testing.google.test/testing/malware/" ], "cacheDuration" => "300s", "threatEntryType" => "URL" ], [ "threatType" => "SOCIAL_ENGINEERING", "platformType" => "ANY_PLATFORM", "threat" => [ "url" => "https://testsafebrowsing.appspot.com/s/phishing.html" ], "cacheDuration" => "300s", "threatEntryType" => "URL" ], [ "threatType" => "MALWARE", "platformType" => "ANY_PLATFORM", "threat" => [ "url" => "https://testsafebrowsing.appspot.com/s/malware.html" ], "cacheDuration" => "300s", "threatEntryType" => "URL" ], [ "threatType" => "MALWARE", "platformType" => "ANY_PLATFORM", "threat" => [ "url" => "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/" ], "cacheDuration" => "300s", "threatEntryType" => "URL" ], [ "threatType" => "SOCIAL_ENGINEERING", "platformType" => "ANY_PLATFORM", "threat" => [ "url" => "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/SOCIAL_ENGINEERING/URL/" ], "cacheDuration" => "300s", "threatEntryType" => "URL" ], ], ], ]
SafeUrls::check($urls)
(或 SafeUrls::check($urls, false)
)将返回以下 JSON 编码字符串
{ "status":200, "response":{ "matches":[ { "threatType":"MALWARE", "platformType":"ANY_PLATFORM", "threat":{ "url":"http:\/\/malware.testing.google.test\/testing\/malware\/" }, "cacheDuration":"300s", "threatEntryType":"URL" }, { "threatType":"SOCIAL_ENGINEERING", "platformType":"ANY_PLATFORM", "threat":{ "url":"http:\/\/malware.testing.google.test\/testing\/malware\/" }, "cacheDuration":"300s", "threatEntryType":"URL" }, { "threatType":"SOCIAL_ENGINEERING", "platformType":"ANY_PLATFORM", "threat":{ "url":"https:\/\/testsafebrowsing.appspot.com\/s\/phishing.html" }, "cacheDuration":"300s", "threatEntryType":"URL" }, { "threatType":"MALWARE", "platformType":"ANY_PLATFORM", "threat":{ "url":"https:\/\/testsafebrowsing.appspot.com\/s\/malware.html" }, "cacheDuration":"300s", "threatEntryType":"URL" }, { "threatType":"MALWARE", "platformType":"ANY_PLATFORM", "threat":{ "url":"http:\/\/testsafebrowsing.appspot.com\/apiv4\/ANY_PLATFORM\/MALWARE\/URL\/" }, "cacheDuration":"300s", "threatEntryType":"URL" }, { "threatType":"SOCIAL_ENGINEERING", "platformType":"ANY_PLATFORM", "threat":{ "url":"http:\/\/testsafebrowsing.appspot.com\/apiv4\/ANY_PLATFORM\/SOCIAL_ENGINEERING\/URL\/" }, "cacheDuration":"300s", "threatEntryType":"URL" } ] } }
两种输出都将取决于您在 config/safe-urls.php
文件中设置的选项。
测试 URL
以下是一些在实验 Laravel 包时可以使用的方便的测试 URL。
- http://www.yahoo.com/(OK)
- http://www.google.com/(OK)
- http://malware.testing.google.test/testing/malware/(恶意软件)
- http://twitter.com/(OK)
- http://ianfette.org(恶意软件)
- https://github.com/(OK)
- https://testsafebrowsing.appspot.com/s/phishing.html(恶意软件)
- https://testsafebrowsing.appspot.com/s/malware.html(恶意软件)
- http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/(恶意软件)
- http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/SOCIAL_ENGINEERING/URL/(恶意软件 / 社会工程学)
变更日志
有关最近更改的更多信息,请参阅变更日志。
测试
从本包的根目录内部
$ ./run_phpunit YOUR_GOOGLE_API_KEY
将 YOUR_GOOGLE_API_KEY
替换为您的密钥。您可以通过访问 https://developers.google.com/safe-browsing/v4/get-started 来获取密钥。
贡献
有关详细信息,请参阅 contributing.md。
安全
如果您发现任何与安全相关的问题,请通过电子邮件而不是问题跟踪器联系作者。
致谢
许可
有关更多信息,请参阅许可文件。