mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-11 06:18:39 +00:00
Add more sanitization to reduce deserialization errors
This commit is contained in:
parent
5e82827fc0
commit
a253e768a7
2 changed files with 7 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -29,9 +30,13 @@ public static class ControllerExtensions
|
|||
|
||||
try
|
||||
{
|
||||
// Prevent unescaped ampersands from causing deserialization to fail
|
||||
bodyString = Regex.Replace(bodyString, "&(?!(amp|apos|quot|lt|gt);)", "&");
|
||||
|
||||
XmlRootAttribute? root = null;
|
||||
if (rootElements.Length > 0)
|
||||
{
|
||||
//TODO: This doesn't support root tags with attributes, but it's only used in scenarios where there shouldn't any (UpdateUser and Playlists)
|
||||
string? matchedRoot = rootElements.FirstOrDefault(e => bodyString.StartsWith($@"<{e}>"));
|
||||
if (matchedRoot == null)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,8 @@ public static class SanitizationHelper
|
|||
private static readonly Dictionary<string, string> charsToReplace = new() {
|
||||
{"<", "<"},
|
||||
{">", ">"},
|
||||
{"\"", """},
|
||||
{"'", "'"},
|
||||
};
|
||||
|
||||
public static void SanitizeStringsInClass(object? instance)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue