Accent not supported in result of sql_get_roles or sql_get_details in authentication process session
mbourquin opened this issue · 1 comments
- [x ] I was not able to find an open or closed issue matching what I'm seeing.
- [x ] This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
Hi,
This problem appear in login process in the AuthenticationMiddleware. I have a table "users" with
some fields like user_id | username | password | firstname | email | role | create_date
PHP 7.1.20-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul 25 2018 10:06:40) ( NTS )
In the authentication config i have:
... 'driver_options' => [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ], 'sql_get_roles' => 'SELECT role FROM users WHERE username = :identity', 'sql_get_details' => 'SELECT user_id,firstname FROM users WHERE username=:identity' ...
All works fine if the content of "firstname" or "role" have no accent and i can access to my app without problem BUT when by example i enter the firstname "Valérie" (something with a accent) in the firstname field (or role), the login process hang (500) (see all errors below) and i must erase cookie to return to the login page (login is impossible).
`expressive/vendor/zendframework/zend-expressive-session/src/Session.php
*/
private $originalData;
public function __construct(array $data)
{
$this->data = $this->originalData = $data;
}
/**
* Convert a value to a JSON-serializable value.
*
* This value should be used by `set()` operations to ensure that the values
* within a session are serializable across any session adapter.
*
* @param mixed $value
* @return null|bool|int|float|string|array|\stdClass
*/
public static function extractSerializableValue($value)
{
**return json_decode(json_encode($value, \JSON_PRESERVE_ZERO_FRACTION), true);**
}`
It indicate me that line in bold (return json_decode(....), i suppose that it have a utf8 problem somewhere...
Code to reproduce the issue
It is just the normal process for authentication found in the docs.
Expected results
Just allowing words with accent (sql_get_details, sql_get_roles)
Actual results
TypeError thrown with message "json_decode() expects parameter 1 to be string, boolean given"
Stacktrace:
#50 TypeError in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-session/src/Session.php:49
#49 json_decode in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-session/src/Session.php:49
#48 Zend\Expressive\Session\Session:extractSerializableValue in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-session/src/Session.php:79
#47 Zend\Expressive\Session\Session:set in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-session/src/LazySession.php:75
#46 Zend\Expressive\Session\LazySession:set in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-authentication-session/src/PhpSession.php:106
#45 Zend\Expressive\Authentication\Session\PhpSession:authenticate in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-authentication/src/AuthenticationMiddleware.php:34
#44 Zend\Expressive\Authentication\AuthenticationMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#43 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/Next.php:52
#42 Zend\Stratigility\Next:handle in /home/michael/dev/test-app/expressive/src/App/src/Handler/LoginHandler.php:69
#41 App\Handler\LoginHandler:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#40 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/Next.php:52
#39 Zend\Stratigility\Next:handle in /home/michael/dev/test-app/expressive/src/App/src/Middleware/PrgMiddleware.php:39
#38 App\Middleware\PrgMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#37 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/Next.php:52
#36 Zend\Stratigility\Next:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-csrf/src/CsrfMiddleware.php:52
#35 Zend\Expressive\Csrf\CsrfMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#34 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/Next.php:52
#33 Zend\Stratigility\Next:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:91
#32 Zend\Stratigility\MiddlewarePipe:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/Route.php:100
#31 Zend\Expressive\Router\Route:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/RouteResult.php:110
#30 Zend\Expressive\Router\RouteResult:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/Middleware/DispatchMiddleware.php:35
#29 Zend\Expressive\Router\Middleware\DispatchMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#28 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#27 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-helpers/src/UrlHelperMiddleware.php:45
#26 Zend\Expressive\Helper\UrlHelperMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#25 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#24 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/Middleware/MethodNotAllowedMiddleware.php:51
#23 Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#22 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#21 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/Middleware/ImplicitOptionsMiddleware.php:70
#20 Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#19 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#18 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/Middleware/ImplicitHeadMiddleware.php:84
#17 Zend\Expressive\Router\Middleware\ImplicitHeadMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#16 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#15 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-router/src/Middleware/RouteMiddleware.php:54
#14 Zend\Expressive\Router\Middleware\RouteMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#13 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#12 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-session/src/SessionMiddleware.php:34
#11 Zend\Expressive\Session\SessionMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#10 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#9 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive-helpers/src/ServerUrlMiddleware.php:37
#8 Zend\Expressive\Helper\ServerUrlMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#7 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#6 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/Middleware/ErrorHandler.php:143
#5 Zend\Stratigility\Middleware\ErrorHandler:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php:46
#4 Zend\Expressive\Middleware\LazyLoadingMiddleware:process in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php:78
#3 Zend\Stratigility\MiddlewarePipe:handle in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-httphandlerrunner/src/RequestHandlerRunner.php:95
#2 Zend\HttpHandlerRunner\RequestHandlerRunner:run in /home/michael/dev/test-app/expressive/vendor/zendframework/zend-expressive/src/Application.php:81
#1 Zend\Expressive\Application:run in /home/michael/dev/test-app/expressive/public/index.php:29
#0 {closure} in /home/michael/dev/test-app/expressive/public/index.php:30
@mbourquin I'm moving this issue to zend-expressive-session (zendframework/zend-expressive-session#26), since it's a problem of this codebase.