mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-31 15:36:47 +02:00
AllowListInputAccessor: Clarify that the "allowed paths" are actually allowed prefixes
E.g. adding "/" will allow access to the root and *everything below it*.
This commit is contained in:
parent
06be819b89
commit
d52d91fe7a
3 changed files with 15 additions and 14 deletions
|
@ -467,13 +467,13 @@ EvalState::~EvalState()
|
||||||
void EvalState::allowPath(const Path & path)
|
void EvalState::allowPath(const Path & path)
|
||||||
{
|
{
|
||||||
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListInputAccessor>())
|
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListInputAccessor>())
|
||||||
rootFS2->allowPath(CanonPath(path));
|
rootFS2->allowPrefix(CanonPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::allowPath(const StorePath & storePath)
|
void EvalState::allowPath(const StorePath & storePath)
|
||||||
{
|
{
|
||||||
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListInputAccessor>())
|
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListInputAccessor>())
|
||||||
rootFS2->allowPath(CanonPath(store->toRealPath(storePath)));
|
rootFS2->allowPrefix(CanonPath(store->toRealPath(storePath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::allowAndSetStorePathString(const StorePath & storePath, Value & v)
|
void EvalState::allowAndSetStorePathString(const StorePath & storePath, Value & v)
|
||||||
|
|
|
@ -51,33 +51,33 @@ void FilteringInputAccessor::checkAccess(const CanonPath & path)
|
||||||
|
|
||||||
struct AllowListInputAccessorImpl : AllowListInputAccessor
|
struct AllowListInputAccessorImpl : AllowListInputAccessor
|
||||||
{
|
{
|
||||||
std::set<CanonPath> allowedPaths;
|
std::set<CanonPath> allowedPrefixes;
|
||||||
|
|
||||||
AllowListInputAccessorImpl(
|
AllowListInputAccessorImpl(
|
||||||
ref<InputAccessor> next,
|
ref<InputAccessor> next,
|
||||||
std::set<CanonPath> && allowedPaths,
|
std::set<CanonPath> && allowedPrefixes,
|
||||||
MakeNotAllowedError && makeNotAllowedError)
|
MakeNotAllowedError && makeNotAllowedError)
|
||||||
: AllowListInputAccessor(SourcePath(next), std::move(makeNotAllowedError))
|
: AllowListInputAccessor(SourcePath(next), std::move(makeNotAllowedError))
|
||||||
, allowedPaths(std::move(allowedPaths))
|
, allowedPrefixes(std::move(allowedPrefixes))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool isAllowed(const CanonPath & path) override
|
bool isAllowed(const CanonPath & path) override
|
||||||
{
|
{
|
||||||
return path.isAllowed(allowedPaths);
|
return path.isAllowed(allowedPrefixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void allowPath(CanonPath path) override
|
void allowPrefix(CanonPath prefix) override
|
||||||
{
|
{
|
||||||
allowedPaths.insert(std::move(path));
|
allowedPrefixes.insert(std::move(prefix));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ref<AllowListInputAccessor> AllowListInputAccessor::create(
|
ref<AllowListInputAccessor> AllowListInputAccessor::create(
|
||||||
ref<InputAccessor> next,
|
ref<InputAccessor> next,
|
||||||
std::set<CanonPath> && allowedPaths,
|
std::set<CanonPath> && allowedPrefixes,
|
||||||
MakeNotAllowedError && makeNotAllowedError)
|
MakeNotAllowedError && makeNotAllowedError)
|
||||||
{
|
{
|
||||||
return make_ref<AllowListInputAccessorImpl>(next, std::move(allowedPaths), std::move(makeNotAllowedError));
|
return make_ref<AllowListInputAccessorImpl>(next, std::move(allowedPrefixes), std::move(makeNotAllowedError));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CachingFilteringInputAccessor::isAllowed(const CanonPath & path)
|
bool CachingFilteringInputAccessor::isAllowed(const CanonPath & path)
|
||||||
|
|
|
@ -54,18 +54,19 @@ struct FilteringInputAccessor : InputAccessor
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapping `InputAccessor` that checks paths against an allow-list.
|
* A wrapping `InputAccessor` that checks paths against a set of
|
||||||
|
* allowed prefixes.
|
||||||
*/
|
*/
|
||||||
struct AllowListInputAccessor : public FilteringInputAccessor
|
struct AllowListInputAccessor : public FilteringInputAccessor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Grant access to the specified path.
|
* Grant access to the specified prefix.
|
||||||
*/
|
*/
|
||||||
virtual void allowPath(CanonPath path) = 0;
|
virtual void allowPrefix(CanonPath prefix) = 0;
|
||||||
|
|
||||||
static ref<AllowListInputAccessor> create(
|
static ref<AllowListInputAccessor> create(
|
||||||
ref<InputAccessor> next,
|
ref<InputAccessor> next,
|
||||||
std::set<CanonPath> && allowedPaths,
|
std::set<CanonPath> && allowedPrefixes,
|
||||||
MakeNotAllowedError && makeNotAllowedError);
|
MakeNotAllowedError && makeNotAllowedError);
|
||||||
|
|
||||||
using FilteringInputAccessor::FilteringInputAccessor;
|
using FilteringInputAccessor::FilteringInputAccessor;
|
||||||
|
|
Loading…
Reference in a new issue