From 8f5888523ca3416235760c5571899c1c4760b8b8 Mon Sep 17 00:00:00 2001 From: Dave Jong Date: Fri, 23 Jan 2026 20:39:48 +0100 Subject: [PATCH 1/3] Fixes request logging in Drupal middleware -> extension call. --- src/Extensions/Drupal/Extension.php | 44 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Extensions/Drupal/Extension.php b/src/Extensions/Drupal/Extension.php index d227b47..ce2dd7c 100644 --- a/src/Extensions/Drupal/Extension.php +++ b/src/Extensions/Drupal/Extension.php @@ -17,23 +17,31 @@ class Extension implements ExtensionInterface { * * @param int $ruleId * The firewall rule ID that matched. - * @param string $bodyData + * @param string|array $request * The request body data. * @param string $blockType * The type of block performed (BLOCK, LOG, or REDIRECT). */ - public function logRequest($ruleId, $bodyData, $blockType): void { + public function logRequest($ruleId, $request, $blockType): void { try { - $request = \Drupal::request(); + // Transform raw payload. + if (is_array($request) && array_key_exists('raw', $request)) { + $request['raw'] = isset($request['raw']) && is_array($request['raw']) ? $request['raw'][0] : $request['raw']; + + // Remove raw payload if not present. + if ((is_array($request['raw']) && count($request['raw'])) == 0 || empty($request['raw'])) { + unset($request['raw']); + } + } - // Get POST data. - $postData = $request->request->all(); - if (empty($postData)) { - $rawContent = $request->getContent(); - $postData = !empty($rawContent) ? $rawContent : NULL; + // Remove files payload if not present. + if (isset($request['files']) && is_array($request['files']) && count($request['files']) == 0) { + unset($request['files']); } - else { - $postData = json_encode($postData); + + // Remove post payload if not present. + if (isset($request['post']) && is_array($request['post']) && count($request['post']) == 0) { + unset($request['post']); } // Insert into the logs table. @@ -41,13 +49,13 @@ public function logRequest($ruleId, $bodyData, $blockType): void { $connection->insert('patchstack_logs') ->fields([ 'ip' => $this->getIpAddress(), - 'request_uri' => $request->getRequestUri() ?? '', - 'user_agent' => $request->headers->get('User-Agent') ?? '', - 'method' => $request->getMethod() ?? '', - 'fid' => (int) $ruleId, - 'post_data' => $postData, + 'request_uri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '', + 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', + 'method' => isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '', + 'fid' => '55' . $ruleId, + 'post_data' => json_encode($request), 'block_type' => $blockType, - 'log_date' => \Drupal::time()->getRequestTime(), + 'log_date' => \Drupal::time()->getRequestTime() ]) ->execute(); } @@ -105,6 +113,10 @@ public function canBypass($isMuCall): bool { 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; } From 44d28397a152b68f7adb44748f166bc0dce8277d Mon Sep 17 00:00:00 2001 From: Dave Jong Date: Sun, 25 Jan 2026 13:59:58 +0100 Subject: [PATCH 2/3] Removed certain functionality that would slow down Drupal performance. --- src/Extensions/Drupal/Extension.php | 53 +++-------------------------- 1 file changed, 4 insertions(+), 49 deletions(-) diff --git a/src/Extensions/Drupal/Extension.php b/src/Extensions/Drupal/Extension.php index ce2dd7c..89cb0c9 100644 --- a/src/Extensions/Drupal/Extension.php +++ b/src/Extensions/Drupal/Extension.php @@ -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. @@ -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. @@ -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; } /** @@ -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. @@ -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; } From 5851efae700d2131cb40b9188560b7efc7ce034b Mon Sep 17 00:00:00 2001 From: Elliot Taylor Date: Thu, 5 Mar 2026 11:42:48 +0000 Subject: [PATCH 3/3] Add OWNERS.md for code ownership compliance Establishes code ownership documentation as part of our compliance requirements. Every repository must have a clearly defined owner responsible for security posture, maintenance decisions, and lifecycle management. Co-Authored-By: Claude Opus 4.6 --- OWNERS.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 OWNERS.md diff --git a/OWNERS.md b/OWNERS.md new file mode 100644 index 0000000..8a9c918 --- /dev/null +++ b/OWNERS.md @@ -0,0 +1,13 @@ +# Code Ownership + +## Owner +- **Name:** Elliot Taylor +- **GitHub:** [@ejntaylor](https://github.com/ejntaylor) + +## Category +Engineering + +## Responsibilities +- Security posture and patching +- Answering questions about purpose, lifecycle, and dependencies +- Deciding on continued maintenance or deprecation