diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-09-21 14:52:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-21 14:52:30 +0200 |
commit | c81f9761ccb40865edc497321752503abc0da858 (patch) | |
tree | 6052b1bce0362786718ed7e2189baf40f6164d87 /src/libfetchers/path.cc | |
parent | be69a98d2cb707f5fe87dfa657e39c06cc95fb58 (diff) | |
parent | 60cc975d22c193cd70cc4e8d3fb5643728aec418 (diff) |
Merge pull request #5279 from edolstra/restrict-path-inputs
Fix relative path input handling
Diffstat (limited to 'src/libfetchers/path.cc')
-rw-r--r-- | src/libfetchers/path.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index b6fcdac9e..fb5702c4c 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -85,18 +85,26 @@ struct PathInputScheme : InputScheme std::string absPath; auto path = getStrAttr(input.attrs, "path"); - if (path[0] != '/' && input.parent) { + if (path[0] != '/') { + if (!input.parent) + throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string()); + auto parent = canonPath(*input.parent); // the path isn't relative, prefix it - absPath = canonPath(parent + "/" + path); + absPath = nix::absPath(path, parent); // for security, ensure that if the parent is a store path, it's inside it - if (!parent.rfind(store->storeDir, 0) && absPath.rfind(store->storeDir, 0)) - throw BadStorePath("relative path '%s' points outside of its parent's store path %s, this is a security violation", path, parent); + if (store->isInStore(parent)) { + auto storePath = store->printStorePath(store->toStorePath(parent).first); + if (!isInDir(absPath, storePath)) + throw BadStorePath("relative path '%s' points outside of its parent's store path '%s'", path, storePath); + } } else absPath = path; + Activity act(*logger, lvlTalkative, actUnknown, fmt("copying '%s'", absPath)); + // FIXME: check whether access to 'path' is allowed. auto storePath = store->maybeParseStorePath(absPath); |