From 683c361935e0a07b636769a026e884d6091f61a0 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Thu, 10 Nov 2022 14:47:23 +0100 Subject: [PATCH] clean up push data validation --- .../MareSynchronosServer/Hubs/MareHub.User.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.User.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.User.cs index 325e500..f5905ab 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.User.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.User.cs @@ -121,7 +121,7 @@ public partial class MareHub [GeneratedRegex(@"^[A-Z0-9]{40}$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ECMAScript)] private static partial Regex HashRegex(); - [GeneratedRegex(@"^([a-z0-9_]+\/)+(([a-z0-9_])+(\.[a-z]{3,4}))$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ECMAScript)] + [GeneratedRegex(@"^([a-z0-9_]{3,}\/)+([a-z0-9_-]+\.[a-z]{3,4})$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ECMAScript)] private static partial Regex GamePathRegex(); [Authorize(Policy = "Identified")] @@ -131,11 +131,10 @@ public partial class MareHub foreach (var replacement in characterCache.FileReplacements.SelectMany(p => p.Value)) { - //bool validGamePaths = replacement.GamePaths.All(p => GamePathRegex().IsMatch(p)); - bool validGamePaths = true; + replacement.GamePaths = replacement.GamePaths.Where(p => GamePathRegex().IsMatch(p)).ToArray(); + bool validGamePaths = replacement.GamePaths.Any(); bool validHash = string.IsNullOrEmpty(replacement.Hash) || HashRegex().IsMatch(replacement.Hash); - //bool validFileSwapPath = string.IsNullOrEmpty(replacement.FileSwapPath) || GamePathRegex().IsMatch(replacement.FileSwapPath); - bool validFileSwapPath = true; + bool validFileSwapPath = string.IsNullOrEmpty(replacement.FileSwapPath) || GamePathRegex().IsMatch(replacement.FileSwapPath); if (!validGamePaths || !validHash || !validFileSwapPath) { _logger.LogCallWarning(MareHubLogger.Args("Invalid Data", "GamePaths", validGamePaths, "Hash", validHash, "FileSwap", validFileSwapPath));