aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/path-regex.hh
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2024-01-30 18:37:23 +0100
committereldritch horrors <pennae@lix.systems>2024-05-02 19:34:38 +0200
commitb7ce11c97dfd0e73ddefbd15ef2cb59fee7d23f2 (patch)
treec661941f805e1ab011f584d5c02f45743e66bcad /src/libstore/path-regex.hh
parent4b3dc66386e164936227ebfbb97ce92b41512ba0 (diff)
Disallow store path names that are . or .. (plus opt. -)
As discussed in the maintainer meeting on 2024-01-29. Mainly this is to avoid a situation where the name is parsed and treated as a file name, mostly to protect users. .-* and ..-* are also considered invalid because they might strip on that separator to remove versions. Doesn't really work, but that's what we decided, and I won't argue with it, because .-* probably doesn't seem to have a real world application anyway. We do still permit a 1-character name that's just "-", which still poses a similar risk in such a situation. We can't start disallowing trailing -, because a non-zero number of users will need it and we've seen how annoying and painful such a change is. What matters most is preventing a situation where . or .. can be injected, and to just get this done. (cherry picked from commit f1b4663805a9dbcb1ace64ec110092d17c9155e0) Change-Id: I900a8509933cee662f888c3c76fa8986b0058839
Diffstat (limited to 'src/libstore/path-regex.hh')
-rw-r--r--src/libstore/path-regex.hh7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libstore/path-regex.hh b/src/libstore/path-regex.hh
index 4f8dc4c1f..56c2cfc1d 100644
--- a/src/libstore/path-regex.hh
+++ b/src/libstore/path-regex.hh
@@ -3,6 +3,11 @@
namespace nix {
-static constexpr std::string_view nameRegexStr = R"([0-9a-zA-Z\+\-\._\?=]+)";
+
+static constexpr std::string_view nameRegexStr =
+ // This uses a negative lookahead: (?!\.\.?(-|$))
+ // - deny ".", "..", or those strings followed by '-'
+ // - when it's not those, start again at the start of the input and apply the next regex, which is [0-9a-zA-Z\+\-\._\?=]+
+ R"((?!\.\.?(-|$))[0-9a-zA-Z\+\-\._\?=]+)";
}