Skip to content

Commit

Permalink
#36: minor suggested improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chucker committed Jul 11, 2023
1 parent 3bf3f73 commit aa29a5f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions TRENZ.Docs.API/Models/Sources/AbstractFilesystemSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace TRENZ.Docs.API.Models.Sources;

public abstract class AbstractFilesystemSource : ISource
{
private class ExceptionMessages
{
public const string PreventedPathTraversal = "Prevented an attempt to traverse a path outside the source's root.";
}
private static SecurityException PreventedPathTraversal => new("Prevented an attempt to traverse a path outside the source's root.");

/// <inheritdoc />
public abstract string Name { get; }
Expand All @@ -28,8 +25,8 @@ public IEnumerable<ISourceFile> FindFiles(Regex pattern)
{
var combinedRoot = FSPath.Combine(Root, Path);

if (FSPath.GetFullPath(combinedRoot).Length < Root.Length)
throw new SecurityException(ExceptionMessages.PreventedPathTraversal);
if (!FSPath.GetFullPath(combinedRoot).StartsWith(Root))
throw PreventedPathTraversal;

return IterateDirectory(pattern, combinedRoot, combinedRoot);
}
Expand Down

0 comments on commit aa29a5f

Please sign in to comment.