Skip to content

Commit 4c132bc

Browse files
committed
update ip address configuration and middleware
1 parent cfc0a59 commit 4c132bc

3 files changed

Lines changed: 34 additions & 17 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
// return [
6+
// 'rka' => [
7+
// 'ip_address' => [
8+
// 'check_proxy_headers' => false,
9+
// 'trusted_proxies' => [],
10+
// 'attribute_name' => 'ip_address',
11+
// 'headers_to_inspect' => [],
12+
// ],
13+
// ],
14+
// ];
15+
16+
return [
17+
'rka' => [
18+
'ip_address' => [
19+
'check_proxy_headers' => true,
20+
'trusted_proxies' => [],
21+
'attribute_name' => 'ip_address',
22+
'headers_to_inspect' => [
23+
'Forwarded',
24+
'X-Forwarded-For',
25+
'X-Forwarded',
26+
'X-Cluster-Client-Ip',
27+
'Client-Ip',
28+
],
29+
],
30+
],
31+
];

‎config/autoload/ip_address.global.php‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎src/App/src/Handler/PostCreateContactHandler.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class PostCreateContactHandler implements RequestHandlerInterface
2424
TemplateRendererInterface::class,
2525
UrlHelper::class,
2626
ContactService::class,
27-
'config',
27+
'config.rka.ip_address',
2828
)]
2929
public function __construct(
3030
protected TemplateRendererInterface $template,
3131
protected UrlHelper $urlHelper,
3232
protected ContactService $contactService,
33-
protected array $config,
33+
protected array $ipAddressConfig,
3434
) {
3535
}
3636

@@ -44,7 +44,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4444
$token = is_array($rawBody) && is_string($rawBody['cf-turnstile-response'] ?? null)
4545
? $rawBody['cf-turnstile-response']
4646
: '';
47-
$ip = $request->getAttribute($this->config['rka']['ip_address']['attribute_name'] ?? 'ip_address');
47+
$ip = $request->getAttribute($this->ipAddressConfig['attribute_name']);
4848

4949
if (! $this->contactService->verifyTurnstile($token, $ip)) {
5050
$errors['captcha'] = "We couldn't verify you're human. Please try again.";

0 commit comments

Comments
 (0)