Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 4 additions & 49 deletions src/Extensions/Drupal/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function logRequest($ruleId, $request, $blockType): void {

/**
* Determine if the current visitor can bypass the firewall.
* This is disabled in this extension.
*
* @param bool $isMuCall
* Whether this is an early call before user session is available.
Expand All @@ -77,28 +78,12 @@ public function logRequest($ruleId, $request, $blockType): void {
* TRUE if the visitor can bypass, FALSE otherwise.
*/
public function canBypass($isMuCall): bool {
// If called too early, we can't check user permissions.
if ($isMuCall) {
return FALSE;
}

try {
$currentUser = \Drupal::currentUser();

// Allow administrators to bypass.
if ($currentUser->hasPermission('administer site configuration')) {
return TRUE;
}
}
catch (\Throwable $e) {
// If we can't determine user, don't bypass.
}

return FALSE;
}

/**
* Determine if the visitor is blocked due to too many blocked requests.
* This is disabled in this extension.
*
* @param int $minutes
* The time window in minutes.
Expand All @@ -111,36 +96,7 @@ public function canBypass($isMuCall): bool {
* TRUE if the visitor should be blocked, FALSE otherwise.
*/
public function isBlocked($minutes, $blockTime, $attempts): bool {
// Currently disabled - return false to not auto-block based on attempts.
// This can be enabled later with proper configuration.
if (TRUE) {
return FALSE;
}

if (empty($minutes) || empty($blockTime) || empty($attempts)) {
return FALSE;
}

try {
// Calculate the time window.
$time = ($minutes + $blockTime) * 60;
$cutoffTime = \Drupal::time()->getRequestTime() - $time;

// Count blocked requests from this IP in the time window.
$connection = \Drupal::database();
$count = $connection->select('patchstack_logs', 'pl')
->condition('block_type', 'BLOCK')
->condition('ip', $this->getIpAddress())
->condition('log_date', $cutoffTime, '>=')
->countQuery()
->execute()
->fetchField();

return (int) $count >= $attempts;
}
catch (\Throwable $e) {
return FALSE;
}
return FALSE;
}

/**
Expand Down Expand Up @@ -205,6 +161,7 @@ public function getHostName(): string {

/**
* Determine if the request should bypass the firewall based on whitelist.
* This is disabled in this extension.
*
* @param array $whitelistRules
* The whitelist rules.
Expand All @@ -215,8 +172,6 @@ public function getHostName(): string {
* TRUE if the request is whitelisted, FALSE otherwise.
*/
public function isWhitelisted($whitelistRules, $request): bool {
// Whitelist processing is handled by the firewall engine itself.
// This method can be used for additional Drupal-specific whitelisting.
return FALSE;
}

Expand Down