Skip to content
Snippets Groups Projects
Commit 7e392041 authored by Andjelko Horvat's avatar Andjelko Horvat
Browse files

SimpleSAML_SessionHandler::setCookie: deny setting secure cookie on http (issue 416).

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2876 44740490-163a-0410-bde0-09ae8108e29a
parent 8821f75a
No related branches found
No related tags found
No related merge requests found
...@@ -136,6 +136,12 @@ abstract class SimpleSAML_SessionHandler { ...@@ -136,6 +136,12 @@ abstract class SimpleSAML_SessionHandler {
$params = $this->getCookieParams(); $params = $this->getCookieParams();
// Do not set secure cookie if not on HTTPS
if ($params['secure'] && !SimpleSAML_Utilities::isHTTPS()) {
SimpleSAML_Logger::warning('Setting secure cookie on http not allowed.');
return;
}
if ($value === NULL) { if ($value === NULL) {
$expire = time() - 365*24*60*60; $expire = time() - 365*24*60*60;
} elseif ($params['lifetime'] === 0) { } elseif ($params['lifetime'] === 0) {
...@@ -146,9 +152,12 @@ abstract class SimpleSAML_SessionHandler { ...@@ -146,9 +152,12 @@ abstract class SimpleSAML_SessionHandler {
$version = explode('.', PHP_VERSION); $version = explode('.', PHP_VERSION);
if ((int)$version[0] === 5 && (int)$version[1] < 2) { if ((int)$version[0] === 5 && (int)$version[1] < 2) {
setcookie($name, $value, $expire, $params['path'], $params['domain'], $params['secure']); $success = setcookie($name, $value, $expire, $params['path'], $params['domain'], $params['secure']);
} else { } else {
setcookie($name, $value, $expire, $params['path'], $params['domain'], $params['secure'], $params['httponly']); $success = setcookie($name, $value, $expire, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
if (!$success) {
throw new SimpleSAML_Error_Exception('Error setting cookie - headers already sent.');
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment