diff --git a/samples/OpenIdConnect.AzureAdSample/Startup.cs b/samples/OpenIdConnect.AzureAdSample/Startup.cs index f0c2f7c221..45304e1bd6 100644 --- a/samples/OpenIdConnect.AzureAdSample/Startup.cs +++ b/samples/OpenIdConnect.AzureAdSample/Startup.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; @@ -106,7 +107,7 @@ namespace OpenIdConnect.AzureAdSample { await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); await WriteHtmlAsync(context.Response, - response => response.WriteAsync($"

Signed out locally: {context.User.Identity.Name}

Sign In")); + response => response.WriteAsync($"

Signed out locally: {HtmlEncode(context.User.Identity.Name)}

Sign In")); } else if (context.Request.Path.Equals("/signout-remote")) { @@ -120,7 +121,7 @@ namespace OpenIdConnect.AzureAdSample { await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); await WriteHtmlAsync(context.Response, - response => response.WriteAsync($"

Signed out remotely: {context.User.Identity.Name}

Sign In")); + response => response.WriteAsync($"

Signed out remotely: {HtmlEncode(context.User.Identity.Name)}

Sign In")); } else { @@ -132,7 +133,7 @@ namespace OpenIdConnect.AzureAdSample await WriteHtmlAsync(context.Response, async response => { - await response.WriteAsync($"

Hello Authenticated User {context.User.Identity.Name}

"); + await response.WriteAsync($"

Hello Authenticated User {HtmlEncode(context.User.Identity.Name)}

"); await response.WriteAsync("Sign Out Locally"); await response.WriteAsync("Sign Out Remotely"); @@ -152,7 +153,7 @@ namespace OpenIdConnect.AzureAdSample } catch (Exception ex) { - await response.WriteAsync($"AquireToken error: {ex.Message}
{Environment.NewLine}"); + await response.WriteAsync($"AquireToken error: {ex.Message}"); } }); } @@ -189,6 +190,9 @@ namespace OpenIdConnect.AzureAdSample } await response.WriteAsync(""); } + + private static string HtmlEncode(string content) => + string.IsNullOrEmpty(content) ? string.Empty : HtmlEncoder.Default.Encode(content); } }