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 @@ -3087,6 +3087,11 @@ SourcePath EvalState::findFile(const LookupPath & lookupPath, const std::string_
3087
3087
3088
3088
auto res = (r / CanonPath (suffix)).resolveSymlinks ();
3089
3089
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 );
3090
3095
}
3091
3096
3092
3097
if (hasPrefix (path, " nix/" ))
@@ -3157,6 +3162,11 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
3157
3162
if (path.resolveSymlinks ().pathExists ())
3158
3163
return finish (std::move (path));
3159
3164
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
+
3160
3170
logWarning ({
3161
3171
.msg = HintFmt (" Nix search path entry '%1%' does not exist, ignoring" , value)
3162
3172
});
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