Skip to content

Fix: Prevent creating folders with forbidden names #10967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6046833
Initial fix
hecksmosis Jan 9, 2023
889818e
Fix formatting
hecksmosis Jan 9, 2023
9d862bd
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 10, 2023
a96f055
Add dialog
hecksmosis Jan 10, 2023
e7207f6
Update strings
hecksmosis Jan 10, 2023
3723ed3
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 10, 2023
e533da3
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 12, 2023
06b30f7
Add check for rename
hecksmosis Jan 12, 2023
31996ad
Merge branch 'fix_forbidden_filenames' of https://github.com/hecksmos…
hecksmosis Jan 12, 2023
d266fcc
Update FilesystemOperations.cs
hecksmosis Jan 12, 2023
b1d6934
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 15, 2023
d08a57b
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 15, 2023
98c24e7
Update FilesystemOperations.cs
hecksmosis Jan 15, 2023
86999b1
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 15, 2023
94c0c61
Merge branch 'main' into fix_forbidden_filenames
yaira2 Jan 19, 2023
45fc470
Update src/Files.App/Strings/en-US/Resources.resw
hecksmosis Jan 19, 2023
c4adf1f
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 19, 2023
70da83c
Add name checker method
hecksmosis Jan 20, 2023
02d3730
Merge branch 'main' of https://github.com/files-community/Files into …
hecksmosis Jan 20, 2023
0fa289e
Merge branch 'fix_forbidden_filenames' of https://github.com/hecksmos…
hecksmosis Jan 20, 2023
37ec237
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,4 @@ public Task<IStorageHistory> CreateShortcutItemsAsync(IList<IStorageItemWithPath
throw new NotImplementedException("Cannot create shortcuts in UWP.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public FilesystemHelpers(IShellPage associatedInstance, CancellationToken cancel
var progress = new Progress<FileSystemProgress>();
progress.ProgressChanged += (s, e) => returnStatus = returnStatus < ReturnResult.Failed ? e.Status!.Value.ToStatus() : returnStatus;

if (!IsValidForFilename(source.Name))
{
await DialogDisplayHelper.ShowDialogAsync(
"ErrorDialogThisActionCannotBeDone".GetLocalizedResource(),
"ErrorDialogNameNotAllowed".GetLocalizedResource());
return (ReturnResult.Failed, null);
}

var result = await filesystemOperations.CreateAsync(source, progress, cancellationToken);

if (registerHistory && !string.IsNullOrWhiteSpace(source.Path))
Expand Down Expand Up @@ -538,6 +546,14 @@ public async Task<ReturnResult> RenameAsync(IStorageItemWithPath source, string
var progress = new Progress<FileSystemProgress>();
progress.ProgressChanged += (s, e) => returnStatus = returnStatus < ReturnResult.Failed ? e.Status!.Value.ToStatus() : returnStatus;

if (!IsValidForFilename(newName))
{
await DialogDisplayHelper.ShowDialogAsync(
"ErrorDialogThisActionCannotBeDone".GetLocalizedResource(),
"ErrorDialogNameNotAllowed".GetLocalizedResource());
return ReturnResult.Failed;
}

IStorageHistory history = null;

switch (source.ItemType)
Expand Down Expand Up @@ -632,6 +648,9 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag

#endregion IFilesystemHelpers

private static bool IsValidForFilename(string name)
=> !string.IsNullOrWhiteSpace(name) && !ContainsRestrictedCharacters(name) && !ContainsRestrictedFileName(name);

private static async Task<(List<FileNameConflictResolveOptionType> collisions, bool cancelOperation, IEnumerable<IFileSystemDialogConflictItemViewModel>)> GetCollision(FilesystemOperationType operationType, IEnumerable<IStorageItemWithPath> source, IEnumerable<string> destination, bool forceDialog)
{
var incomingItems = new List<BaseFileSystemDialogItemViewModel>();
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,9 @@
<data name="ReleaseNotes" xml:space="preserve">
<value>Release Notes</value>
</data>
<data name="ErrorDialogNameNotAllowed" xml:space="preserve">
<value>The specified item name is invalid</value>
</data>
<data name="Settings" xml:space="preserve">
<value>Settings</value>
</data>
Expand Down