File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -3069,6 +3069,11 @@ SourcePath EvalState::findFile(const LookupPath & lookupPath, const std::string_
3069
3069
3070
3070
auto res = (r / CanonPath (suffix)).resolveSymlinks ();
3071
3071
if (res.pathExists ()) return res;
3072
+
3073
+ // Backward compatibility hack: throw an exception if access
3074
+ // to this path is not allowed.
3075
+ if (auto accessor = res.accessor .dynamic_pointer_cast <FilteringSourceAccessor>())
3076
+ accessor->checkAccess (res.path );
3072
3077
}
3073
3078
3074
3079
if (hasPrefix (path, " nix/" ))
@@ -3139,6 +3144,11 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
3139
3144
if (path.resolveSymlinks ().pathExists ())
3140
3145
return finish (std::move (path));
3141
3146
else {
3147
+ // Backward compatibility hack: throw an exception if access
3148
+ // to this path is not allowed.
3149
+ if (auto accessor = path.accessor .dynamic_pointer_cast <FilteringSourceAccessor>())
3150
+ accessor->checkAccess (path.path );
3151
+
3142
3152
logWarning ({
3143
3153
.msg = HintFmt (" Nix search path entry '%1%' does not exist, ignoring" , value)
3144
3154
});
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
23
23
(! nix-instantiate --restrict-eval --eval -E ' builtins.readFile ./simple.nix' )
24
24
nix-instantiate --restrict-eval --eval -E ' builtins.readFile ./simple.nix' -I src=../..
25
25
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"
27
27
nix-instantiate --restrict-eval --eval -E ' let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' -I src=.
28
28
29
29
p=$( 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
53
53
ln -sfn .. $TEST_ROOT /tunnel.d/tunnel
54
54
echo foo > $TEST_ROOT /bar
55
55
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"
57
57
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"
59
59
60
60
# Reading the parents of allowed paths should show only the ancestors of the allowed paths.
61
61
[[ $( 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