Skip to content

Commit

Permalink
Add firefox support + some XSS testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Feb 25, 2024
1 parent 7b4140f commit d8f3acf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
14 changes: 13 additions & 1 deletion SU.LorePage/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ public static string GetCurrentDate()
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string ParseContent(string content)
public static string ParseContent(string content, bool isFirefox)
{
// First we escape any HTML tags
content = content.Replace("<", "&lt;");
content = content.Replace(">", "&gt;");

// Since white-space-collapse is not supported in Firefox, we need to replace all new lines with <br> tags
if (isFirefox)
{
content = content.Replace("\n", "<br>");
// We also need to replace all double spaces with &nbsp;
content = content.Replace(" ", "&nbsp; ");
// as well as tabs
content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
// This makes it mostly work, but it's not perfect agh
// TODO: Fix firefox support
}

// Then we replace the placeholders
content = content.Replace("[date]", GetCurrentDate());
Expand Down
3 changes: 2 additions & 1 deletion SU.LorePage/Layout/Screen.razor
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@
var content = responseString.ToCharArray();
try
{
content = Helpers.ParseContent(responseString).ToCharArray();
var isFirefox = await JsRuntime.InvokeAsync<bool>("isFirefox");
content = Helpers.ParseContent(responseString, isFirefox).ToCharArray();
}
catch (Exception e)
{
Expand Down
16 changes: 16 additions & 0 deletions SU.LorePage/wwwroot/Resources/Debug/XSS_Test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#TERMINAL_FILE
TITLE=XSS Test
```
Testing direct XSS
<script>alert('XSS');</script>
Testing escape from color tag
[color=red"><script>alert('XSS');</script>][/color]
Button XSS test
[button=javascript:alert('XSS');Click me]
```

This is a test file used to test XSS vulnerabilities. Never link to this file in any way.
5 changes: 5 additions & 0 deletions SU.LorePage/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
console.error(`Element with id content_${id} not found`);
}
}

function isFirefox() {
return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
}

</script>
</body>

Expand Down

0 comments on commit d8f3acf

Please sign in to comment.