Skip to content

Commit

Permalink
Prevent "regex injection"
Browse files Browse the repository at this point in the history
If an attacker is able to authenticate with a user name like .* he can bypass limitations imposed by "owner_write" and "owner_only".
  • Loading branch information
Unrud committed Dec 23, 2015
1 parent c7fe477 commit 4bfe7c9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion radicale/rights/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def _read_from_sections(user, collection_url, permission):
"""Get regex sections."""
filename = os.path.expanduser(config.get("rights", "file"))
rights_type = config.get("rights", "type").lower()
regex = ConfigParser({"login": user, "path": collection_url})
# Prevent "regex injection"
user_escaped = re.escape(user)
collection_url_escaped = re.escape(collection_url)
regex = ConfigParser({"login": user_escaped, "path": collection_url_escaped})
if rights_type in DEFINED_RIGHTS:
log.LOGGER.debug("Rights type '%s'" % rights_type)
regex.readfp(StringIO(DEFINED_RIGHTS[rights_type]))
Expand Down

0 comments on commit 4bfe7c9

Please sign in to comment.