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

Commit 92fe165

Browse files
authored
Merge pull request #12 from DuendeSoftware/roland/securesss
Secure ServerSideSessions page in the same way as Diagnostics
2 parents 4b92023 + c8f4e2c commit 92fe165

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
/.vs

Pages/Diagnostics/Index.cshtml.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@ public class Index : PageModel
1616

1717
public async Task<IActionResult> OnGet()
1818
{
19-
var localAddresses = new List<string?> { "127.0.0.1", "::1" };
20-
if(HttpContext.Connection.LocalIpAddress != null)
21-
{
22-
localAddresses.Add(HttpContext.Connection.LocalIpAddress.ToString());
23-
}
24-
25-
if (!localAddresses.Contains(HttpContext.Connection.RemoteIpAddress?.ToString()))
26-
{
19+
//Replace with an authorization policy check
20+
if (HttpContext.Connection.IsRemote())
2721
return NotFound();
28-
}
2922

3023
View = new ViewModel(await HttpContext.AuthenticateAsync());
3124

Pages/Extensions.cs

+18
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,22 @@ internal static IActionResult LoadingPage(this PageModel page, string? redirectU
3939

4040
return page.RedirectToPage("/Redirect/Index", new { RedirectUri = redirectUri });
4141
}
42+
43+
/// <summary>
44+
/// Check for a remote connection (non-localhost)
45+
/// </summary>
46+
internal static bool IsRemote(this ConnectionInfo connection)
47+
{
48+
var localAddresses = new List<string?> { "127.0.0.1", "::1" };
49+
if (connection.LocalIpAddress != null)
50+
{
51+
localAddresses.Add(connection.LocalIpAddress.ToString());
52+
}
53+
54+
if (!localAddresses.Contains(connection.RemoteIpAddress?.ToString()))
55+
{
56+
return true;
57+
}
58+
return false;
59+
}
4260
}

Pages/ServerSideSessions/Index.cshtml.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public IndexModel(ISessionManagementService? sessionManagementService = null)
3535
[BindProperty(SupportsGet = true)]
3636
public string? Prev { get; set; }
3737

38-
public async Task OnGet()
38+
public async Task<ActionResult> OnGet()
3939
{
40+
//Replace with an authorization policy check
41+
if (HttpContext.Connection.IsRemote())
42+
return NotFound();
43+
4044
if (_sessionManagementService != null)
4145
{
4246
UserSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
@@ -48,13 +52,18 @@ public async Task OnGet()
4852
SubjectId = SubjectIdFilter
4953
});
5054
}
55+
return Page();
5156
}
5257

5358
[BindProperty]
5459
public string? SessionId { get; set; }
5560

5661
public async Task<IActionResult> OnPost()
5762
{
63+
//Replace with an authorization policy check
64+
if (HttpContext.Connection.IsRemote())
65+
return NotFound();
66+
5867
ArgumentNullException.ThrowIfNull(_sessionManagementService);
5968

6069
await _sessionManagementService.RemoveSessionsAsync(new RemoveSessionsContext {

0 commit comments

Comments
 (0)