File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -3087,6 +3087,11 @@ SourcePath EvalState::findFile(const LookupPath & lookupPath, const std::string_
30873087
30883088 auto res = (r / CanonPath (suffix)).resolveSymlinks ();
30893089 if (res.pathExists ()) return res;
3090+
3091+ // Backward compatibility hack: throw an exception if access
3092+ // to this path is not allowed.
3093+ if (auto accessor = res.accessor .dynamic_pointer_cast <FilteringSourceAccessor>())
3094+ accessor->checkAccess (res.path );
30903095 }
30913096
30923097 if (hasPrefix (path, " nix/" ))
@@ -3157,6 +3162,11 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
31573162 if (path.resolveSymlinks ().pathExists ())
31583163 return finish (std::move (path));
31593164 else {
3165+ // Backward compatibility hack: throw an exception if access
3166+ // to this path is not allowed.
3167+ if (auto accessor = path.accessor .dynamic_pointer_cast <FilteringSourceAccessor>())
3168+ accessor->checkAccess (path.path );
3169+
31603170 logWarning ({
31613171 .msg = HintFmt (" Nix search path entry '%1%' does not exist, ignoring" , value)
31623172 });
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ nix-instantiate --restrict-eval ./simple.nix -I src1=./simple.nix -I src2=./conf
2323(! nix-instantiate --restrict-eval --eval -E ' builtins.readFile ./simple.nix' )
2424nix-instantiate --restrict-eval --eval -E ' builtins.readFile ./simple.nix' -I src=../..
2525
26- expectStderr 1 nix-instantiate --restrict-eval --eval -E ' let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' # | grepQuiet "forbidden in restricted mode"
26+ expectStderr 1 nix-instantiate --restrict-eval --eval -E ' let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' | grepQuiet " forbidden in restricted mode"
2727nix-instantiate --restrict-eval --eval -E ' let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' -I src=.
2828
2929p=$( nix eval --raw --expr " builtins.fetchurl file://${_NIX_TEST_SOURCE_DIR} /restricted.sh" --impure --restrict-eval --allowed-uris " file://${_NIX_TEST_SOURCE_DIR} " )
@@ -53,9 +53,9 @@ mkdir -p $TEST_ROOT/tunnel.d $TEST_ROOT/foo2
5353ln -sfn .. $TEST_ROOT /tunnel.d/tunnel
5454echo foo > $TEST_ROOT /bar
5555
56- expectStderr 1 nix-instantiate --restrict-eval --eval -E " let __nixPath = [ { prefix = \" foo\" ; path = $TEST_ROOT /tunnel.d; } ]; in builtins.readFile <foo/tunnel/bar>" -I $TEST_ROOT /tunnel.d # | grepQuiet "forbidden in restricted mode"
56+ expectStderr 1 nix-instantiate --restrict-eval --eval -E " let __nixPath = [ { prefix = \" foo\" ; path = $TEST_ROOT /tunnel.d; } ]; in builtins.readFile <foo/tunnel/bar>" -I $TEST_ROOT /tunnel.d | grepQuiet " forbidden in restricted mode"
5757
58- expectStderr 1 nix-instantiate --restrict-eval --eval -E " let __nixPath = [ { prefix = \" foo\" ; path = $TEST_ROOT /tunnel.d; } ]; in builtins.readDir <foo/tunnel/foo2>" -I $TEST_ROOT /tunnel.d # | grepQuiet "forbidden in restricted mode"
58+ expectStderr 1 nix-instantiate --restrict-eval --eval -E " let __nixPath = [ { prefix = \" foo\" ; path = $TEST_ROOT /tunnel.d; } ]; in builtins.readDir <foo/tunnel/foo2>" -I $TEST_ROOT /tunnel.d | grepQuiet " forbidden in restricted mode"
5959
6060# Reading the parents of allowed paths should show only the ancestors of the allowed paths.
6161[[ $( nix-instantiate --restrict-eval --eval -E " let __nixPath = [ { prefix = \" foo\" ; path = $TEST_ROOT /tunnel.d; } ]; in builtins.readDir <foo/tunnel>" -I $TEST_ROOT /tunnel.d) == ' { "tunnel.d" = "directory"; }' ]]
You can’t perform that action at this time.
0 commit comments