Skip to content

Commit

Permalink
Merge pull request #91 from Lakshan-Madushanka/Fix-login-vulnerabilities
Browse files Browse the repository at this point in the history
Fix login vulnerabilities
  • Loading branch information
tnylea authored Jul 11, 2024
2 parents fd4669e + 670d284 commit ea968c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions resources/views/pages/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ public function authenticate()
event(new Login(auth()->guard('web'), $this->userModel->where('email', $this->email)->first(), true));
if(session()->get('url.intended') != route('logout.get')){
session()->regenerate();
redirect()->intended(config('devdojo.auth.settings.redirect_after_auth'));
} else {
session()->regenerate();
return redirect(config('devdojo.auth.settings.redirect_after_auth'));
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources/views/pages/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ public function register()
}
if (session()->get('url.intended') != route('logout.get')) {
session()->regenerate();
redirect()->intended(config('devdojo.auth.settings.redirect_after_auth'));
} else {
session()->regenerate();
return redirect(config('devdojo.auth.settings.redirect_after_auth'));
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/Http/Controllers/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@
namespace Devdojo\Auth\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LogoutController
{
public function __invoke(): RedirectResponse
public function __invoke(Request $request): RedirectResponse
{
Auth::logout();

$this->clearTraces($request);

return redirect()->route('home');
}

public function getLogout()
public function getLogout(Request $request)
{
Auth::logout();
Session()->flush();

$this->clearTraces($request);

return redirect('/');
}

private function clearTraces(Request $request): void
{
$request->session()->invalidate();
$request->session()->regenerateToken();
}
}

0 comments on commit ea968c7

Please sign in to comment.