server/scoped_fs.ts

Declarations
#

4 declarations

view source

PathNotAllowedError
#

server/scoped_fs.ts view source

Error thrown when a path is not allowed

inheritance

extends:
  • Error

name

constructor

type new (path: string, options?: ErrorOptions | undefined): PathNotAllowedError

path
type string
options?
type ErrorOptions | undefined
optional

ScopedFs
#

server/scoped_fs.ts view source

Provides a secure wrapper around filesystem operations to prevent path traversal attacks and unauthorized file access.

Security features: - Restricts operations to specified allowed paths - Prevents path traversal attacks by normalizing all paths - Blocks access to symlinks to avoid arbitrary file access - Requires absolute paths to avoid relative path confusion - Validates the entire path hierarchy for each operation

This class should be used whenever performing filesystem operations on user-provided or untrusted input paths to ensure proper access boundaries.

allowed_paths

type ReadonlyArray<ScopedFsPath>

readonly

constructor

Create a new ScopedFs instance with the specified allowed paths.

type new (allowed_paths: readonly string[] | string[]): ScopedFs

allowed_paths

Array of absolute paths that operations will be restricted to

type readonly string[] | string[]

is_path_allowed

Checks if the given path is allowed based on the paths provided during instantiation.

type (path_to_check: string): boolean

path_to_check
type string
returns boolean

is_path_safe

Performs a complete security check on a path, including symlink validation

type (path_to_check: string): Promise<boolean>

path_to_check
type string
returns Promise<boolean>

read_file

type (file_path: string, options?: (ObjectEncodingOptions & Abortable & { flag?: OpenMode | undefined; }) | BufferEncoding | null | undefined): Promise<...>

file_path
type string
options
type (ObjectEncodingOptions & Abortable & { flag?: OpenMode | undefined; }) | BufferEncoding | null | undefined
default 'utf8'
returns Promise<string | Buffer<ArrayBufferLike>>

write_file

type (file_path: string, data: string | ArrayBufferView<ArrayBufferLike> | Iterable<string | ArrayBufferView<ArrayBufferLike>> | AsyncIterable<...> | Stream, options?: BufferEncoding | ... 2 more ... | undefined): Promise<...>

file_path
type string
data
type string | ArrayBufferView<ArrayBufferLike> | Iterable<string | ArrayBufferView<ArrayBufferLike>> | AsyncIterable<...> | Stream
options
type BufferEncoding | (ObjectEncodingOptions & { mode?: Mode | undefined; flag?: OpenMode | undefined; flush?: boolean | undefined; } & Abortable) | null | undefined
default 'utf8'
returns Promise<void>

rm

type (path_to_remove: string, options?: RmOptions | undefined): Promise<void>

path_to_remove
type string
options?
type RmOptions | undefined
optional
returns Promise<void>

mkdir

type (dir_path: string, options?: MakeDirectoryOptions | undefined): Promise<string | undefined>

dir_path
type string
options?
type MakeDirectoryOptions | undefined
optional
returns Promise<string | undefined>

readdir

type (path: PathLike, options?: BufferEncoding | (ObjectEncodingOptions & { withFileTypes?: false | undefined; recursive?: boolean | undefined; }) | null | undefined): Promise<...>

path
type PathLike
options?
type BufferEncoding | (ObjectEncodingOptions & { withFileTypes?: false | undefined; recursive?: boolean | undefined; }) | null | undefined
optional
returns Promise<string[]>

readdir

type (path: PathLike, options?: BufferEncoding | (ObjectEncodingOptions & { withFileTypes?: false | undefined; recursive?: boolean | undefined; }) | null | undefined): Promise<...>

path
type PathLike
options?
type BufferEncoding | (ObjectEncodingOptions & { withFileTypes?: false | undefined; recursive?: boolean | undefined; }) | null | undefined
optional
returns Promise<string[]>

readdir

type (path: PathLike, options?: BufferEncoding | (ObjectEncodingOptions & { withFileTypes?: false | undefined; recursive?: boolean | undefined; }) | null | undefined): Promise<...>

path
type PathLike
options?
type BufferEncoding | (ObjectEncodingOptions & { withFileTypes?: false | undefined; recursive?: boolean | undefined; }) | null | undefined
optional
returns Promise<string[]>

stat

type (path_to_stat: string, options?: StatOptions | undefined): Promise<Stats>

path_to_stat
type string
options?
type StatOptions | undefined
optional
returns Promise<Stats>

stat

type (path_to_stat: string, options?: StatOptions | undefined): Promise<Stats>

path_to_stat
type string
options?
type StatOptions | undefined
optional
returns Promise<Stats>

stat

type (path_to_stat: string, options?: StatOptions | undefined): Promise<Stats>

path_to_stat
type string
options?
type StatOptions | undefined
optional
returns Promise<Stats>

copy_file

type (source: string, destination: string, mode?: number | undefined): Promise<void>

source
type string
destination
type string
mode?
type number | undefined
optional
returns Promise<void>

exists

type (path_to_check: string): Promise<boolean>

path_to_check
type string
returns Promise<boolean>

ScopedFsPath
#

server/scoped_fs.ts view source

$ZodBranded<ZodPipe<ZodString, ZodTransform<string, string>>, "ScopedFsPath">

A branded type for representing safely normalized filesystem paths

SymlinkNotAllowedError
#

server/scoped_fs.ts view source

Error thrown when a path is a symlink

inheritance

extends:
  • Error

name

constructor

type new (path: string, options?: ErrorOptions | undefined): SymlinkNotAllowedError

path
type string
options?
type ErrorOptions | undefined
optional

Imported by
#