mirror of
https://github.com/flarum/core.git
synced 2025-08-03 15:07:53 +02:00
Overhaul sessions, tokens, and authentication
- Use cookies + CSRF token for API authentication in the default client. This mitigates potential XSS attacks by making the token unavailable to JavaScript. The Authorization header is still supported, but not used by default. - Make sensitive/destructive actions (editing a user, permanently deleting anything, visiting the admin CP) require the user to re-enter their password if they haven't entered it in the last 30 minutes. - Refactor and clean up the authentication middleware. - Add an `onhide` hook to the Modal component. (+1 squashed commit)
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
|
||||
namespace Flarum\Core\Access;
|
||||
|
||||
use Flarum\Api\Exception\InvalidAccessTokenException;
|
||||
use Flarum\Core\Exception\PermissionDeniedException;
|
||||
use Flarum\Core\User;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
trait AssertPermissionTrait
|
||||
{
|
||||
@@ -61,6 +63,30 @@ trait AssertPermissionTrait
|
||||
*/
|
||||
protected function assertAdmin(User $actor)
|
||||
{
|
||||
$this->assertPermission($actor->isAdmin());
|
||||
$this->assertCan($actor, 'administrate');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @throws InvalidAccessTokenException
|
||||
*/
|
||||
protected function assertSudo(ServerRequestInterface $request)
|
||||
{
|
||||
$session = $request->getAttribute('session');
|
||||
|
||||
if (! $session || ! $session->isSudo()) {
|
||||
throw new InvalidAccessTokenException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @throws PermissionDeniedException
|
||||
*/
|
||||
protected function assertAdminAndSudo(ServerRequestInterface $request)
|
||||
{
|
||||
$this->assertAdmin($request->getAttribute('actor'));
|
||||
|
||||
$this->assertSudo($request);
|
||||
}
|
||||
}
|
||||
|
@@ -135,7 +135,7 @@ class User extends AbstractModel
|
||||
|
||||
$user->read()->detach();
|
||||
$user->groups()->detach();
|
||||
$user->accessTokens()->delete();
|
||||
$user->sessions()->delete();
|
||||
$user->notifications()->delete();
|
||||
});
|
||||
|
||||
@@ -654,13 +654,13 @@ class User extends AbstractModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the user's access tokens.
|
||||
* Define the relationship with the user's sessions.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function accessTokens()
|
||||
public function sessions()
|
||||
{
|
||||
return $this->hasMany('Flarum\Api\AccessToken');
|
||||
return $this->hasMany('Flarum\Http\Session');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user