Skip to content

Commit eaf2023

Browse files
Merge branch '6.0' into 6
2 parents f23efcd + 01461ff commit eaf2023

File tree

5 files changed

+32
-54
lines changed

5 files changed

+32
-54
lines changed

src/Control/RequestHandler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ class RequestHandler extends ModelData
117117
*/
118118
private static $allowed_actions = null;
119119

120+
/**
121+
* If the request is handed off to a nested request handler, and that handler returns an array,
122+
* by default this handler will be customised with that returned array.
123+
* Setting this to true will return the array directly instead, which treats it as through this handler
124+
* returned the array from an action method directly.
125+
*/
126+
private static bool $customise_array_return_value = true;
127+
120128
public function __construct()
121129
{
122130
$this->brokenOnConstruct = false;
@@ -223,7 +231,7 @@ public function handleRequest(HTTPRequest $request)
223231
$returnValue = $result->handleRequest($request);
224232

225233
// Array results can be used to handle
226-
if (is_array($returnValue)) {
234+
if (is_array($returnValue) && static::config()->get('customise_array_return_value')) {
227235
$returnValue = $this->customise($returnValue);
228236
}
229237

src/Control/Session.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use BadMethodCallException;
66
use SilverStripe\Core\Config\Configurable;
7-
use SilverStripe\Dev\Deprecation;
87

98
/**
109
* Handles all manipulation of the session.
@@ -128,13 +127,6 @@ class Session
128127
*/
129128
private static bool $cookie_secure = true;
130129

131-
/**
132-
* @config
133-
* @var string
134-
* @deprecated 5.4.3 Will be removed without equivalent functionality to replace it
135-
*/
136-
private static $cookie_name_secure = 'SECSESSID';
137-
138130
/**
139131
* Must be "Strict", "Lax", or "None".
140132
* @config
@@ -231,7 +223,7 @@ public function __construct($data)
231223
*/
232224
public function init(HTTPRequest $request)
233225
{
234-
if (!$this->isStarted() && $this->requestContainsSessionId($request)) {
226+
if (!$this->isStarted() && $this->requestContainsSessionId()) {
235227
$this->start($request);
236228
}
237229

@@ -266,19 +258,12 @@ public function isStarted()
266258
}
267259

268260
/**
269-
* @param HTTPRequest $request - deprecated will be removed
270261
* @return bool
271262
*/
272-
public function requestContainsSessionId(HTTPRequest $request)
263+
public function requestContainsSessionId()
273264
{
274-
Deprecation::noticeWithNoReplacment(
275-
'5.4.3',
276-
'The $request parameter is deprecated and will be removed',
277-
Deprecation::SCOPE_GLOBAL
278-
);
279-
$secure = Director::is_https($request) && $this->config()->get('cookie_secure');
280-
$name = $secure ? $this->config()->get('cookie_name_secure') : session_name();
281-
return (bool)Cookie::get($name);
265+
$name = session_name();
266+
return (bool) Cookie::get($name);
282267
}
283268

284269
/**
@@ -299,7 +284,7 @@ public function start(HTTPRequest $request)
299284
// If the session cookie is already set, then the session can be read even if headers_sent() = true
300285
// This helps with edge-case such as debugging.
301286
$data = [];
302-
if (!session_id() && (!headers_sent() || $this->requestContainsSessionId($request))) {
287+
if (!session_id() && (!headers_sent() || $this->requestContainsSessionId())) {
303288
if (!headers_sent()) {
304289
$cookieParams = $this->buildCookieParams($request);
305290
session_set_cookie_params($cookieParams);
@@ -314,19 +299,11 @@ public function start(HTTPRequest $request)
314299
session_save_path($session_path);
315300
}
316301

317-
// If we want a secure cookie for HTTPS, use a separate session name. This lets us have a
318-
// separate (less secure) session for non-HTTPS requests
319-
// if headers_sent() is true then it's best to throw the resulting error rather than risk
320-
// a security hole.
321-
if ($cookieParams['secure']) {
322-
session_name($this->config()->get('cookie_name_secure'));
323-
}
324-
325302
session_start();
326303

327304
// Session start emits a cookie, but only if there's no existing session. If there is a session timeout
328305
// tied to this request, make sure the session is held for the entire timeout by refreshing the cookie age.
329-
if ($cookieParams['lifetime'] && $this->requestContainsSessionId($request)) {
306+
if ($cookieParams['lifetime'] && $this->requestContainsSessionId()) {
330307
Cookie::set(
331308
session_name(),
332309
session_id(),

src/Forms/GridField/GridFieldDetailForm_ItemRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace SilverStripe\Forms\GridField;
44

55
use LogicException;
6-
use SilverStripe\Admin\LeftAndMain;
6+
use SilverStripe\Admin\AdminController;
77
use SilverStripe\Control\Controller;
88
use SilverStripe\Control\HTTPRequest;
99
use SilverStripe\Control\HTTPResponse;
@@ -285,7 +285,7 @@ public function ItemEditForm()
285285
}
286286

287287
$toplevelController = $this->getToplevelController();
288-
if ($toplevelController && $toplevelController instanceof LeftAndMain) {
288+
if ($toplevelController && $toplevelController instanceof AdminController) {
289289
// Always show with base template (full width, no other panels),
290290
// regardless of overloaded CMS controller templates.
291291
$form->setTemplate([
@@ -513,7 +513,7 @@ protected function getBackLink()
513513
{
514514
$backlink = '';
515515
$toplevelController = $this->getToplevelController();
516-
if ($toplevelController && $toplevelController instanceof LeftAndMain) {
516+
if ($toplevelController && $toplevelController instanceof AdminController) {
517517
if ($toplevelController->hasMethod('Backlink')) {
518518
$backlink = $toplevelController->Backlink();
519519
} elseif ($this->popupController->hasMethod('Breadcrumbs')) {
@@ -849,7 +849,7 @@ public function doDelete($data, $form)
849849
);
850850

851851
$toplevelController = $this->getToplevelController();
852-
if ($toplevelController && $toplevelController instanceof LeftAndMain) {
852+
if ($toplevelController && $toplevelController instanceof AdminController) {
853853
$backForm = $toplevelController->getEditForm();
854854
$backForm->sessionMessage($message, 'good', ValidationResult::CAST_HTML);
855855
} else {

src/Security/MemberAuthenticator/ChangePasswordHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class ChangePasswordHandler extends RequestHandler
4747
'' => 'changepassword',
4848
];
4949

50+
private static bool $customise_array_return_value = false;
51+
5052
/**
5153
* Keep track of whether a temporary hash is already generated during this request cycle.
5254
* @internal
@@ -282,15 +284,16 @@ public function doChangePassword(array $data, $form)
282284
$session = $this->getRequest()->getSession();
283285
if (!$member) {
284286
$autoLoginHash = $session->get('AutoLoginHash');
285-
if ($autoLoginHash) {
286-
$member = Member::member_from_autologinhash($autoLoginHash);
287+
if (!$autoLoginHash) {
288+
// The user is not logged in and had no reset token, so give them a login form.
289+
return $this->redirect($this->addBackURLParam(Security::singleton()->Link('login')));
287290
}
288291

289-
// The user is not logged in and no valid auto login hash is available
292+
$member = Member::member_from_autologinhash($autoLoginHash);
290293
if (!$member) {
294+
// Hash was invalid or expired
291295
$session->clear('AutoLoginHash');
292-
293-
return $this->redirect($this->addBackURLParam(Security::singleton()->Link('login')));
296+
return $this->getInvalidTokenResponse();
294297
}
295298
}
296299

tests/php/Control/SessionTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testStartUsesDefaultCookieNameWithHttp()
7474
Cookie::set(session_name(), '1234');
7575
$session = new Session(null); // unstarted session
7676
$session->start($req);
77-
$this->assertNotEquals(session_name(), $session->config()->get('cookie_name_secure'));
77+
$this->assertEquals(session_name(), 'PHPSESSID');
7878
}
7979

8080
#[RunInSeparateProcess]
@@ -87,7 +87,7 @@ public function testStartUsesDefaultCookieNameWithHttpsAndCookieSecureOff()
8787
$session = new Session(null); // unstarted session
8888
$session->config()->set('cookie_secure', false);
8989
$session->start($req);
90-
$this->assertNotEquals(session_name(), $session->config()->get('cookie_name_secure'));
90+
$this->assertEquals(session_name(), 'PHPSESSID');
9191
}
9292

9393
#[RunInSeparateProcess]
@@ -99,7 +99,7 @@ public function testStartUsesSecureCookieNameWithHttpsAndCookieSecureOn()
9999
Cookie::set(session_name(), '1234');
100100
$session = new Session(null); // unstarted session
101101
$session->start($req);
102-
$this->assertEquals(session_name(), $session->config()->get('cookie_name_secure'));
102+
$this->assertEquals(session_name(), 'PHPSESSID');
103103
}
104104

105105
#[RunInSeparateProcess]
@@ -242,19 +242,9 @@ public function testRequestContainsSessionId()
242242
{
243243
$req = new HTTPRequest('GET', '/');
244244
$session = new Session(null); // unstarted session
245-
$this->assertFalse($session->requestContainsSessionId($req));
245+
$this->assertFalse($session->requestContainsSessionId());
246246
Cookie::set(session_name(), '1234');
247-
$this->assertTrue($session->requestContainsSessionId($req));
248-
}
249-
250-
public function testRequestContainsSessionIdRespectsCookieNameSecure()
251-
{
252-
$req = (new HTTPRequest('GET', '/'))
253-
->setScheme('https');
254-
$session = new Session(null); // unstarted session
255-
Cookie::set($session->config()->get('cookie_name_secure'), '1234');
256-
$session->config()->set('cookie_secure', true);
257-
$this->assertTrue($session->requestContainsSessionId($req));
247+
$this->assertTrue($session->requestContainsSessionId());
258248
}
259249

260250
public function testUserAgentLockout()

0 commit comments

Comments
 (0)