From b4efc66e2854c100780174af5689df3f2073fbda Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Feb 2026 15:29:17 +0000
Subject: [PATCH 1/5] Initial plan
From c3bb94c95e8d2d70fc567d850a4ca6ca73011cd3 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Feb 2026 15:34:22 +0000
Subject: [PATCH 2/5] Add DashboardController with robust User-Agent parsing
and comprehensive tests
Co-authored-by: mrsharm <68247673+mrsharm@users.noreply.github.com>
---
Controllers/DashboardController.cs | 111 ++++++++
.../DashboardControllerTests.cs | 251 ++++++++++++++++++
.../WebApp_AppService.Tests.csproj | 28 ++
WebApp_AppService.csproj | 6 +
WebApp_AppService.sln | 28 +-
5 files changed, 423 insertions(+), 1 deletion(-)
create mode 100644 Controllers/DashboardController.cs
create mode 100644 WebApp_AppService.Tests/DashboardControllerTests.cs
create mode 100644 WebApp_AppService.Tests/WebApp_AppService.Tests.csproj
diff --git a/Controllers/DashboardController.cs b/Controllers/DashboardController.cs
new file mode 100644
index 0000000..d660bb6
--- /dev/null
+++ b/Controllers/DashboardController.cs
@@ -0,0 +1,111 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace WebApp_AppService.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class DashboardController : ControllerBase
+ {
+ ///
+ /// Extracts a critical segment from User-Agent string with proper bounds checking
+ /// to prevent IndexOutOfRangeException
+ ///
+ /// The User-Agent string to parse
+ /// Critical segment or a safe default value
+ private string ExtractCriticalSegment(string? userAgent)
+ {
+ // Defensive check: Handle null or empty User-Agent
+ if (string.IsNullOrWhiteSpace(userAgent))
+ {
+ return "Unknown";
+ }
+
+ try
+ {
+ // Split by common delimiters in User-Agent strings
+ var segments = userAgent.Split(new[] { ' ', '/', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
+
+ // Bounds check: Ensure we have at least one segment
+ if (segments.Length == 0)
+ {
+ return "Unknown";
+ }
+
+ // Safely access the first segment
+ // In production, this might target a specific index, but with bounds checking
+ var criticalSegment = segments.Length > 0 ? segments[0] : "Unknown";
+
+ // Additional validation: Ensure the segment is not empty after trim
+ criticalSegment = criticalSegment.Trim();
+ if (string.IsNullOrEmpty(criticalSegment))
+ {
+ return "Unknown";
+ }
+
+ // Limit the length to prevent potential buffer issues
+ const int maxLength = 100;
+ if (criticalSegment.Length > maxLength)
+ {
+ criticalSegment = criticalSegment.Substring(0, maxLength);
+ }
+
+ return criticalSegment;
+ }
+ catch (Exception)
+ {
+ // Catch any unexpected exceptions during parsing
+ return "Unknown";
+ }
+ }
+
+ ///
+ /// Admin dashboard endpoint that processes User-Agent information
+ ///
+ /// Dashboard information including parsed User-Agent segment
+ [HttpGet]
+ [Route("admin")]
+ public ActionResult