v7.0.0-beta.4 release
This commit is contained in:
1 parent
05db17887d
commit
1db039ff34
1545 files changed
+136783
-11634
No files matched your search
+39
-6
@@ -2,8 +2,22 @@
|
||||
|
||||
namespace App\Seo;
|
||||
|
||||
use App\Extension\HookManager;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* 검색/링크 프리뷰/AI 봇 감지기.
|
||||
*
|
||||
* 평가 체인:
|
||||
* 1. seo.bot_detection_enabled = false → false
|
||||
* 2. _escaped_fragment_ 쿼리 → true (구형 크롤러 호환)
|
||||
* 3. UA 빈 문자열 → false
|
||||
* 4. core.seo.resolve_is_bot 훅 결과(non-null) → 즉시 결정 (확장 슬롯)
|
||||
* 5. seo.bot_detection_library_enabled = true → jaybizzle/crawler-detect
|
||||
* + G7 보강 패턴(미커버 3종) + 운영자 커스텀 패턴
|
||||
* 6. 라이브러리 비활성 → 운영자 커스텀 패턴 stripos 매칭만 (레거시 모드)
|
||||
* 7. fallthrough → false
|
||||
*/
|
||||
class BotDetector
|
||||
{
|
||||
/**
|
||||
@@ -14,12 +28,10 @@ class BotDetector
|
||||
*/
|
||||
public function isBot(Request $request): bool
|
||||
{
|
||||
// 봇 감지 비활성화 시 항상 false
|
||||
if (! g7_core_settings('seo.bot_detection_enabled', true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// _escaped_fragment_ 파라미터 지원 (구형 크롤러 호환)
|
||||
if ($request->has('_escaped_fragment_')) {
|
||||
return true;
|
||||
}
|
||||
@@ -29,12 +41,33 @@ class BotDetector
|
||||
return false;
|
||||
}
|
||||
|
||||
$botPatterns = g7_core_settings('seo.bot_user_agents', []);
|
||||
if (empty($botPatterns)) {
|
||||
return false;
|
||||
$hookResult = HookManager::applyFilters('core.seo.resolve_is_bot', null, [
|
||||
'request' => $request,
|
||||
'userAgent' => $userAgent,
|
||||
]);
|
||||
if ($hookResult !== null) {
|
||||
return (bool) $hookResult;
|
||||
}
|
||||
|
||||
foreach ($botPatterns as $pattern) {
|
||||
$libraryEnabled = (bool) g7_core_settings('seo.bot_detection_library_enabled', true);
|
||||
$userPatterns = (array) g7_core_settings('seo.bot_user_agents', []);
|
||||
|
||||
if ($libraryEnabled) {
|
||||
// 라이브러리 1차: jaybizzle 약 1,000종 + G7 보강 패턴.
|
||||
// 라이브러리는 isCrawler() 내부에서 Exclusions 패턴(Firefox/Mozilla/Chrome/Safari 등 일반 브라우저 식별자)
|
||||
// 을 UA 에서 strip 한 후 매칭하므로, 운영자가 "Firefox" 등을 봇으로 지정해도 라이브러리 경로로는 잡히지 않음.
|
||||
if ((new BotDetectorCustomProvider($userPatterns))->isCrawler($userAgent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 라이브러리 2차: 운영자 커스텀 패턴은 raw UA 에 stripos 직접 매칭 — Exclusions 우회.
|
||||
// 라이브러리와 함께 작동.
|
||||
}
|
||||
|
||||
foreach ($userPatterns as $pattern) {
|
||||
if (! is_string($pattern) || $pattern === '') {
|
||||
continue;
|
||||
}
|
||||
if (stripos($userAgent, $pattern) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user