Skip to content

Commit 4810e65

Browse files
authored
Merge pull request #243 from creative-commoners/pulls/4.0/do-not-store-password
FIX SessionStore no longer persists the member's password during MFA login
2 parents c15efc1 + 8396339 commit 4810e65

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

docs/en/datastores.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ SilverStripe\Core\Injector\Injector:
1515
1616
Please note that the store should always be treated as a server side implementation. It's not a good idea to implement
1717
a client store e.g. cookies.
18+
19+
## Adjusting what goes into the store
20+
21+
By default, the entire HTTPRequest object is saved to the store during the multi-factor authentication process. We
22+
exclude the `Password` field from the request by default, but if you need to exclude other fields, you can add an
23+
extension, for example:
24+
25+
```php
26+
// Apply extension to \SilverStripe\MFA\Authenticator\LoginHandler
27+
class MyLoginHandlerExtension extends Extension
28+
{
29+
public function onBeforeSaveRequestToStore(HTTPRequest $request, StoreInterface $store): void
30+
{
31+
$request->offsetUnset('MySecretField');
32+
}
33+
```

src/Authenticator/LoginHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public function doLogin($data, MemberLoginForm $form, HTTPRequest $request)
9696

9797
// Create a store for handling MFA for this member
9898
$store = $this->createStore($member);
99+
// We don't need to store the user's password
100+
$request->offsetUnset('Password');
101+
// User code may adjust the request properties further if they have their own sensitive data which
102+
// should be excluded from the store.
103+
$this->extend('onBeforeSaveRequestToStore', $request, $store);
99104
$store->save($request);
100105

101106
// Store the BackURL for use after the process is complete

0 commit comments

Comments
 (0)