Fix symlink leak in restricted eval mode #2326
Merged
+21
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
EvalState::checkSourcePath
, the path is checked against the list of allowed paths first and later it's checked again after resolving symlinks.The resolving of the symlinks is done via canonPath, which also strips out
../
and./
. However after the canonicalisation the error message pointing out that the path is not allowed prints the symlink target inthe error message.
Even if we'd suppress the message, symlink targets could still be leaked if the symlink target doesn't exist (in this case the error is thrown in
canonPath
).So instead, we now do
canonPath()
without symlink resolving first before even checking against the list of allowed paths and then later do the symlink resolving and checking the allowed paths again.The first call to
canonPath()
should get rid of all the../
and./
, so in theory the only way to leak a symlink if the attacker is able to put a symlink in one of the paths allowed by restricted evaluation mode.For the latter I don't think this is part of the threat model, because if the attacker can write to that path, the attack vector is even larger.