From 23022411809999b02df78eee3128c5c523ba720b Mon Sep 17 00:00:00 2001 From: cmurialdo Date: Tue, 6 Sep 2022 10:53:38 -0300 Subject: [PATCH] Avoid external control of file name when loading svc files. --- .../GxClasses.Web/Middleware/GXRouting.cs | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs b/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs index ccaf7d06f..09d5bbddd 100644 --- a/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs +++ b/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs @@ -34,6 +34,8 @@ internal class GXRouting : IGXRouting static char[] urlSeparator = { '/', '\\' }; const char QUESTIONMARK = '?'; const string oauthRoute = "/oauth"; + const string SvcExtension = ".svc"; + const string SvcExtensionPattern = "*.svc"; public static string UrlTemplateControllerWithParms; //Azure Functions @@ -48,6 +50,7 @@ internal class GXRouting : IGXRouting public Dictionary> servicesMap = new Dictionary>(); public Dictionary, String>> servicesMapData = new Dictionary, string>>(); public Dictionary> servicesValidPath = new Dictionary>(); + public HashSet svcFiles; public string restBaseURL; public GXRouting(string baseURL) @@ -410,9 +413,9 @@ public GxRestWrapper GetController(HttpContext context, ControllerInfo controlle else { string controllerLower = controller.ToLower(); - string svcFile = Path.Combine(ContentRootPath, $"{controller}.svc"); - if (!File.Exists(svcFile)) - svcFile = Path.Combine(ContentRootPath, $"{controllerLower}.svc"); + string svcFile = SvcFile($"{controller}{SvcExtension}"); + if (svcFile==null) + svcFile = SvcFile($"{controllerLower}{SvcExtension}"); if (File.Exists(svcFile)) { string[] controllerAssemblyQualifiedName = new string(File.ReadLines(svcFile).First().SkipWhile(c => c != '"') @@ -444,6 +447,24 @@ public GxRestWrapper GetController(HttpContext context, ControllerInfo controlle GXLogging.Warn(log, $"Controller was not found"); return null; } + string SvcFile(string controller) + { + if (svcFiles == null) + { + svcFiles = new HashSet(); + foreach (string file in Directory.GetFiles(ContentRootPath, SvcExtensionPattern, SearchOption.AllDirectories)) + { + svcFiles.Add(file); + } + } + string fileName; + string controllerFullName = Path.Combine(ContentRootPath, controller); + if (svcFiles.TryGetValue(new FileInfo(controllerFullName).FullName, out fileName)) + return fileName; + else + return null; + + } public void ServicesGroupSetting() { try