Skip to content

Commit

Permalink
Always match full username/collection with regex
Browse files Browse the repository at this point in the history
It's easy to forget $ at the end of a regex and it's counter-intuitive that ^ is implicit but $ is not.
  • Loading branch information
Unrud committed Aug 1, 2016
1 parent f4ebe3f commit 9dd8c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions radicale/rights.py
Expand Up @@ -66,7 +66,7 @@ def load(configuration, logger):
"owner_write": """
[w]
user:.+
collection:^%(login)s(/.*)?$
collection:%(login)s(/.*)?
permission:rw
[r]
user:.+
Expand All @@ -76,7 +76,7 @@ def load(configuration, logger):
"owner_only": """
[rw]
user:.+
collection:^%(login)s(/.*)?$
collection:%(login)s(/.*)?
permission:rw
"""}

Expand Down Expand Up @@ -127,10 +127,10 @@ def authorized(self, user, collection, permission):
self.logger.debug(
"Test if '%s:%s' matches against '%s:%s' from section '%s'" % (
user, collection_url, re_user, re_collection, section))
user_match = re.match(re_user, user)
user_match = re.fullmatch(re_user, user)
if user_match:
re_collection = re_collection.format(*user_match.groups())
if re.match(re_collection, collection_url):
if re.fullmatch(re_collection, collection_url):
self.logger.debug("Section '%s' matches" % section)
return permission in regex.get(section, "permission")
else:
Expand Down
10 changes: 5 additions & 5 deletions rights
Expand Up @@ -14,22 +14,22 @@

# This means all users starting with "admin" may read any collection
[admin]
user: ^admin.*$
user: admin.*
collection: .*
permission: r

# This means all users may read and write any collection starting with public.
# We do so by just not testing against the user string.
[public]
user: .*
collection: ^public(/.+)?$
collection: public(/.+)?
permission: rw

# A little more complex: give read access to users from a domain for all
# collections of all the users (ie. user@domain.tld can read domain/*).
[domain-wide-access]
user: ^.+@(.+)\..+$
collection: ^{0}/.+$
user: .+@(.+)\..+
collection: {0}/.+
permission: r

# Allow authenticated user to read all collections
Expand All @@ -41,5 +41,5 @@ permission: r
# Give write access to owners
[owner-write]
user: .+
collection: ^%(login)s/.*$
collection: %(login)s/.*
permission: w

0 comments on commit 9dd8c65

Please sign in to comment.