lib/types: check paths in pathWith with hasStorePathPrefix (#387304)

This commit is contained in:
Johannes Kirschbauer 2025-04-21 10:45:23 +02:00 committed by GitHub
commit 013beed1db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 2 deletions

View file

@ -678,7 +678,14 @@ let
check =
x:
let
isInStore = builtins.match "${builtins.storeDir}/[^.].*" (toString x) != null;
isInStore = lib.path.hasStorePathPrefix (
if builtins.isPath x then
x
# Discarding string context is necessary to convert the value to
# a path and safe as the result is never used in any derivation.
else
/. + builtins.unsafeDiscardStringContext x
);
isAbsolute = builtins.substring 0 1 (toString x) == "/";
isExpectedType = (
if inStore == null || inStore then isStringLike x else isString x # Do not allow a true path, which could be copied to the store later on.