Skip to content

Commit

Permalink
protect invoke other sessions endpoint with anti forgery token
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Jan 11, 2024
1 parent e3e7431 commit 4d3af83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions KratosSelfService/Controllers/SessionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ public async Task<IActionResult> Sessions()
return View("Sessions", model);
}

[HttpGet("sessions-logout")]
public async Task<IActionResult> LogoutAllOtherSessions()
[HttpPost("sessions")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> LogoutAllOtherSessions([FromForm] string? action)
{
//TODO: protect with anti forgery token
_ = await api.Frontend.DisableMyOtherSessionsAsync(cookie: Request.Headers.Cookie);
if (action == "invokeSessions")
{
_ = await api.Frontend.DisableMyOtherSessionsAsync(cookie: Request.Headers.Cookie);
}

return Redirect("sessions");
}
}
14 changes: 9 additions & 5 deletions KratosSelfService/Views/Sessions/Sessions.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using UAParser
@using Microsoft.AspNetCore.Components.Web
@model SessionsModel
@{
Layout = "_NavbarLayout";
Expand Down Expand Up @@ -96,11 +97,14 @@
}
else
{
<div class="buttons">
<a class="button is-warning" href="sessions-logout">
@CustomTranslator.Get("sessions.logoutOtherSessions")
</a>
</div>
<form action="/sessions" method="post">
@Html.AntiForgeryToken()
<div class="buttons">
<button type="submit" class="button is-warning" name="action" value="invokeSessions">
@CustomTranslator.Get("sessions.logoutOtherSessions")
</button>
</div>
</form>
<table class="table is-fullwidth">
<thead>
<tr>
Expand Down

0 comments on commit 4d3af83

Please sign in to comment.