Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit dedda79

Browse files
authored
Merge pull request #83 from pranavkm/patch-1
Remove random XSS code
2 parents 5c002c3 + 3c934ee commit dedda79

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

docs/3. Add front-end, render agenda, set up front-end models.md

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,9 @@ In this session, we'll add the front end web site, with a public (anonymous) hom
364364

365365
DayOffset = Session.StartTime?.Subtract(startDate ?? DateTimeOffset.MinValue).Days;
366366

367-
if (!string.IsNullOrEmpty(Session.Abstract))
368-
{
369-
Session.Abstract = "<p>" + String.Join("</p><p>", Session.Abstract.Split("\r\n", StringSplitOptions.RemoveEmptyEntries)) + "</p>";
370-
}
367+
return Page();
368+
}
371369

372-
return Page();
373-
}
374370
```
375371
1. Open the *Session.cshtml* file and add markup to display the details and navigation UI:
376372
``` html
@@ -391,32 +387,10 @@ In this session, we'll add the front end web site, with a public (anonymous) hom
391387
<em><a asp-page="Speaker" asp-route-id="@speaker.ID">@speaker.Name</a></em>
392388
}
393389

394-
<p>@Html.Raw(Model.Session.Abstract)</p>
395-
```
396-
397-
## HTML Encoding the Session Abstract
398-
Currently, the *Session* Abstract is displayed using `@Html.Raw()`. This makes it vulnerable to Cross-Site Scripting (XSS) and Injection Attacks, since an abstract could contain JavaScript. We'll update `Session.cshtml.cs` to HTML encode the Abstract to protect against these attacks.
399-
400-
1. Add an `HtmlEncoder` field to the `SessionModel` using the following code:
401-
```csharp
402-
private readonly HtmlEncoder _htmlEncoder;
403-
```
404-
1. Update the `SessionModel` constructor to inject an `HtmlEncoder`:
405-
```csharp
406-
public SessionModel(IApiClient apiClient, HtmlEncoder htmlEncoder)
407-
{
408-
_apiClient = apiClient;
409-
_htmlEncoder = htmlEncoder;
410-
}
411-
```
412-
1. Update the section of the `OnGet()` method that handles `Session.Abstract` to encode the output.
413-
```csharp
414-
if (!string.IsNullOrEmpty(Session.Abstract))
415-
{
416-
var encodedCrLf = _htmlEncoder.Encode("\r\n");
417-
var encodedAbstract = _htmlEncoder.Encode(Session.Abstract);
418-
Session.Abstract = "<p>" + String.Join("</p><p>", encodedAbstract.Split(encodedCrLf, StringSplitOptions.RemoveEmptyEntries)) + "</p>";
419-
}
390+
@foreach (var para in Model.Session.Abstract.Split("\r\n", StringSplitOptions.RemoveEmptyEntries))
391+
{
392+
<p>@para</p>
393+
}
420394
```
421395

422396
## Add a page to show speaker details

0 commit comments

Comments
 (0)