Skip to content

Commit 1a54996

Browse files
mattleibowCopilot
andcommitted
Address review findings: open redirect and teardown error handling
- Login endpoint now validates returnUrl is a well-formed relative URI to prevent open-redirect attacks (GPT 5.4 finding) - Teardown script checks exit codes after each az ad app delete and preserves the setup data file if deletion fails (GPT 5.4 finding) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ba08cc3 commit 1a54996

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

10.0/MauiBlazorWebEntraWorkforce/MauiBlazorWebEntraWorkforce.Web/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@
8181
// Login endpoint: triggers the OIDC redirect to the workforce tenant
8282
app.MapGet("/authentication/login", async (HttpContext context, string? returnUrl) =>
8383
{
84+
// Only allow local return URLs to prevent open-redirect attacks.
85+
if (string.IsNullOrEmpty(returnUrl) || !Uri.IsWellFormedUriString(returnUrl, UriKind.Relative))
86+
returnUrl = "/";
87+
8488
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme,
85-
new AuthenticationProperties { RedirectUri = returnUrl ?? "/" });
89+
new AuthenticationProperties { RedirectUri = returnUrl });
8690
});
8791

8892
// Logout endpoint: clears cookie and signs out of Entra

10.0/MauiBlazorWebEntraWorkforce/scripts/Teardown-Azure.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,29 @@ if ($confirm -notmatch "^[Yy]$") {
4141
exit 0
4242
}
4343

44+
$failed = $false
45+
4446
az ad app delete --id $data.mauiClientId 2>&1 | Out-Null
47+
if ($LASTEXITCODE -ne 0) {
48+
Write-Warning "Failed to delete MAUI app registration: $($data.mauiClientId)"
49+
$failed = $true
50+
} else {
51+
Write-Host " Deleted MAUI app: $($data.mauiClientId)" -ForegroundColor Green
52+
}
53+
4554
az ad app delete --id $data.webClientId 2>&1 | Out-Null
55+
if ($LASTEXITCODE -ne 0) {
56+
Write-Warning "Failed to delete web app registration: $($data.webClientId)"
57+
$failed = $true
58+
} else {
59+
Write-Host " Deleted web app: $($data.webClientId)" -ForegroundColor Green
60+
}
61+
62+
if ($failed) {
63+
Write-Error "One or more app registrations could not be deleted. The setup data file has been kept."
64+
exit 1
65+
}
66+
4667
Remove-Item $dataPath -Force
4768

4869
Write-Host ""

0 commit comments

Comments
 (0)