mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 10:10:14 +00:00
add restrict urls
This commit is contained in:
parent
0a57629cff
commit
2071d5c2bc
7 changed files with 74 additions and 1 deletions
|
@ -55,6 +55,12 @@ class URLAnalyzer extends URLAnalyzerBase
|
|||
if (!$host) {
|
||||
$this->error->throwError(self::ERROR_INVALID_URL, '');
|
||||
}
|
||||
|
||||
// Check if URL contains restricted keywords
|
||||
if ($this->isRestrictedUrl($url)) {
|
||||
Logger::getInstance()->logUrl($url, 'RESTRICTED_URL');
|
||||
$this->error->throwError(self::ERROR_RESTRICTED_URL, '');
|
||||
}
|
||||
$originalHost = parse_url($url, PHP_URL_HOST);
|
||||
$host = preg_replace('/^www\./', '', $host);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class URLAnalyzerBase
|
|||
const ERROR_DNS_FAILURE = 'DNS_FAILURE';
|
||||
const ERROR_CONTENT_ERROR = 'CONTENT_ERROR';
|
||||
const ERROR_GENERIC_ERROR = 'GENERIC_ERROR';
|
||||
const ERROR_RESTRICTED_URL = 'RESTRICTED_URL';
|
||||
|
||||
/** @var array Maps error types to HTTP codes and message keys */
|
||||
protected $errorMap = [
|
||||
|
@ -40,7 +41,8 @@ class URLAnalyzerBase
|
|||
self::ERROR_CONNECTION_ERROR => ['code' => 503, 'message_key' => 'CONNECTION_ERROR'],
|
||||
self::ERROR_DNS_FAILURE => ['code' => 504, 'message_key' => 'DNS_FAILURE'],
|
||||
self::ERROR_CONTENT_ERROR => ['code' => 502, 'message_key' => 'CONTENT_ERROR'],
|
||||
self::ERROR_GENERIC_ERROR => ['code' => 500, 'message_key' => 'GENERIC_ERROR']
|
||||
self::ERROR_GENERIC_ERROR => ['code' => 500, 'message_key' => 'GENERIC_ERROR'],
|
||||
self::ERROR_RESTRICTED_URL => ['code' => 403, 'message_key' => 'RESTRICTED_URL']
|
||||
];
|
||||
|
||||
/** @var array List of user agents to rotate through, including Googlebot */
|
||||
|
@ -125,4 +127,49 @@ class URLAnalyzerBase
|
|||
{
|
||||
return $this->rules->hasDomainRules($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if URL contains restricted keywords
|
||||
* @param string $url The URL to check
|
||||
* @return bool True if URL contains restricted keywords, false otherwise
|
||||
*/
|
||||
protected function isRestrictedUrl($url)
|
||||
{
|
||||
$restrictedKeywords = [
|
||||
'login',
|
||||
'signin',
|
||||
'sign-in',
|
||||
'signup',
|
||||
'sign-up',
|
||||
'register',
|
||||
'registration',
|
||||
'lost-password',
|
||||
'forgot-password',
|
||||
'reset-password',
|
||||
'password',
|
||||
'auth',
|
||||
'authentication',
|
||||
'account',
|
||||
'profile',
|
||||
'dashboard',
|
||||
'admin',
|
||||
'member',
|
||||
'subscription',
|
||||
'subscribe',
|
||||
'premium',
|
||||
'checkout',
|
||||
'payment',
|
||||
'billing'
|
||||
];
|
||||
|
||||
$urlLower = strtolower($url);
|
||||
|
||||
foreach ($restrictedKeywords as $keyword) {
|
||||
if (strpos($urlLower, $keyword) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,10 @@ return [
|
|||
'GENERIC_ERROR' => [
|
||||
'message' => 'Bei der Bearbeitung Ihrer Anfrage ist ein Fehler aufgetreten.',
|
||||
'type' => 'warning'
|
||||
],
|
||||
'RESTRICTED_URL' => [
|
||||
'message' => 'Diese URL enthält eingeschränkten Inhalt und kann aus Sicherheitsgründen nicht verarbeitet werden.',
|
||||
'type' => 'error'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
|
@ -52,6 +52,10 @@ return [
|
|||
'GENERIC_ERROR' => [
|
||||
'message' => 'An error occurred while processing your request.',
|
||||
'type' => 'warning'
|
||||
],
|
||||
'RESTRICTED_URL' => [
|
||||
'message' => 'This URL contains restricted content and cannot be processed for security reasons.',
|
||||
'type' => 'error'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
|
@ -52,6 +52,10 @@ return [
|
|||
'GENERIC_ERROR' => [
|
||||
'message' => 'Ocurrió un error al procesar su solicitud.',
|
||||
'type' => 'warning'
|
||||
],
|
||||
'RESTRICTED_URL' => [
|
||||
'message' => 'Esta URL contiene contenido restringido y no se puede procesar por razones de seguridad.',
|
||||
'type' => 'error'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
|
@ -52,6 +52,10 @@ return [
|
|||
'GENERIC_ERROR' => [
|
||||
'message' => 'Ocorreu um erro ao processar sua solicitação.',
|
||||
'type' => 'warning'
|
||||
],
|
||||
'RESTRICTED_URL' => [
|
||||
'message' => 'Esta URL contém conteúdo restrito e não pode ser processada por motivos de segurança.',
|
||||
'type' => 'error'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
|
@ -52,6 +52,10 @@ return [
|
|||
'GENERIC_ERROR' => [
|
||||
'message' => 'При обработке вашего запроса произошла ошибка.',
|
||||
'type' => 'warning'
|
||||
],
|
||||
'RESTRICTED_URL' => [
|
||||
'message' => 'Этот URL-адрес содержит запрещенный контент и не может быть обработан по соображениям безопасности.',
|
||||
'type' => 'error'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue