NAME

Filesys::Restrict - Restrict filesystem access

SYNOPSIS

{
    my $check = Filesys::Restrict::create(
        sub {
            my ($op, $path) = @_;

            return 1 if $path =~ m<^/safe/place/>;

            # Deny access to anything else:
            return 0;
        },
    );

    # In this block, most Perl code will throw if it tries
    # to access anything outside of /safe/place.
}

# No more filesystem checks here.

DESCRIPTION

This module is a reasonable-best-effort at preventing Perl code from accessing files you don’t want to allow. One potential application of this is to restrict filesystem access to /tmp in tests.

THIS IS NOT A SECURITY TOOL!

This module cannot prevent all unintended filesystem access. The following are some known ways to circumvent it:

SEE ALSO

Test::MockFile can achieve a similar effect to this module but has some compatibility problems with some Perl syntax.

Linux’s fanotify(7) provides a method of real-time access control via the kernel. See Linux::Fanotify and Linux::Perl for Perl implementations.

FUNCTIONS

$obj = create( sub { .. } )

Creates an opaque object that installs an access-control callback. Any existing access-control callback is saved and restored whenever $obj is DESTROYed.

The access-control callback is called with two arguments:

The callback can end in one of three ways:

LICENSE & COPYRIGHT

Copyright 2022 Gasper Software Consulting. All rights reserved.

This library is licensed under the same terms as Perl itself. See perlartistic.

This library was originally a research project at cPanel, L.L.C..