Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security] Fix for check_path and logout #6040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;

use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerAware;

class UnicodeController extends ContainerAware
{
public function loginAction()
{
// get the login error if there is one
if ($this->container->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $this->container->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $this->container->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}

return $this->container->get('templating')->renderResponse('FormLoginBundle:Unicode:login.html.twig', array(
// last username entered by the user
'last_username' => $this->container->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}

public function loginCheckAction()
{
throw new \RuntimeException('loginCheckAction() should never be called.');
}

public function logoutAction()
{
throw new \RuntimeException('logoutAction() should never be called.');
}

public function secureAction()
{
throw new \RuntimeException('secureAction() should never be called.');
}

public function profileAction()
{
return new Response('Profile');
}

public function homepageAction()
{
return new Response('Homepage');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
unicode_login_path:
pattern: /вход
defaults: { _controller: FormLoginBundle:Unicode:login }

unicode_check_path:
pattern: /аутентификация
defaults: { _controller: FormLoginBundle:Unicode:loginCheck }

unicode_default_target_path:
pattern: /профайл
defaults: { _controller: FormLoginBundle:Unicode:profile }

unicode_logout_path:
pattern: /выход
defaults: { _controller: FormLoginBundle:Unicode:logout }

unicode_logout_target_path:
pattern: /домашняя_страница
defaults: { _controller: FormLoginBundle:Unicode:homepage }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "::base.html.twig" %}

{% block body %}

{% if error %}
<div>{{ error.message }}</div>
{% endif %}

<form action="{{ path('unicode_check_path') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />

<label for="password">Password:</label>
<input type="password" id="password" name="_password" />

<input type="hidden" name="_target_path" value="" />

<input type="submit" name="login" />
</form>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

class UnicodeRoutesTest extends WebTestCase
{
/**
* @var string Login username
*/
protected $username = 'johannes';

/**
* @var string Login password
*/
protected $password = 'test';

/**
* @var array Routes helper
*/
protected $routes = array(
'homepage' => '/домашняя_страница',
'profile' => '/профайл',
'login' => '/вход',
'logout' => '/выход',
);

public function testLoginLogoutProcedure()
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'unicode_routes_in_firewall.yml'));
$client->insulate();

$crawler = $client->request('GET', $this->getRoute('login'));
$form = $crawler->selectButton('login')->form();
$form['_username'] = $this->username;
$form['_password'] = $this->password;
$client->submit($form);

$this->assertRedirect($client->getResponse(), $this->getRoute('profile'));
$this->assertEquals('Profile', $client->followRedirect()->text());

$client->request('GET', $this->getRoute('logout'));
$this->assertRedirect($client->getResponse(), $this->getRoute('homepage'));
$this->assertEquals('Homepage', $client->followRedirect()->text());
}

public function getRoute($name)
{
if (!isset($this->routes[$name])) {
throw new \InvalidArgumentException(sprintf('No route defined with name: %s', $name));
}

return $this->routes[$name];
}

protected function setUp()
{
parent::setUp();

$this->deleteTmpDir('StandardFormLogin');
}

protected function tearDown()
{
parent::tearDown();

$this->deleteTmpDir('StandardFormLogin');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ _form_login_bundle:

_form_login_localized:
resource: @FormLoginBundle/Resources/config/localized_routing.yml

_form_login_unicode:
resource: @FormLoginBundle/Resources/config/unicode_routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
imports:
- { resource: ./../config/default.yml }

security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext

providers:
in_memory:
memory:
users:
johannes: { password: test, roles: [ROLE_USER] }

firewalls:
default:
form_login:
login_path: /вход
check_path: /аутентификация
default_target_path: /профайл
use_forward: true
logout:
path: /выход
target: /домашняя_страница
anonymous: ~

access_control:
- { path: '^/(?:[a-z]{2})/secure/.*', roles: ROLE_USER }
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Security/Http/HttpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public function checkRequestPath(Request $request, $path)
return false;
}
}

return $path === $request->getPathInfo();
return $path === rawurldecode($request->getPathInfo());
}

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.