Silverstripe-framework: Security::permissionFailure() assumes session is available

Created on 8 Jul 2019  路  7Comments  路  Source: silverstripe/silverstripe-framework

Affected Version

4.x

Description

Security::permissionFailure() attempts to store a back URL in the session without checking whether a session is available on the request object:

https://github.com/silverstripe/silverstripe-framework/blob/d04e54c1bea46c17bb8bf4a3ec661833d4127de6/src/Security/Security.php#L426

This may result in an exception:

BadMethodCallException: "No session available for this HTTPRequest"

I believe this happened because the current request was a NullHTTPRequest. The setup that reached this error is a bit complex (it involves elemental + userforms + elemental-userforms + page access controls), but it鈥檚 a simple change to code defensively here.

affectv4 changpatch efforeasy impaclow typbug

All 7 comments

Yeah, none of HTTPRequest indicates that getRequest() can return null, but I'm pretty sure it can. Do you think this would be a case of "if there's a session, run that logic, else ignore it" or something else like trying to get a session from somewhere else?

Do you think this would be a case of "if there's a session, run that logic, else ignore it" or something else like trying to get a session from somewhere else?

I think the first option is fine, we could achieve that by introducing a simple hasSession() method

Throwing an exception like that in the getter is a bit strange. I'm +1 for the hasSession method.

We can probably do both

Merged https://github.com/silverstripe/silverstripe-framework/pull/9152 but I鈥檒l leave this open until hasSession() is added to a minor release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dnsl48 picture dnsl48  路  6Comments

leomeloxp picture leomeloxp  路  4Comments

maxime-rainville picture maxime-rainville  路  6Comments

Cheddam picture Cheddam  路  3Comments

sminnee picture sminnee  路  6Comments