Skip to content

Commit 53048ce

Browse files
committed
Log potential redirect loops caused by forced HTTPS
If the developer forgets/fails to set "trusted_proxies" properly, forcing the https channel can cause infinite redirect loops. This change will hopefully help them identify the problem faster. See #27603
1 parent b560883 commit 53048ce

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Symfony/Component/Security/Http/Firewall/ChannelListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ public function handle(GetResponseEvent $event)
4646

4747
if ('https' === $channel && !$request->isSecure()) {
4848
if (null !== $this->logger) {
49-
$this->logger->info('Redirecting to HTTPS.');
49+
if ('https' === $request->headers->get('X-Forwarded-Proto')) {
50+
$this->logger->info('Redirecting to HTTPS. ("X-Forwarded-Proto" header is set to "https" - did you set "trusted_proxies" correctly?)');
51+
} elseif (false !== strpos($request->headers->get('Forwarded'), 'proto=https')) {
52+
$this->logger->info('Redirecting to HTTPS. ("Forwarded" header is set to "proto=https" - did you set "trusted_proxies" correctly?)');
53+
} else {
54+
$this->logger->info('Redirecting to HTTPS.');
55+
}
5056
}
5157

5258
$response = $this->authenticationEntryPoint->start($request);

0 commit comments

Comments
 (0)