Handle permission regexes that may start with ^ or \

This commit is contained in:
Alexandre Aubin 2020-12-28 16:58:50 +01:00 committed by GitHub
parent 0c977d8c70
commit bdff5937f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -668,6 +668,9 @@ def _validate_and_sanitize_permission_url(url, app_base_path, app):
For example: For example:
re:/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$ re:/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$
re:domain.tld/app/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$ re:domain.tld/app/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$
We can also have less-trivial regexes like:
re:^\/api\/.*|\/scripts\/api.js$
""" """
from yunohost.domain import domain_list from yunohost.domain import domain_list
@ -692,9 +695,9 @@ def _validate_and_sanitize_permission_url(url, app_base_path, app):
if url.startswith('re:'): if url.startswith('re:'):
# regex without domain # regex without domain
# we check for the first char after 're:'
if url.startswith('re:/'): if url[3] in ['/', '^', '\\']:
validate_regex(url[4:]) validate_regex(url[3:])
return url return url
# regex with domain # regex with domain