Skip to content
Snippets Groups Projects
Commit f50f0297 authored by Jaime Pérez's avatar Jaime Pérez
Browse files

Start using the error codes in SimpleSAML\Error\CannotSetCookie.

Both SimpleSAML_SessionHandlerPHP::setCookie() and SimpleSAML\Utils\HTTP::setCookie() throw the SimpleSAML\Error\CannotSetCookie exception. Depending on why the error was generated, set the error code in the exception accordingly.
parent 0c660fda
No related branches found
No related tags found
No related merge requests found
......@@ -322,11 +322,17 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
}
if ($cookieParams['secure'] && !\SimpleSAML\Utils\HTTP::isHTTPS()) {
throw new SimpleSAML\Error\CannotSetCookie('Secure cookies not allowed on http.');
throw new \SimpleSAML\Error\CannotSetCookie(
'Secure cookies not allowed on http.',
\SimpleSAML\Error\CannotSetCookie::SECURE_COOKIE
);
}
if (headers_sent()) {
throw new SimpleSAML\Error\CannotSetCookie('Headers already sent.');
throw new \SimpleSAML\Error\CannotSetCookie(
'Headers already sent.',
\SimpleSAML\Error\CannotSetCookie::HEADERS_SENT
);
}
session_set_cookie_params(
......
......@@ -1041,7 +1041,13 @@ class HTTP
// Do not set secure cookie if not on HTTPS
if ($params['secure'] && !self::isHTTPS()) {
Logger::warning('Setting secure cookie on plain HTTP is not allowed.');
if ($throw) {
throw new \SimpleSAML\Error\CannotSetCookie(
'Setting secure cookie on plain HTTP is not allowed.',
\SimpleSAML\Error\CannotSetCookie::SECURE_COOKIE
);
}
Logger::warning('Error setting cookie: setting secure cookie on plain HTTP is not allowed.');
return;
}
......@@ -1079,10 +1085,12 @@ class HTTP
if (!$success) {
if ($throw) {
throw new \SimpleSAML\Error\CannotSetCookie('Headers already sent.');
} else {
Logger::warning('Error setting cookie: headers already sent.');
throw new \SimpleSAML\Error\CannotSetCookie(
'Headers already sent.',
\SimpleSAML\Error\CannotSetCookie::HEADERS_SENT
);
}
Logger::warning('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