Skip to content

Commit 7894925

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: fix merge [FrameworkBundle] Allow to specify `null` for exception mapping configuration values Fix BinaryFileResponse content type detection logic [Notifier] [Expo] Throw exception on error-response from expo api Bump Symfony version to 6.0.14 Update VERSION for 6.0.13 Update CHANGELOG for 6.0.13 Bump Symfony version to 5.4.14 Update VERSION for 5.4.13 Update CHANGELOG for 5.4.13 Bump Symfony version to 4.4.47 Update VERSION for 4.4.46 Update CONTRIBUTORS for 4.4.46 Update CHANGELOG for 4.4.46 [Security] Fix login url matching when app is not run with url rewriting or from a sub folder
2 parents c2d2e1b + dca3b8f commit 7894925

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

Authenticator/AbstractLoginFormAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract protected function getLoginUrl(Request $request): string;
4141
*/
4242
public function supports(Request $request): bool
4343
{
44-
return $request->isMethod('POST') && $this->getLoginUrl($request) === $request->getPathInfo();
44+
return $request->isMethod('POST') && $this->getLoginUrl($request) === $request->getBaseUrl().$request->getPathInfo();
4545
}
4646

4747
/**
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Tests\Authenticator;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18+
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
19+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
20+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
21+
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
22+
23+
class AbstractLoginFormAuthenticatorTest extends TestCase
24+
{
25+
/**
26+
* @dataProvider provideSupportsData
27+
*/
28+
public function testSupports(string $loginUrl, Request $request, bool $expected)
29+
{
30+
$authenticator = new ConcreteFormAuthenticator($loginUrl);
31+
$this->assertSame($expected, $authenticator->supports($request));
32+
}
33+
34+
public function provideSupportsData(): iterable
35+
{
36+
yield [
37+
'/login',
38+
Request::create('http://localhost/login', Request::METHOD_POST, [], [], [], [
39+
'DOCUMENT_ROOT' => '/var/www/app/public',
40+
'PHP_SELF' => '/index.php',
41+
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
42+
'SCRIPT_NAME' => '/index.php',
43+
]),
44+
true,
45+
];
46+
yield [
47+
'/login',
48+
Request::create('http://localhost/somepath', Request::METHOD_POST, [], [], [], [
49+
'DOCUMENT_ROOT' => '/var/www/app/public',
50+
'PHP_SELF' => '/index.php',
51+
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
52+
'SCRIPT_NAME' => '/index.php',
53+
]),
54+
false,
55+
];
56+
yield [
57+
'/folder/login',
58+
Request::create('http://localhost/folder/login', Request::METHOD_POST, [], [], [], [
59+
'DOCUMENT_ROOT' => '/var/www/app/public',
60+
'PHP_SELF' => '/folder/index.php',
61+
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
62+
'SCRIPT_NAME' => '/folder/index.php',
63+
]),
64+
true,
65+
];
66+
yield [
67+
'/folder/login',
68+
Request::create('http://localhost/folder/somepath', Request::METHOD_POST, [], [], [], [
69+
'DOCUMENT_ROOT' => '/var/www/app/public',
70+
'PHP_SELF' => '/folder/index.php',
71+
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
72+
'SCRIPT_NAME' => '/folder/index.php',
73+
]),
74+
false,
75+
];
76+
yield [
77+
'/index.php/login',
78+
Request::create('http://localhost/index.php/login', Request::METHOD_POST, [], [], [], [
79+
'DOCUMENT_ROOT' => '/var/www/app/public',
80+
'PHP_SELF' => '/index.php',
81+
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
82+
'SCRIPT_NAME' => '/index.php',
83+
]),
84+
true,
85+
];
86+
yield [
87+
'/index.php/login',
88+
Request::create('http://localhost/index.php/somepath', Request::METHOD_POST, [], [], [], [
89+
'DOCUMENT_ROOT' => '/var/www/app/public',
90+
'PHP_SELF' => '/index.php',
91+
'SCRIPT_FILENAME' => '/var/www/app/public/index.php',
92+
'SCRIPT_NAME' => '/index.php',
93+
]),
94+
false,
95+
];
96+
}
97+
}
98+
99+
class ConcreteFormAuthenticator extends AbstractLoginFormAuthenticator
100+
{
101+
private $loginUrl;
102+
103+
public function __construct(string $loginUrl)
104+
{
105+
$this->loginUrl = $loginUrl;
106+
}
107+
108+
protected function getLoginUrl(Request $request): string
109+
{
110+
return $this->loginUrl;
111+
}
112+
113+
public function authenticate(Request $request): Passport
114+
{
115+
return new SelfValidatingPassport(new UserBadge('dummy'));
116+
}
117+
118+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
119+
{
120+
return null;
121+
}
122+
}

0 commit comments

Comments
 (0)