Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4d3af83

Browse files
committed
protect invoke other sessions endpoint with anti forgery token
1 parent e3e7431 commit 4d3af83

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

KratosSelfService/Controllers/SessionsController.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ public async Task<IActionResult> Sessions()
1919
return View("Sessions", model);
2020
}
2121

22-
[HttpGet("sessions-logout")]
23-
public async Task<IActionResult> LogoutAllOtherSessions()
22+
[HttpPost("sessions")]
23+
[ValidateAntiForgeryToken]
24+
public async Task<IActionResult> LogoutAllOtherSessions([FromForm] string? action)
2425
{
25-
//TODO: protect with anti forgery token
26-
_ = await api.Frontend.DisableMyOtherSessionsAsync(cookie: Request.Headers.Cookie);
26+
if (action == "invokeSessions")
27+
{
28+
_ = await api.Frontend.DisableMyOtherSessionsAsync(cookie: Request.Headers.Cookie);
29+
}
30+
2731
return Redirect("sessions");
2832
}
2933
}

KratosSelfService/Views/Sessions/Sessions.cshtml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using UAParser
2+
@using Microsoft.AspNetCore.Components.Web
23
@model SessionsModel
34
@{
45
Layout = "_NavbarLayout";
@@ -96,11 +97,14 @@
9697
}
9798
else
9899
{
99-
<div class="buttons">
100-
<a class="button is-warning" href="sessions-logout">
101-
@CustomTranslator.Get("sessions.logoutOtherSessions")
102-
</a>
103-
</div>
100+
<form action="/sessions" method="post">
101+
@Html.AntiForgeryToken()
102+
<div class="buttons">
103+
<button type="submit" class="button is-warning" name="action" value="invokeSessions">
104+
@CustomTranslator.Get("sessions.logoutOtherSessions")
105+
</button>
106+
</div>
107+
</form>
104108
<table class="table is-fullwidth">
105109
<thead>
106110
<tr>

0 commit comments

Comments
 (0)