Open legacy registry attachments: accept multi-dot stored file names
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
83cf3c9b03
commit
334b881262
|
|
@ -17,6 +17,11 @@ internal sealed partial class RegistryFileStoreService(IRegistrySettingsService
|
||||||
[GeneratedRegex(@"^[A-Za-z0-9_\-]+(\.[A-Za-z0-9]{1,8})?$")]
|
[GeneratedRegex(@"^[A-Za-z0-9_\-]+(\.[A-Za-z0-9]{1,8})?$")]
|
||||||
private static partial Regex StoredNameRegex();
|
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 TempFile(string id) => Path.Combine(settings.TempUploadPath, id + ".tmp");
|
||||||
private string TempNameFile(string id) => Path.Combine(settings.TempUploadPath, id + ".name");
|
private string TempNameFile(string id) => Path.Combine(settings.TempUploadPath, id + ".name");
|
||||||
|
|
||||||
|
|
@ -55,7 +60,7 @@ internal sealed partial class RegistryFileStoreService(IRegistrySettingsService
|
||||||
|
|
||||||
public Task<Stream?> OpenAsync(string folder, string storedName, CancellationToken ct = default)
|
public Task<Stream?> OpenAsync(string folder, string storedName, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (!StoredNameRegex().IsMatch(storedName)) return Task.FromResult<Stream?>(null);
|
if (!ReadNameRegex().IsMatch(storedName) || storedName.Contains("..")) return Task.FromResult<Stream?>(null);
|
||||||
var path = Path.Combine(settings.UploadedFilesPath, folder, storedName);
|
var path = Path.Combine(settings.UploadedFilesPath, folder, storedName);
|
||||||
return Task.FromResult<Stream?>(File.Exists(path)
|
return Task.FromResult<Stream?>(File.Exists(path)
|
||||||
? new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 81920, useAsync: true)
|
? new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 81920, useAsync: true)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue