From 334b8812627313f33b8530df46cba9b0d0d43093 Mon Sep 17 00:00:00 2001 From: Samer Salameh Date: Tue, 17 Nov 2026 11:45:17 +0300 Subject: [PATCH] Open legacy registry attachments: accept multi-dot stored file names Co-Authored-By: Claude Sonnet 5.5 --- .../Grains/Registry/RegistryFileStoreService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Registry/RegistryFileStoreService.cs b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Registry/RegistryFileStoreService.cs index ed90bf5..ddbd039 100644 --- a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Registry/RegistryFileStoreService.cs +++ b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Registry/RegistryFileStoreService.cs @@ -17,6 +17,11 @@ internal sealed partial class RegistryFileStoreService(IRegistrySettingsService [GeneratedRegex(@"^[A-Za-z0-9_\-]+(\.[A-Za-z0-9]{1,8})?$")] private static partial Regex StoredNameRegex(); + // Files stored by the legacy system are named after a random decimal (genFileName: "0.7234567.pdf", sometimes "1.2E-4.pdf"), so + // reading accepts several dots; separators and ".." stay refused (the name must also be a registered GRAINS_FILES row). + [GeneratedRegex(@"^[A-Za-z0-9_.-]+$")] + private static partial Regex ReadNameRegex(); + private string TempFile(string id) => Path.Combine(settings.TempUploadPath, id + ".tmp"); private string TempNameFile(string id) => Path.Combine(settings.TempUploadPath, id + ".name"); @@ -55,7 +60,7 @@ internal sealed partial class RegistryFileStoreService(IRegistrySettingsService public Task OpenAsync(string folder, string storedName, CancellationToken ct = default) { - if (!StoredNameRegex().IsMatch(storedName)) return Task.FromResult(null); + if (!ReadNameRegex().IsMatch(storedName) || storedName.Contains("..")) return Task.FromResult(null); var path = Path.Combine(settings.UploadedFilesPath, folder, storedName); return Task.FromResult(File.Exists(path) ? new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 81920, useAsync: true)