Skip to main content

A System.IO.Abstractions IFileSystem decorator that restricts file read and write operations to one or more configured scope roots and rejects symbolic links.

Total Downloads
70.0K
70,022
Published
Nov 12, 2026
10d ago

Get Started

dotnet add package Nullean.ScopedFileSystem --version 0.7.2
ProductVersions
.NET
net10.0net11.0net9.0
.NET Standard
netstandard2.0netstandard2.1

README

Nullean.ScopedFileSystem

nullean

A System.IO.Abstractions IFileSystem decorator that restricts file reads and writes to one or more scope root directories and rejects symbolic links, hidden files and path traversal.

NuGet

Install

dotnet add package Nullean.ScopedFileSystem

Quick start

using System.IO.Abstractions;
using Nullean.ScopedFileSystem;

IFileSystem scoped = new ScopedFileSystem("/var/www/docs");

var content = scoped.File.ReadAllText("/var/www/docs/page.md");      // OK: within scope
scoped.File.WriteAllText("/var/www/docs/output.md", content);         // OK: write within scope

bool exists = scoped.File.Exists("/etc/passwd");                      // false, no exception

scoped.File.ReadAllText("/etc/passwd");                               // ScopedFileSystemException: outside scope
scoped.File.ReadAllText("/var/www/docs/../../../etc/passwd");         // ScopedFileSystemException: .. is resolved first
scoped.File.ReadAllText("/var/www/docs/.env");                        // ScopedFileSystemException: hidden file
scoped.File.ReadAllText("/var/www/docs/link-to-secret");              // ScopedFileSystemException: symbolic link

Wrap any IFileSystem, such as a MockFileSystem in tests, and allow what else you need:

using System.IO.Abstractions;
using Nullean.ScopedFileSystem;

IFileSystem inner = new FileSystem();   // or a MockFileSystem in tests

IFileSystem scoped = new ScopedFileSystem(inner, new ScopedFileSystemOptions("/var/www/docs", "/var/www/data")
{
	AllowedHiddenFolderNames = [".git"],
	AllowedHiddenFileNames = [".gitkeep"],
	AllowedSpecialFolders = AllowedSpecialFolder.Temp | AllowedSpecialFolder.ApplicationData,
});

scoped.File.WriteAllText(Path.Combine(Path.GetTempPath(), "cache.txt"), "ok");   // OK: temp is allowed

What it enforces

Rule Detail
Scope The resolved path must be within a configured scope root or an explicitly allowed OS special folder.
No symlinks The target and all ancestor directories up to the scope root must not be symbolic links.
No hidden files Files whose name starts with . are blocked unless the name is in AllowedHiddenFileNames.
No hidden directories Directories whose name starts with . are blocked unless the name is in AllowedHiddenFolderNames. This applies to both the target directory and all ancestors up to the scope root.
Exists is safe File.Exists() and Directory.Exists() return false for out-of-scope paths instead of throwing.

Any violation throws ScopedFileSystemException (extends SecurityException).

Any violation throws ScopedFileSystemException (extends SecurityException). Paths are resolved with IPath.GetFullPath before any check, so .. cannot escape, and scope membership is checked by walking up the directory tree, so /docs-extra is not inside /docs. Multiple roots must be disjoint, or the constructor throws ArgumentException.

Learn more

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 5 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.