routing: improve bad character detection on repo names

This commit is contained in:
RhodeCode Admin 2023-01-12 21:24:59 +01:00
parent 28af9bcecf
commit 7908e6921a
2 changed files with 13 additions and 3 deletions

View file

@ -618,8 +618,13 @@ class RepoRoutePredicate(object):
return
repo_name = info['match']['repo_name']
if repo_name != repo_name_slug(repo_name):
repo_name_parts = repo_name.split('/')
repo_slugs = [x for x in map(lambda x: repo_name_slug(x), repo_name_parts)]
if repo_name_parts != repo_slugs:
# short-skip if the repo-name doesn't follow slug rule
log.warning('repo_name: %s is different than slug %s', repo_name_parts, repo_slugs)
return False
repo_model = repo.RepoModel()
@ -727,7 +732,12 @@ class RepoGroupRoutePredicate(object):
return
repo_group_name = info['match']['repo_group_name']
if repo_group_name != repo_name_slug(repo_group_name):
repo_group_name_parts = repo_group_name.split('/')
repo_group_slugs = [x for x in map(lambda x: repo_name_slug(x), repo_group_name_parts)]
if repo_group_name_parts != repo_group_slugs:
# short-skip if the repo-name doesn't follow slug rule
log.warning('repo_group_name: %s is different than slug %s', repo_group_name_parts, repo_group_slugs)
return False
repo_group_model = repo_group.RepoGroupModel()

View file

@ -66,7 +66,7 @@ REMOVED_REPO_PAT = re.compile(r'rm__\d{8}_\d{6}_\d{6}__.*')
SLUG_BAD_CHARS = re.escape('`?=[]\;\'"<>,/~!@#$%^&*()+{}|:')
# Regex that matches forbidden characters in repo/group slugs.
SLUG_BAD_CHAR_RE = re.compile('[{}]'.format(SLUG_BAD_CHARS))
SLUG_BAD_CHAR_RE = re.compile('[{}\x00-\x08\x0b-\x0c\x0e-\x1f]'.format(SLUG_BAD_CHARS))
# Regex that matches allowed characters in repo/group slugs.
SLUG_GOOD_CHAR_RE = re.compile('[^{}]'.format(SLUG_BAD_CHARS))