Skip to content

Commit

Permalink
Merge pull request #7 from sansecio/filter-headers
Browse files Browse the repository at this point in the history
filter request headers
  • Loading branch information
danslo authored Feb 13, 2025
2 parents ee12bfa + 9a575a2 commit e06c650
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Model/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,32 @@ class Report
/** @var IP */
private $ip;

/** @var string[] */
private $filteredHeaders;

public function __construct(
Config $config,
CurlFactory $curlFactory,
Logger $logger,
SerializerInterface $serializer,
IP $ip
IP $ip,
array $filteredHeaders = []
) {
$this->config = $config;
$this->curlFactory = $curlFactory;
$this->logger = $logger;
$this->serializer = $serializer;
$this->ip = $ip;
$this->filteredHeaders = $filteredHeaders;
}

private function getRequestHeaders(RequestInterface $request): array
{
$headers = $request->getHeaders()->toArray();
foreach ($this->filteredHeaders as $filteredHeader) {
unset($headers[$filteredHeader]);
}
return $headers;
}

public function sendReport(RequestInterface $request, array $rules)
Expand All @@ -57,7 +71,7 @@ public function sendReport(RequestInterface $request, array $rules)
'path' => $request->getRequestUri(),
'body' => $request->getContent(),
'ips' => $this->ip->collectRequestIPs(),
'headers' => $request->getHeaders()->toArray(),
'headers' => $this->getRequestHeaders($request),
'scheme' => $request->getScheme(),
]
]);
Expand Down
8 changes: 8 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@
</argument>
</arguments>
</type>
<type name="Sansec\Shield\Model\Report">
<arguments>
<argument name="filteredHeaders" xsi:type="array">
<item name="Cookie" xsi:type="string">Cookie</item>
<item name="Authorization" xsi:type="string">Authorization</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit e06c650

Please sign in to comment.