8000 Disallow invalid characters in session.name by ostrolucky · Pull Request #27246 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Disallow invalid characters in session.name #27246

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

Merged
merged 1 commit into from
May 17, 2018
Merged
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
Disallow illegal characters like "." in session.name
PHP saves cookie with correct name, but upon deserializa
8000
tion to
$_COOKIE, it replaces some characters, e.g. "." becomes "_".

This is probably also reason why \SessionHandler is not able to find
a session.

https://harrybailey.com/2009/04/dots-arent-allowed-in-php-cookie-names/
https://bugs.php.net/bug.php?id=75883
  • Loading branch information
ostrolucky committed May 13, 2018
commit 16ebb43bd4ff29b53cb78b9cd1d1f7d97de3cb32
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,16 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->children()
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
->scalarNode('name')->end()
->scalarNode('name')
->validate()
->ifTrue(function ($v) {
parse_str($v, $parsed);

return implode('&', array_keys($parsed)) !== (string) $v;
})
->thenInvalid('Session name %s contains illegal character(s)')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing double quotes around %s
about the implode, this means & is valid in a session name? how strange is that :)
but OK, that's because cookie are not encoded using URL queries.
This also means we should exclude ;, isn't it?

Copy link
Contributor Author
@ostrolucky ostrolucky May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config quotes it by type itself, if I did it, it would be double quoted. Yes, & is valid. No need to exclude ; and further complicate this closure, rest of the chars are handled by setcookie call. As long as developer is warned, it's all good.

Got any pointers why appveyor fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appveryor fails for some reason on ' char even though it's valid... I've just removed it from test case

->end()
->end()
->scalarNode('cookie_lifetime')->end()
->scalarNode('cookie_path')->end()
->scalarNode('cookie_domain')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@ public function testDoNoDuplicateDefaultFormResources()
$this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']);
}

/**
* @dataProvider getTestValidSessionName
*/
public function testValidSessionName($sessionName)
{
$processor = new Processor();
$config = $processor->processConfiguration(
new Configuration(true),
array(array('session' => array('name' => $sessionName)))
);

$this->assertEquals($sessionName, $config['session']['name']);
}

public function getTestValidSessionName()
{
return array(
array(null),
array('PHPSESSID'),
array('a&b'),
array(',_-!@#$%^*(){}:<>/?'),
);
}

/**
* @dataProvider getTestInvalidSessionName
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testInvalidSessionName($sessionName)
{
$processor = new Processor();
$processor->processConfiguration(
new Configuration(true),
array(array('session' => array('name' => $sessionName)))
);
}

public function getTestInvalidSessionName()
{
return array(
array('a.b'),
array('a['),
array('a[]'),
array('a[b]'),
array('a=b'),
array('a+b'),
);
}

/**
* @dataProvider getTestValidTrustedProxiesData
*/
Expand Down
0