Skip to content
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

SessionBagProxy::initialize() must be of the type array, string given #33769

Closed
mynameisbogdan opened this issue Sep 30, 2019 · 3 comments
Closed

Comments

@mynameisbogdan
Copy link
Contributor

Symfony version(s) affected: v4.3.4, 4.4.x-dev

Description
When _sf2_attributes or _sf2_meta is set to a string the following error occurs:
Argument 1 passed to Symfony\Component\HttpFoundation\Session\SessionBagProxy::initialize() must be of the type array, string given, called in vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php on line 460

To force the reproduction I used $_SESSION['_sf2_attributes'] = '';, but it seems to happen when the session expires too.

How to reproduce

<?php

use App\Kernel;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__) . '/../config/bootstrap.php';

session_start();
$_SESSION['_sf2_attributes'] = '';

$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

Possible Solution
Updating NativeSessionStorage::loadSession to check first if is an array?

- $session[$key] = isset($session[$key]) ? $session[$key] : [];
+ $session[$key] = isset($session[$key]) && \is_array($session[$key]) ? $session[$key] : [];
@nicolas-grekas
Copy link
Member

To force the reproduction I used $_SESSION['_sf2_attributes'] = '';

to me, we don't need to support this use case

it seems to happen when the session expires too.

I suppose that's when you hint the issue? Can you give more details? How can we reproduce it?

@nicolas-grekas
Copy link
Member

BTW, PR welcome :)

@mynameisbogdan
Copy link
Contributor Author

this is just a way to a 100% reproduction without waiting sessions to expire.

in my use case I'm migrating a legacy app to Symfony, exactly like Prestashop does it.

I already provided a /public/index.php necesary to replicate the issue. I think it's a good way to check for arrays anyway since SessionBagProxy::initialize accepts only type array.

BTW, PR welcome :)

Okay. 👍

nicolas-grekas added a commit that referenced this issue Oct 2, 2019
…initialize is an array (mynameisbogdan)

This PR was submitted for the 4.3 branch but it was merged into the 3.4 branch instead (closes #33814).

Discussion
----------

[HttpFoundation] Check if data passed to SessionBagProxy::initialize is an array

[HttpFoundation] Check if data passed to SessionBagProxy::initialize is an array

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #33769 <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

If `$_SESSION['_sf2_attributes']` is set to a string, `SessionBagProxy::initialize` will throw an error since it's argument is type-hinted as array. So this change is to check before if the data to be passed is truly an array.

Commits
-------

38782bc [HttpFoundation] Check if data passed to SessionBagProxy::initialize is an array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants